Ei kuvausta

jquery.dataTables.js 446KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707
  1. /*! DataTables 1.13.5
  2. * ©2008-2023 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary DataTables
  6. * @description Paginate, search and order HTML tables
  7. * @version 1.13.4
  8. * @author SpryMedia Ltd
  9. * @contact www.datatables.net
  10. * @copyright SpryMedia Ltd.
  11. *
  12. * This source file is free software, available under the following license:
  13. * MIT license - http://datatables.net/license
  14. *
  15. * This source file is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  17. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  18. *
  19. * For details please refer to: http://www.datatables.net
  20. */
  21. /*jslint evil: true, undef: true, browser: true */
  22. /*globals $,require,jQuery,define,_selector_run,_selector_opts,_selector_first,_selector_row_indexes,_ext,_Api,_api_register,_api_registerPlural,_re_new_lines,_re_html,_re_formatted_numeric,_re_escape_regex,_empty,_intVal,_numToDecimal,_isNumber,_isHtml,_htmlNumeric,_pluck,_pluck_order,_range,_stripHtml,_unique,_fnBuildAjax,_fnAjaxUpdate,_fnAjaxParameters,_fnAjaxUpdateDraw,_fnAjaxDataSrc,_fnAddColumn,_fnColumnOptions,_fnAdjustColumnSizing,_fnVisibleToColumnIndex,_fnColumnIndexToVisible,_fnVisbleColumns,_fnGetColumns,_fnColumnTypes,_fnApplyColumnDefs,_fnHungarianMap,_fnCamelToHungarian,_fnLanguageCompat,_fnBrowserDetect,_fnAddData,_fnAddTr,_fnNodeToDataIndex,_fnNodeToColumnIndex,_fnGetCellData,_fnSetCellData,_fnSplitObjNotation,_fnGetObjectDataFn,_fnSetObjectDataFn,_fnGetDataMaster,_fnClearTable,_fnDeleteIndex,_fnInvalidate,_fnGetRowElements,_fnCreateTr,_fnBuildHead,_fnDrawHead,_fnDraw,_fnReDraw,_fnAddOptionsHtml,_fnDetectHeader,_fnGetUniqueThs,_fnFeatureHtmlFilter,_fnFilterComplete,_fnFilterCustom,_fnFilterColumn,_fnFilter,_fnFilterCreateSearch,_fnEscapeRegex,_fnFilterData,_fnFeatureHtmlInfo,_fnUpdateInfo,_fnInfoMacros,_fnInitialise,_fnInitComplete,_fnLengthChange,_fnFeatureHtmlLength,_fnFeatureHtmlPaginate,_fnPageChange,_fnFeatureHtmlProcessing,_fnProcessingDisplay,_fnFeatureHtmlTable,_fnScrollDraw,_fnApplyToChildren,_fnCalculateColumnWidths,_fnThrottle,_fnConvertToWidth,_fnGetWidestNode,_fnGetMaxLenString,_fnStringToCss,_fnSortFlatten,_fnSort,_fnSortAria,_fnSortListener,_fnSortAttachListener,_fnSortingClasses,_fnSortData,_fnSaveState,_fnLoadState,_fnSettingsFromNode,_fnLog,_fnMap,_fnBindAction,_fnCallbackReg,_fnCallbackFire,_fnLengthOverflow,_fnRenderer,_fnDataSource,_fnRowAttributes*/
  23. (function( factory ) {
  24. "use strict";
  25. if ( typeof define === 'function' && define.amd ) {
  26. // AMD
  27. define( ['jquery'], function ( $ ) {
  28. return factory( $, window, document );
  29. } );
  30. }
  31. else if ( typeof exports === 'object' ) {
  32. // CommonJS
  33. // jQuery's factory checks for a global window - if it isn't present then it
  34. // returns a factory function that expects the window object
  35. var jq = require('jquery');
  36. if (typeof window !== 'undefined') {
  37. module.exports = function (root, $) {
  38. if ( ! root ) {
  39. // CommonJS environments without a window global must pass a
  40. // root. This will give an error otherwise
  41. root = window;
  42. }
  43. if ( ! $ ) {
  44. $ = jq( root );
  45. }
  46. return factory( $, root, root.document );
  47. };
  48. }
  49. else {
  50. return factory( jq, window, window.document );
  51. }
  52. }
  53. else {
  54. // Browser
  55. window.DataTable = factory( jQuery, window, document );
  56. }
  57. }
  58. (function( $, window, document, undefined ) {
  59. "use strict";
  60. var DataTable = function ( selector, options )
  61. {
  62. // Check if called with a window or jQuery object for DOM less applications
  63. // This is for backwards compatibility
  64. if (DataTable.factory(selector, options)) {
  65. return DataTable;
  66. }
  67. // When creating with `new`, create a new DataTable, returning the API instance
  68. if (this instanceof DataTable) {
  69. return $(selector).DataTable(options);
  70. }
  71. else {
  72. // Argument switching
  73. options = selector;
  74. }
  75. /**
  76. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  77. * return the resulting jQuery object.
  78. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  79. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  80. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  81. * criterion ("applied") or all TR elements (i.e. no filter).
  82. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  83. * Can be either 'current', whereby the current sorting of the table is used, or
  84. * 'original' whereby the original order the data was read into the table is used.
  85. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  86. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  87. * 'current' and filter is 'applied', regardless of what they might be given as.
  88. * @returns {object} jQuery object, filtered by the given selector.
  89. * @dtopt API
  90. * @deprecated Since v1.10
  91. *
  92. * @example
  93. * $(document).ready(function() {
  94. * var oTable = $('#example').dataTable();
  95. *
  96. * // Highlight every second row
  97. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  98. * } );
  99. *
  100. * @example
  101. * $(document).ready(function() {
  102. * var oTable = $('#example').dataTable();
  103. *
  104. * // Filter to rows with 'Webkit' in them, add a background colour and then
  105. * // remove the filter, thus highlighting the 'Webkit' rows only.
  106. * oTable.fnFilter('Webkit');
  107. * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
  108. * oTable.fnFilter('');
  109. * } );
  110. */
  111. this.$ = function ( sSelector, oOpts )
  112. {
  113. return this.api(true).$( sSelector, oOpts );
  114. };
  115. /**
  116. * Almost identical to $ in operation, but in this case returns the data for the matched
  117. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  118. * rather than any descendants, so the data can be obtained for the row/cell. If matching
  119. * rows are found, the data returned is the original data array/object that was used to
  120. * create the row (or a generated array if from a DOM source).
  121. *
  122. * This method is often useful in-combination with $ where both functions are given the
  123. * same parameters and the array indexes will match identically.
  124. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  125. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  126. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  127. * criterion ("applied") or all elements (i.e. no filter).
  128. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  129. * Can be either 'current', whereby the current sorting of the table is used, or
  130. * 'original' whereby the original order the data was read into the table is used.
  131. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  132. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  133. * 'current' and filter is 'applied', regardless of what they might be given as.
  134. * @returns {array} Data for the matched elements. If any elements, as a result of the
  135. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  136. * entry in the array.
  137. * @dtopt API
  138. * @deprecated Since v1.10
  139. *
  140. * @example
  141. * $(document).ready(function() {
  142. * var oTable = $('#example').dataTable();
  143. *
  144. * // Get the data from the first row in the table
  145. * var data = oTable._('tr:first');
  146. *
  147. * // Do something useful with the data
  148. * alert( "First cell is: "+data[0] );
  149. * } );
  150. *
  151. * @example
  152. * $(document).ready(function() {
  153. * var oTable = $('#example').dataTable();
  154. *
  155. * // Filter to 'Webkit' and get all data for
  156. * oTable.fnFilter('Webkit');
  157. * var data = oTable._('tr', {"search": "applied"});
  158. *
  159. * // Do something with the data
  160. * alert( data.length+" rows matched the search" );
  161. * } );
  162. */
  163. this._ = function ( sSelector, oOpts )
  164. {
  165. return this.api(true).rows( sSelector, oOpts ).data();
  166. };
  167. /**
  168. * Create a DataTables Api instance, with the currently selected tables for
  169. * the Api's context.
  170. * @param {boolean} [traditional=false] Set the API instance's context to be
  171. * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
  172. * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
  173. * or if all tables captured in the jQuery object should be used.
  174. * @return {DataTables.Api}
  175. */
  176. this.api = function ( traditional )
  177. {
  178. return traditional ?
  179. new _Api(
  180. _fnSettingsFromNode( this[ _ext.iApiIndex ] )
  181. ) :
  182. new _Api( this );
  183. };
  184. /**
  185. * Add a single new row or multiple rows of data to the table. Please note
  186. * that this is suitable for client-side processing only - if you are using
  187. * server-side processing (i.e. "bServerSide": true), then to add data, you
  188. * must add it to the data source, i.e. the server-side, through an Ajax call.
  189. * @param {array|object} data The data to be added to the table. This can be:
  190. * <ul>
  191. * <li>1D array of data - add a single row with the data provided</li>
  192. * <li>2D array of arrays - add multiple rows in a single call</li>
  193. * <li>object - data object when using <i>mData</i></li>
  194. * <li>array of objects - multiple data objects when using <i>mData</i></li>
  195. * </ul>
  196. * @param {bool} [redraw=true] redraw the table or not
  197. * @returns {array} An array of integers, representing the list of indexes in
  198. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  199. * the table.
  200. * @dtopt API
  201. * @deprecated Since v1.10
  202. *
  203. * @example
  204. * // Global var for counter
  205. * var giCount = 2;
  206. *
  207. * $(document).ready(function() {
  208. * $('#example').dataTable();
  209. * } );
  210. *
  211. * function fnClickAddRow() {
  212. * $('#example').dataTable().fnAddData( [
  213. * giCount+".1",
  214. * giCount+".2",
  215. * giCount+".3",
  216. * giCount+".4" ]
  217. * );
  218. *
  219. * giCount++;
  220. * }
  221. */
  222. this.fnAddData = function( data, redraw )
  223. {
  224. var api = this.api( true );
  225. /* Check if we want to add multiple rows or not */
  226. var rows = Array.isArray(data) && ( Array.isArray(data[0]) || $.isPlainObject(data[0]) ) ?
  227. api.rows.add( data ) :
  228. api.row.add( data );
  229. if ( redraw === undefined || redraw ) {
  230. api.draw();
  231. }
  232. return rows.flatten().toArray();
  233. };
  234. /**
  235. * This function will make DataTables recalculate the column sizes, based on the data
  236. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  237. * through the sWidth parameter). This can be useful when the width of the table's
  238. * parent element changes (for example a window resize).
  239. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  240. * @dtopt API
  241. * @deprecated Since v1.10
  242. *
  243. * @example
  244. * $(document).ready(function() {
  245. * var oTable = $('#example').dataTable( {
  246. * "sScrollY": "200px",
  247. * "bPaginate": false
  248. * } );
  249. *
  250. * $(window).on('resize', function () {
  251. * oTable.fnAdjustColumnSizing();
  252. * } );
  253. * } );
  254. */
  255. this.fnAdjustColumnSizing = function ( bRedraw )
  256. {
  257. var api = this.api( true ).columns.adjust();
  258. var settings = api.settings()[0];
  259. var scroll = settings.oScroll;
  260. if ( bRedraw === undefined || bRedraw ) {
  261. api.draw( false );
  262. }
  263. else if ( scroll.sX !== "" || scroll.sY !== "" ) {
  264. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  265. _fnScrollDraw( settings );
  266. }
  267. };
  268. /**
  269. * Quickly and simply clear a table
  270. * @param {bool} [bRedraw=true] redraw the table or not
  271. * @dtopt API
  272. * @deprecated Since v1.10
  273. *
  274. * @example
  275. * $(document).ready(function() {
  276. * var oTable = $('#example').dataTable();
  277. *
  278. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  279. * oTable.fnClearTable();
  280. * } );
  281. */
  282. this.fnClearTable = function( bRedraw )
  283. {
  284. var api = this.api( true ).clear();
  285. if ( bRedraw === undefined || bRedraw ) {
  286. api.draw();
  287. }
  288. };
  289. /**
  290. * The exact opposite of 'opening' a row, this function will close any rows which
  291. * are currently 'open'.
  292. * @param {node} nTr the table row to 'close'
  293. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  294. * @dtopt API
  295. * @deprecated Since v1.10
  296. *
  297. * @example
  298. * $(document).ready(function() {
  299. * var oTable;
  300. *
  301. * // 'open' an information row when a row is clicked on
  302. * $('#example tbody tr').click( function () {
  303. * if ( oTable.fnIsOpen(this) ) {
  304. * oTable.fnClose( this );
  305. * } else {
  306. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  307. * }
  308. * } );
  309. *
  310. * oTable = $('#example').dataTable();
  311. * } );
  312. */
  313. this.fnClose = function( nTr )
  314. {
  315. this.api( true ).row( nTr ).child.hide();
  316. };
  317. /**
  318. * Remove a row for the table
  319. * @param {mixed} target The index of the row from aoData to be deleted, or
  320. * the TR element you want to delete
  321. * @param {function|null} [callBack] Callback function
  322. * @param {bool} [redraw=true] Redraw the table or not
  323. * @returns {array} The row that was deleted
  324. * @dtopt API
  325. * @deprecated Since v1.10
  326. *
  327. * @example
  328. * $(document).ready(function() {
  329. * var oTable = $('#example').dataTable();
  330. *
  331. * // Immediately remove the first row
  332. * oTable.fnDeleteRow( 0 );
  333. * } );
  334. */
  335. this.fnDeleteRow = function( target, callback, redraw )
  336. {
  337. var api = this.api( true );
  338. var rows = api.rows( target );
  339. var settings = rows.settings()[0];
  340. var data = settings.aoData[ rows[0][0] ];
  341. rows.remove();
  342. if ( callback ) {
  343. callback.call( this, settings, data );
  344. }
  345. if ( redraw === undefined || redraw ) {
  346. api.draw();
  347. }
  348. return data;
  349. };
  350. /**
  351. * Restore the table to it's original state in the DOM by removing all of DataTables
  352. * enhancements, alterations to the DOM structure of the table and event listeners.
  353. * @param {boolean} [remove=false] Completely remove the table from the DOM
  354. * @dtopt API
  355. * @deprecated Since v1.10
  356. *
  357. * @example
  358. * $(document).ready(function() {
  359. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  360. * var oTable = $('#example').dataTable();
  361. * oTable.fnDestroy();
  362. * } );
  363. */
  364. this.fnDestroy = function ( remove )
  365. {
  366. this.api( true ).destroy( remove );
  367. };
  368. /**
  369. * Redraw the table
  370. * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
  371. * @dtopt API
  372. * @deprecated Since v1.10
  373. *
  374. * @example
  375. * $(document).ready(function() {
  376. * var oTable = $('#example').dataTable();
  377. *
  378. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  379. * oTable.fnDraw();
  380. * } );
  381. */
  382. this.fnDraw = function( complete )
  383. {
  384. // Note that this isn't an exact match to the old call to _fnDraw - it takes
  385. // into account the new data, but can hold position.
  386. this.api( true ).draw( complete );
  387. };
  388. /**
  389. * Filter the input based on data
  390. * @param {string} sInput String to filter the table on
  391. * @param {int|null} [iColumn] Column to limit filtering to
  392. * @param {bool} [bRegex=false] Treat as regular expression or not
  393. * @param {bool} [bSmart=true] Perform smart filtering or not
  394. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  395. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  396. * @dtopt API
  397. * @deprecated Since v1.10
  398. *
  399. * @example
  400. * $(document).ready(function() {
  401. * var oTable = $('#example').dataTable();
  402. *
  403. * // Sometime later - filter...
  404. * oTable.fnFilter( 'test string' );
  405. * } );
  406. */
  407. this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
  408. {
  409. var api = this.api( true );
  410. if ( iColumn === null || iColumn === undefined ) {
  411. api.search( sInput, bRegex, bSmart, bCaseInsensitive );
  412. }
  413. else {
  414. api.column( iColumn ).search( sInput, bRegex, bSmart, bCaseInsensitive );
  415. }
  416. api.draw();
  417. };
  418. /**
  419. * Get the data for the whole table, an individual row or an individual cell based on the
  420. * provided parameters.
  421. * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
  422. * a TR node then the data source for the whole row will be returned. If given as a
  423. * TD/TH cell node then iCol will be automatically calculated and the data for the
  424. * cell returned. If given as an integer, then this is treated as the aoData internal
  425. * data index for the row (see fnGetPosition) and the data for that row used.
  426. * @param {int} [col] Optional column index that you want the data of.
  427. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  428. * returned. If mRow is defined, just data for that row, and is iCol is
  429. * defined, only data for the designated cell is returned.
  430. * @dtopt API
  431. * @deprecated Since v1.10
  432. *
  433. * @example
  434. * // Row data
  435. * $(document).ready(function() {
  436. * oTable = $('#example').dataTable();
  437. *
  438. * oTable.$('tr').click( function () {
  439. * var data = oTable.fnGetData( this );
  440. * // ... do something with the array / object of data for the row
  441. * } );
  442. * } );
  443. *
  444. * @example
  445. * // Individual cell data
  446. * $(document).ready(function() {
  447. * oTable = $('#example').dataTable();
  448. *
  449. * oTable.$('td').click( function () {
  450. * var sData = oTable.fnGetData( this );
  451. * alert( 'The cell clicked on had the value of '+sData );
  452. * } );
  453. * } );
  454. */
  455. this.fnGetData = function( src, col )
  456. {
  457. var api = this.api( true );
  458. if ( src !== undefined ) {
  459. var type = src.nodeName ? src.nodeName.toLowerCase() : '';
  460. return col !== undefined || type == 'td' || type == 'th' ?
  461. api.cell( src, col ).data() :
  462. api.row( src ).data() || null;
  463. }
  464. return api.data().toArray();
  465. };
  466. /**
  467. * Get an array of the TR nodes that are used in the table's body. Note that you will
  468. * typically want to use the '$' API method in preference to this as it is more
  469. * flexible.
  470. * @param {int} [iRow] Optional row index for the TR element you want
  471. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  472. * in the table's body, or iRow is defined, just the TR element requested.
  473. * @dtopt API
  474. * @deprecated Since v1.10
  475. *
  476. * @example
  477. * $(document).ready(function() {
  478. * var oTable = $('#example').dataTable();
  479. *
  480. * // Get the nodes from the table
  481. * var nNodes = oTable.fnGetNodes( );
  482. * } );
  483. */
  484. this.fnGetNodes = function( iRow )
  485. {
  486. var api = this.api( true );
  487. return iRow !== undefined ?
  488. api.row( iRow ).node() :
  489. api.rows().nodes().flatten().toArray();
  490. };
  491. /**
  492. * Get the array indexes of a particular cell from it's DOM element
  493. * and column index including hidden columns
  494. * @param {node} node this can either be a TR, TD or TH in the table's body
  495. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  496. * if given as a cell, an array of [row index, column index (visible),
  497. * column index (all)] is given.
  498. * @dtopt API
  499. * @deprecated Since v1.10
  500. *
  501. * @example
  502. * $(document).ready(function() {
  503. * $('#example tbody td').click( function () {
  504. * // Get the position of the current data from the node
  505. * var aPos = oTable.fnGetPosition( this );
  506. *
  507. * // Get the data array for this row
  508. * var aData = oTable.fnGetData( aPos[0] );
  509. *
  510. * // Update the data array and return the value
  511. * aData[ aPos[1] ] = 'clicked';
  512. * this.innerHTML = 'clicked';
  513. * } );
  514. *
  515. * // Init DataTables
  516. * oTable = $('#example').dataTable();
  517. * } );
  518. */
  519. this.fnGetPosition = function( node )
  520. {
  521. var api = this.api( true );
  522. var nodeName = node.nodeName.toUpperCase();
  523. if ( nodeName == 'TR' ) {
  524. return api.row( node ).index();
  525. }
  526. else if ( nodeName == 'TD' || nodeName == 'TH' ) {
  527. var cell = api.cell( node ).index();
  528. return [
  529. cell.row,
  530. cell.columnVisible,
  531. cell.column
  532. ];
  533. }
  534. return null;
  535. };
  536. /**
  537. * Check to see if a row is 'open' or not.
  538. * @param {node} nTr the table row to check
  539. * @returns {boolean} true if the row is currently open, false otherwise
  540. * @dtopt API
  541. * @deprecated Since v1.10
  542. *
  543. * @example
  544. * $(document).ready(function() {
  545. * var oTable;
  546. *
  547. * // 'open' an information row when a row is clicked on
  548. * $('#example tbody tr').click( function () {
  549. * if ( oTable.fnIsOpen(this) ) {
  550. * oTable.fnClose( this );
  551. * } else {
  552. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  553. * }
  554. * } );
  555. *
  556. * oTable = $('#example').dataTable();
  557. * } );
  558. */
  559. this.fnIsOpen = function( nTr )
  560. {
  561. return this.api( true ).row( nTr ).child.isShown();
  562. };
  563. /**
  564. * This function will place a new row directly after a row which is currently
  565. * on display on the page, with the HTML contents that is passed into the
  566. * function. This can be used, for example, to ask for confirmation that a
  567. * particular record should be deleted.
  568. * @param {node} nTr The table row to 'open'
  569. * @param {string|node|jQuery} mHtml The HTML to put into the row
  570. * @param {string} sClass Class to give the new TD cell
  571. * @returns {node} The row opened. Note that if the table row passed in as the
  572. * first parameter, is not found in the table, this method will silently
  573. * return.
  574. * @dtopt API
  575. * @deprecated Since v1.10
  576. *
  577. * @example
  578. * $(document).ready(function() {
  579. * var oTable;
  580. *
  581. * // 'open' an information row when a row is clicked on
  582. * $('#example tbody tr').click( function () {
  583. * if ( oTable.fnIsOpen(this) ) {
  584. * oTable.fnClose( this );
  585. * } else {
  586. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  587. * }
  588. * } );
  589. *
  590. * oTable = $('#example').dataTable();
  591. * } );
  592. */
  593. this.fnOpen = function( nTr, mHtml, sClass )
  594. {
  595. return this.api( true )
  596. .row( nTr )
  597. .child( mHtml, sClass )
  598. .show()
  599. .child()[0];
  600. };
  601. /**
  602. * Change the pagination - provides the internal logic for pagination in a simple API
  603. * function. With this function you can have a DataTables table go to the next,
  604. * previous, first or last pages.
  605. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  606. * or page number to jump to (integer), note that page 0 is the first page.
  607. * @param {bool} [bRedraw=true] Redraw the table or not
  608. * @dtopt API
  609. * @deprecated Since v1.10
  610. *
  611. * @example
  612. * $(document).ready(function() {
  613. * var oTable = $('#example').dataTable();
  614. * oTable.fnPageChange( 'next' );
  615. * } );
  616. */
  617. this.fnPageChange = function ( mAction, bRedraw )
  618. {
  619. var api = this.api( true ).page( mAction );
  620. if ( bRedraw === undefined || bRedraw ) {
  621. api.draw(false);
  622. }
  623. };
  624. /**
  625. * Show a particular column
  626. * @param {int} iCol The column whose display should be changed
  627. * @param {bool} bShow Show (true) or hide (false) the column
  628. * @param {bool} [bRedraw=true] Redraw the table or not
  629. * @dtopt API
  630. * @deprecated Since v1.10
  631. *
  632. * @example
  633. * $(document).ready(function() {
  634. * var oTable = $('#example').dataTable();
  635. *
  636. * // Hide the second column after initialisation
  637. * oTable.fnSetColumnVis( 1, false );
  638. * } );
  639. */
  640. this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
  641. {
  642. var api = this.api( true ).column( iCol ).visible( bShow );
  643. if ( bRedraw === undefined || bRedraw ) {
  644. api.columns.adjust().draw();
  645. }
  646. };
  647. /**
  648. * Get the settings for a particular table for external manipulation
  649. * @returns {object} DataTables settings object. See
  650. * {@link DataTable.models.oSettings}
  651. * @dtopt API
  652. * @deprecated Since v1.10
  653. *
  654. * @example
  655. * $(document).ready(function() {
  656. * var oTable = $('#example').dataTable();
  657. * var oSettings = oTable.fnSettings();
  658. *
  659. * // Show an example parameter from the settings
  660. * alert( oSettings._iDisplayStart );
  661. * } );
  662. */
  663. this.fnSettings = function()
  664. {
  665. return _fnSettingsFromNode( this[_ext.iApiIndex] );
  666. };
  667. /**
  668. * Sort the table by a particular column
  669. * @param {int} iCol the data index to sort on. Note that this will not match the
  670. * 'display index' if you have hidden data entries
  671. * @dtopt API
  672. * @deprecated Since v1.10
  673. *
  674. * @example
  675. * $(document).ready(function() {
  676. * var oTable = $('#example').dataTable();
  677. *
  678. * // Sort immediately with columns 0 and 1
  679. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  680. * } );
  681. */
  682. this.fnSort = function( aaSort )
  683. {
  684. this.api( true ).order( aaSort ).draw();
  685. };
  686. /**
  687. * Attach a sort listener to an element for a given column
  688. * @param {node} nNode the element to attach the sort listener to
  689. * @param {int} iColumn the column that a click on this node will sort on
  690. * @param {function} [fnCallback] callback function when sort is run
  691. * @dtopt API
  692. * @deprecated Since v1.10
  693. *
  694. * @example
  695. * $(document).ready(function() {
  696. * var oTable = $('#example').dataTable();
  697. *
  698. * // Sort on column 1, when 'sorter' is clicked on
  699. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  700. * } );
  701. */
  702. this.fnSortListener = function( nNode, iColumn, fnCallback )
  703. {
  704. this.api( true ).order.listener( nNode, iColumn, fnCallback );
  705. };
  706. /**
  707. * Update a table cell or row - this method will accept either a single value to
  708. * update the cell with, an array of values with one element for each column or
  709. * an object in the same format as the original data source. The function is
  710. * self-referencing in order to make the multi column updates easier.
  711. * @param {object|array|string} mData Data to update the cell/row with
  712. * @param {node|int} mRow TR element you want to update or the aoData index
  713. * @param {int} [iColumn] The column to update, give as null or undefined to
  714. * update a whole row.
  715. * @param {bool} [bRedraw=true] Redraw the table or not
  716. * @param {bool} [bAction=true] Perform pre-draw actions or not
  717. * @returns {int} 0 on success, 1 on error
  718. * @dtopt API
  719. * @deprecated Since v1.10
  720. *
  721. * @example
  722. * $(document).ready(function() {
  723. * var oTable = $('#example').dataTable();
  724. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  725. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
  726. * } );
  727. */
  728. this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
  729. {
  730. var api = this.api( true );
  731. if ( iColumn === undefined || iColumn === null ) {
  732. api.row( mRow ).data( mData );
  733. }
  734. else {
  735. api.cell( mRow, iColumn ).data( mData );
  736. }
  737. if ( bAction === undefined || bAction ) {
  738. api.columns.adjust();
  739. }
  740. if ( bRedraw === undefined || bRedraw ) {
  741. api.draw();
  742. }
  743. return 0;
  744. };
  745. /**
  746. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  747. * to ensure compatibility.
  748. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  749. * formats "X" and "X.Y" are also acceptable.
  750. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  751. * version, or false if this version of DataTales is not suitable
  752. * @method
  753. * @dtopt API
  754. * @deprecated Since v1.10
  755. *
  756. * @example
  757. * $(document).ready(function() {
  758. * var oTable = $('#example').dataTable();
  759. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  760. * } );
  761. */
  762. this.fnVersionCheck = _ext.fnVersionCheck;
  763. var _that = this;
  764. var emptyInit = options === undefined;
  765. var len = this.length;
  766. if ( emptyInit ) {
  767. options = {};
  768. }
  769. this.oApi = this.internal = _ext.internal;
  770. // Extend with old style plug-in API methods
  771. for ( var fn in DataTable.ext.internal ) {
  772. if ( fn ) {
  773. this[fn] = _fnExternApiFunc(fn);
  774. }
  775. }
  776. this.each(function() {
  777. // For each initialisation we want to give it a clean initialisation
  778. // object that can be bashed around
  779. var o = {};
  780. var oInit = len > 1 ? // optimisation for single table case
  781. _fnExtend( o, options, true ) :
  782. options;
  783. /*global oInit,_that,emptyInit*/
  784. var i=0, iLen, j, jLen, k, kLen;
  785. var sId = this.getAttribute( 'id' );
  786. var bInitHandedOff = false;
  787. var defaults = DataTable.defaults;
  788. var $this = $(this);
  789. /* Sanity check */
  790. if ( this.nodeName.toLowerCase() != 'table' )
  791. {
  792. _fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName+')', 2 );
  793. return;
  794. }
  795. /* Backwards compatibility for the defaults */
  796. _fnCompatOpts( defaults );
  797. _fnCompatCols( defaults.column );
  798. /* Convert the camel-case defaults to Hungarian */
  799. _fnCamelToHungarian( defaults, defaults, true );
  800. _fnCamelToHungarian( defaults.column, defaults.column, true );
  801. /* Setting up the initialisation object */
  802. _fnCamelToHungarian( defaults, $.extend( oInit, $this.data() ), true );
  803. /* Check to see if we are re-initialising a table */
  804. var allSettings = DataTable.settings;
  805. for ( i=0, iLen=allSettings.length ; i<iLen ; i++ )
  806. {
  807. var s = allSettings[i];
  808. /* Base check on table node */
  809. if (
  810. s.nTable == this ||
  811. (s.nTHead && s.nTHead.parentNode == this) ||
  812. (s.nTFoot && s.nTFoot.parentNode == this)
  813. ) {
  814. var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
  815. var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
  816. if ( emptyInit || bRetrieve )
  817. {
  818. return s.oInstance;
  819. }
  820. else if ( bDestroy )
  821. {
  822. s.oInstance.fnDestroy();
  823. break;
  824. }
  825. else
  826. {
  827. _fnLog( s, 0, 'Cannot reinitialise DataTable', 3 );
  828. return;
  829. }
  830. }
  831. /* If the element we are initialising has the same ID as a table which was previously
  832. * initialised, but the table nodes don't match (from before) then we destroy the old
  833. * instance by simply deleting it. This is under the assumption that the table has been
  834. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  835. */
  836. if ( s.sTableId == this.id )
  837. {
  838. allSettings.splice( i, 1 );
  839. break;
  840. }
  841. }
  842. /* Ensure the table has an ID - required for accessibility */
  843. if ( sId === null || sId === "" )
  844. {
  845. sId = "DataTables_Table_"+(DataTable.ext._unique++);
  846. this.id = sId;
  847. }
  848. /* Create the settings object for this table and set some of the default parameters */
  849. var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
  850. "sDestroyWidth": $this[0].style.width,
  851. "sInstance": sId,
  852. "sTableId": sId
  853. } );
  854. oSettings.nTable = this;
  855. oSettings.oApi = _that.internal;
  856. oSettings.oInit = oInit;
  857. allSettings.push( oSettings );
  858. // Need to add the instance after the instance after the settings object has been added
  859. // to the settings array, so we can self reference the table instance if more than one
  860. oSettings.oInstance = (_that.length===1) ? _that : $this.dataTable();
  861. // Backwards compatibility, before we apply all the defaults
  862. _fnCompatOpts( oInit );
  863. _fnLanguageCompat( oInit.oLanguage );
  864. // If the length menu is given, but the init display length is not, use the length menu
  865. if ( oInit.aLengthMenu && ! oInit.iDisplayLength )
  866. {
  867. oInit.iDisplayLength = Array.isArray( oInit.aLengthMenu[0] ) ?
  868. oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
  869. }
  870. // Apply the defaults and init options to make a single init object will all
  871. // options defined from defaults and instance options.
  872. oInit = _fnExtend( $.extend( true, {}, defaults ), oInit );
  873. // Map the initialisation options onto the settings object
  874. _fnMap( oSettings.oFeatures, oInit, [
  875. "bPaginate",
  876. "bLengthChange",
  877. "bFilter",
  878. "bSort",
  879. "bSortMulti",
  880. "bInfo",
  881. "bProcessing",
  882. "bAutoWidth",
  883. "bSortClasses",
  884. "bServerSide",
  885. "bDeferRender"
  886. ] );
  887. _fnMap( oSettings, oInit, [
  888. "asStripeClasses",
  889. "ajax",
  890. "fnServerData",
  891. "fnFormatNumber",
  892. "sServerMethod",
  893. "aaSorting",
  894. "aaSortingFixed",
  895. "aLengthMenu",
  896. "sPaginationType",
  897. "sAjaxSource",
  898. "sAjaxDataProp",
  899. "iStateDuration",
  900. "sDom",
  901. "bSortCellsTop",
  902. "iTabIndex",
  903. "fnStateLoadCallback",
  904. "fnStateSaveCallback",
  905. "renderer",
  906. "searchDelay",
  907. "rowId",
  908. [ "iCookieDuration", "iStateDuration" ], // backwards compat
  909. [ "oSearch", "oPreviousSearch" ],
  910. [ "aoSearchCols", "aoPreSearchCols" ],
  911. [ "iDisplayLength", "_iDisplayLength" ]
  912. ] );
  913. _fnMap( oSettings.oScroll, oInit, [
  914. [ "sScrollX", "sX" ],
  915. [ "sScrollXInner", "sXInner" ],
  916. [ "sScrollY", "sY" ],
  917. [ "bScrollCollapse", "bCollapse" ]
  918. ] );
  919. _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
  920. /* Callback functions which are array driven */
  921. _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
  922. _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
  923. _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
  924. _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
  925. _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
  926. _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
  927. _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
  928. _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
  929. _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
  930. _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
  931. _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
  932. oSettings.rowIdFn = _fnGetObjectDataFn( oInit.rowId );
  933. /* Browser support detection */
  934. _fnBrowserDetect( oSettings );
  935. var oClasses = oSettings.oClasses;
  936. $.extend( oClasses, DataTable.ext.classes, oInit.oClasses );
  937. $this.addClass( oClasses.sTable );
  938. if ( oSettings.iInitDisplayStart === undefined )
  939. {
  940. /* Display start point, taking into account the save saving */
  941. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  942. oSettings._iDisplayStart = oInit.iDisplayStart;
  943. }
  944. if ( oInit.iDeferLoading !== null )
  945. {
  946. oSettings.bDeferLoading = true;
  947. var tmp = Array.isArray( oInit.iDeferLoading );
  948. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  949. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  950. }
  951. /* Language definitions */
  952. var oLanguage = oSettings.oLanguage;
  953. $.extend( true, oLanguage, oInit.oLanguage );
  954. if ( oLanguage.sUrl )
  955. {
  956. /* Get the language definitions from a file - because this Ajax call makes the language
  957. * get async to the remainder of this function we use bInitHandedOff to indicate that
  958. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  959. */
  960. $.ajax( {
  961. dataType: 'json',
  962. url: oLanguage.sUrl,
  963. success: function ( json ) {
  964. _fnCamelToHungarian( defaults.oLanguage, json );
  965. _fnLanguageCompat( json );
  966. $.extend( true, oLanguage, json, oSettings.oInit.oLanguage );
  967. _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
  968. _fnInitialise( oSettings );
  969. },
  970. error: function () {
  971. // Error occurred loading language file, continue on as best we can
  972. _fnInitialise( oSettings );
  973. }
  974. } );
  975. bInitHandedOff = true;
  976. }
  977. else {
  978. _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
  979. }
  980. /*
  981. * Stripes
  982. */
  983. if ( oInit.asStripeClasses === null )
  984. {
  985. oSettings.asStripeClasses =[
  986. oClasses.sStripeOdd,
  987. oClasses.sStripeEven
  988. ];
  989. }
  990. /* Remove row stripe classes if they are already on the table row */
  991. var stripeClasses = oSettings.asStripeClasses;
  992. var rowOne = $this.children('tbody').find('tr').eq(0);
  993. if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
  994. return rowOne.hasClass(el);
  995. } ) ) !== -1 ) {
  996. $('tbody tr', this).removeClass( stripeClasses.join(' ') );
  997. oSettings.asDestroyStripes = stripeClasses.slice();
  998. }
  999. /*
  1000. * Columns
  1001. * See if we should load columns automatically or use defined ones
  1002. */
  1003. var anThs = [];
  1004. var aoColumnsInit;
  1005. var nThead = this.getElementsByTagName('thead');
  1006. if ( nThead.length !== 0 )
  1007. {
  1008. _fnDetectHeader( oSettings.aoHeader, nThead[0] );
  1009. anThs = _fnGetUniqueThs( oSettings );
  1010. }
  1011. /* If not given a column array, generate one with nulls */
  1012. if ( oInit.aoColumns === null )
  1013. {
  1014. aoColumnsInit = [];
  1015. for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
  1016. {
  1017. aoColumnsInit.push( null );
  1018. }
  1019. }
  1020. else
  1021. {
  1022. aoColumnsInit = oInit.aoColumns;
  1023. }
  1024. /* Add the columns */
  1025. for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
  1026. {
  1027. _fnAddColumn( oSettings, anThs ? anThs[i] : null );
  1028. }
  1029. /* Apply the column definitions */
  1030. _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  1031. _fnColumnOptions( oSettings, iCol, oDef );
  1032. } );
  1033. /* HTML5 attribute detection - build an mData object automatically if the
  1034. * attributes are found
  1035. */
  1036. if ( rowOne.length ) {
  1037. var a = function ( cell, name ) {
  1038. return cell.getAttribute( 'data-'+name ) !== null ? name : null;
  1039. };
  1040. $( rowOne[0] ).children('th, td').each( function (i, cell) {
  1041. var col = oSettings.aoColumns[i];
  1042. if (! col) {
  1043. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  1044. }
  1045. if ( col.mData === i ) {
  1046. var sort = a( cell, 'sort' ) || a( cell, 'order' );
  1047. var filter = a( cell, 'filter' ) || a( cell, 'search' );
  1048. if ( sort !== null || filter !== null ) {
  1049. col.mData = {
  1050. _: i+'.display',
  1051. sort: sort !== null ? i+'.@data-'+sort : undefined,
  1052. type: sort !== null ? i+'.@data-'+sort : undefined,
  1053. filter: filter !== null ? i+'.@data-'+filter : undefined
  1054. };
  1055. col._isArrayHost = true;
  1056. _fnColumnOptions( oSettings, i );
  1057. }
  1058. }
  1059. } );
  1060. }
  1061. var features = oSettings.oFeatures;
  1062. var loadedInit = function () {
  1063. /*
  1064. * Sorting
  1065. * @todo For modularisation (1.11) this needs to do into a sort start up handler
  1066. */
  1067. // If aaSorting is not defined, then we use the first indicator in asSorting
  1068. // in case that has been altered, so the default sort reflects that option
  1069. if ( oInit.aaSorting === undefined ) {
  1070. var sorting = oSettings.aaSorting;
  1071. for ( i=0, iLen=sorting.length ; i<iLen ; i++ ) {
  1072. sorting[i][1] = oSettings.aoColumns[ i ].asSorting[0];
  1073. }
  1074. }
  1075. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  1076. * account, and also will apply sorting disabled classes if disabled
  1077. */
  1078. _fnSortingClasses( oSettings );
  1079. if ( features.bSort ) {
  1080. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1081. if ( oSettings.bSorted ) {
  1082. var aSort = _fnSortFlatten( oSettings );
  1083. var sortedColumns = {};
  1084. $.each( aSort, function (i, val) {
  1085. sortedColumns[ val.src ] = val.dir;
  1086. } );
  1087. _fnCallbackFire( oSettings, null, 'order', [oSettings, aSort, sortedColumns] );
  1088. _fnSortAria( oSettings );
  1089. }
  1090. } );
  1091. }
  1092. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1093. if ( oSettings.bSorted || _fnDataSource( oSettings ) === 'ssp' || features.bDeferRender ) {
  1094. _fnSortingClasses( oSettings );
  1095. }
  1096. }, 'sc' );
  1097. /*
  1098. * Final init
  1099. * Cache the header, body and footer as required, creating them if needed
  1100. */
  1101. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  1102. var captions = $this.children('caption').each( function () {
  1103. this._captionSide = $(this).css('caption-side');
  1104. } );
  1105. var thead = $this.children('thead');
  1106. if ( thead.length === 0 ) {
  1107. thead = $('<thead/>').appendTo($this);
  1108. }
  1109. oSettings.nTHead = thead[0];
  1110. var tbody = $this.children('tbody');
  1111. if ( tbody.length === 0 ) {
  1112. tbody = $('<tbody/>').insertAfter(thead);
  1113. }
  1114. oSettings.nTBody = tbody[0];
  1115. var tfoot = $this.children('tfoot');
  1116. if ( tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") ) {
  1117. // If we are a scrolling table, and no footer has been given, then we need to create
  1118. // a tfoot element for the caption element to be appended to
  1119. tfoot = $('<tfoot/>').appendTo($this);
  1120. }
  1121. if ( tfoot.length === 0 || tfoot.children().length === 0 ) {
  1122. $this.addClass( oClasses.sNoFooter );
  1123. }
  1124. else if ( tfoot.length > 0 ) {
  1125. oSettings.nTFoot = tfoot[0];
  1126. _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
  1127. }
  1128. /* Check if there is data passing into the constructor */
  1129. if ( oInit.aaData ) {
  1130. for ( i=0 ; i<oInit.aaData.length ; i++ ) {
  1131. _fnAddData( oSettings, oInit.aaData[ i ] );
  1132. }
  1133. }
  1134. else if ( oSettings.bDeferLoading || _fnDataSource( oSettings ) == 'dom' ) {
  1135. /* Grab the data from the page - only do this when deferred loading or no Ajax
  1136. * source since there is no point in reading the DOM data if we are then going
  1137. * to replace it with Ajax data
  1138. */
  1139. _fnAddTr( oSettings, $(oSettings.nTBody).children('tr') );
  1140. }
  1141. /* Copy the data index array */
  1142. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  1143. /* Initialisation complete - table can be drawn */
  1144. oSettings.bInitialised = true;
  1145. /* Check if we need to initialise the table (it might not have been handed off to the
  1146. * language processor)
  1147. */
  1148. if ( bInitHandedOff === false ) {
  1149. _fnInitialise( oSettings );
  1150. }
  1151. };
  1152. /* Must be done after everything which can be overridden by the state saving! */
  1153. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
  1154. if ( oInit.bStateSave )
  1155. {
  1156. features.bStateSave = true;
  1157. _fnLoadState( oSettings, oInit, loadedInit );
  1158. }
  1159. else {
  1160. loadedInit();
  1161. }
  1162. } );
  1163. _that = null;
  1164. return this;
  1165. };
  1166. /*
  1167. * It is useful to have variables which are scoped locally so only the
  1168. * DataTables functions can access them and they don't leak into global space.
  1169. * At the same time these functions are often useful over multiple files in the
  1170. * core and API, so we list, or at least document, all variables which are used
  1171. * by DataTables as private variables here. This also ensures that there is no
  1172. * clashing of variable names and that they can easily referenced for reuse.
  1173. */
  1174. // Defined else where
  1175. // _selector_run
  1176. // _selector_opts
  1177. // _selector_first
  1178. // _selector_row_indexes
  1179. var _ext; // DataTable.ext
  1180. var _Api; // DataTable.Api
  1181. var _api_register; // DataTable.Api.register
  1182. var _api_registerPlural; // DataTable.Api.registerPlural
  1183. var _re_dic = {};
  1184. var _re_new_lines = /[\r\n\u2028]/g;
  1185. var _re_html = /<.*?>/g;
  1186. // This is not strict ISO8601 - Date.parse() is quite lax, although
  1187. // implementations differ between browsers.
  1188. var _re_date = /^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/;
  1189. // Escape regular expression special characters
  1190. var _re_escape_regex = new RegExp( '(\\' + [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ].join('|\\') + ')', 'g' );
  1191. // http://en.wikipedia.org/wiki/Foreign_exchange_market
  1192. // - \u20BD - Russian ruble.
  1193. // - \u20a9 - South Korean Won
  1194. // - \u20BA - Turkish Lira
  1195. // - \u20B9 - Indian Rupee
  1196. // - R - Brazil (R$) and South Africa
  1197. // - fr - Swiss Franc
  1198. // - kr - Swedish krona, Norwegian krone and Danish krone
  1199. // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
  1200. // - Ƀ - Bitcoin
  1201. // - Ξ - Ethereum
  1202. // standards as thousands separators.
  1203. var _re_formatted_numeric = /['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi;
  1204. var _empty = function ( d ) {
  1205. return !d || d === true || d === '-' ? true : false;
  1206. };
  1207. var _intVal = function ( s ) {
  1208. var integer = parseInt( s, 10 );
  1209. return !isNaN(integer) && isFinite(s) ? integer : null;
  1210. };
  1211. // Convert from a formatted number with characters other than `.` as the
  1212. // decimal place, to a Javascript number
  1213. var _numToDecimal = function ( num, decimalPoint ) {
  1214. // Cache created regular expressions for speed as this function is called often
  1215. if ( ! _re_dic[ decimalPoint ] ) {
  1216. _re_dic[ decimalPoint ] = new RegExp( _fnEscapeRegex( decimalPoint ), 'g' );
  1217. }
  1218. return typeof num === 'string' && decimalPoint !== '.' ?
  1219. num.replace( /\./g, '' ).replace( _re_dic[ decimalPoint ], '.' ) :
  1220. num;
  1221. };
  1222. var _isNumber = function ( d, decimalPoint, formatted ) {
  1223. var type = typeof d;
  1224. var strType = type === 'string';
  1225. if ( type === 'number' || type === 'bigint') {
  1226. return true;
  1227. }
  1228. // If empty return immediately so there must be a number if it is a
  1229. // formatted string (this stops the string "k", or "kr", etc being detected
  1230. // as a formatted number for currency
  1231. if ( _empty( d ) ) {
  1232. return true;
  1233. }
  1234. if ( decimalPoint && strType ) {
  1235. d = _numToDecimal( d, decimalPoint );
  1236. }
  1237. if ( formatted && strType ) {
  1238. d = d.replace( _re_formatted_numeric, '' );
  1239. }
  1240. return !isNaN( parseFloat(d) ) && isFinite( d );
  1241. };
  1242. // A string without HTML in it can be considered to be HTML still
  1243. var _isHtml = function ( d ) {
  1244. return _empty( d ) || typeof d === 'string';
  1245. };
  1246. var _htmlNumeric = function ( d, decimalPoint, formatted ) {
  1247. if ( _empty( d ) ) {
  1248. return true;
  1249. }
  1250. var html = _isHtml( d );
  1251. return ! html ?
  1252. null :
  1253. _isNumber( _stripHtml( d ), decimalPoint, formatted ) ?
  1254. true :
  1255. null;
  1256. };
  1257. var _pluck = function ( a, prop, prop2 ) {
  1258. var out = [];
  1259. var i=0, ien=a.length;
  1260. // Could have the test in the loop for slightly smaller code, but speed
  1261. // is essential here
  1262. if ( prop2 !== undefined ) {
  1263. for ( ; i<ien ; i++ ) {
  1264. if ( a[i] && a[i][ prop ] ) {
  1265. out.push( a[i][ prop ][ prop2 ] );
  1266. }
  1267. }
  1268. }
  1269. else {
  1270. for ( ; i<ien ; i++ ) {
  1271. if ( a[i] ) {
  1272. out.push( a[i][ prop ] );
  1273. }
  1274. }
  1275. }
  1276. return out;
  1277. };
  1278. // Basically the same as _pluck, but rather than looping over `a` we use `order`
  1279. // as the indexes to pick from `a`
  1280. var _pluck_order = function ( a, order, prop, prop2 )
  1281. {
  1282. var out = [];
  1283. var i=0, ien=order.length;
  1284. // Could have the test in the loop for slightly smaller code, but speed
  1285. // is essential here
  1286. if ( prop2 !== undefined ) {
  1287. for ( ; i<ien ; i++ ) {
  1288. if ( a[ order[i] ][ prop ] ) {
  1289. out.push( a[ order[i] ][ prop ][ prop2 ] );
  1290. }
  1291. }
  1292. }
  1293. else {
  1294. for ( ; i<ien ; i++ ) {
  1295. out.push( a[ order[i] ][ prop ] );
  1296. }
  1297. }
  1298. return out;
  1299. };
  1300. var _range = function ( len, start )
  1301. {
  1302. var out = [];
  1303. var end;
  1304. if ( start === undefined ) {
  1305. start = 0;
  1306. end = len;
  1307. }
  1308. else {
  1309. end = start;
  1310. start = len;
  1311. }
  1312. for ( var i=start ; i<end ; i++ ) {
  1313. out.push( i );
  1314. }
  1315. return out;
  1316. };
  1317. var _removeEmpty = function ( a )
  1318. {
  1319. var out = [];
  1320. for ( var i=0, ien=a.length ; i<ien ; i++ ) {
  1321. if ( a[i] ) { // careful - will remove all falsy values!
  1322. out.push( a[i] );
  1323. }
  1324. }
  1325. return out;
  1326. };
  1327. var _stripHtml = function ( d ) {
  1328. return d
  1329. .replace( _re_html, '' ) // Complete tags
  1330. .replace(/<script/i, ''); // Safety for incomplete script tag
  1331. };
  1332. /**
  1333. * Determine if all values in the array are unique. This means we can short
  1334. * cut the _unique method at the cost of a single loop. A sorted array is used
  1335. * to easily check the values.
  1336. *
  1337. * @param {array} src Source array
  1338. * @return {boolean} true if all unique, false otherwise
  1339. * @ignore
  1340. */
  1341. var _areAllUnique = function ( src ) {
  1342. if ( src.length < 2 ) {
  1343. return true;
  1344. }
  1345. var sorted = src.slice().sort();
  1346. var last = sorted[0];
  1347. for ( var i=1, ien=sorted.length ; i<ien ; i++ ) {
  1348. if ( sorted[i] === last ) {
  1349. return false;
  1350. }
  1351. last = sorted[i];
  1352. }
  1353. return true;
  1354. };
  1355. /**
  1356. * Find the unique elements in a source array.
  1357. *
  1358. * @param {array} src Source array
  1359. * @return {array} Array of unique items
  1360. * @ignore
  1361. */
  1362. var _unique = function ( src )
  1363. {
  1364. if ( _areAllUnique( src ) ) {
  1365. return src.slice();
  1366. }
  1367. // A faster unique method is to use object keys to identify used values,
  1368. // but this doesn't work with arrays or objects, which we must also
  1369. // consider. See jsperf.com/compare-array-unique-versions/4 for more
  1370. // information.
  1371. var
  1372. out = [],
  1373. val,
  1374. i, ien=src.length,
  1375. j, k=0;
  1376. again: for ( i=0 ; i<ien ; i++ ) {
  1377. val = src[i];
  1378. for ( j=0 ; j<k ; j++ ) {
  1379. if ( out[j] === val ) {
  1380. continue again;
  1381. }
  1382. }
  1383. out.push( val );
  1384. k++;
  1385. }
  1386. return out;
  1387. };
  1388. // Surprisingly this is faster than [].concat.apply
  1389. // https://jsperf.com/flatten-an-array-loop-vs-reduce/2
  1390. var _flatten = function (out, val) {
  1391. if (Array.isArray(val)) {
  1392. for (var i=0 ; i<val.length ; i++) {
  1393. _flatten(out, val[i]);
  1394. }
  1395. }
  1396. else {
  1397. out.push(val);
  1398. }
  1399. return out;
  1400. }
  1401. var _includes = function (search, start) {
  1402. if (start === undefined) {
  1403. start = 0;
  1404. }
  1405. return this.indexOf(search, start) !== -1;
  1406. };
  1407. // Array.isArray polyfill.
  1408. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
  1409. if (! Array.isArray) {
  1410. Array.isArray = function(arg) {
  1411. return Object.prototype.toString.call(arg) === '[object Array]';
  1412. };
  1413. }
  1414. if (! Array.prototype.includes) {
  1415. Array.prototype.includes = _includes;
  1416. }
  1417. // .trim() polyfill
  1418. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
  1419. if (!String.prototype.trim) {
  1420. String.prototype.trim = function () {
  1421. return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  1422. };
  1423. }
  1424. if (! String.prototype.includes) {
  1425. String.prototype.includes = _includes;
  1426. }
  1427. /**
  1428. * DataTables utility methods
  1429. *
  1430. * This namespace provides helper methods that DataTables uses internally to
  1431. * create a DataTable, but which are not exclusively used only for DataTables.
  1432. * These methods can be used by extension authors to save the duplication of
  1433. * code.
  1434. *
  1435. * @namespace
  1436. */
  1437. DataTable.util = {
  1438. /**
  1439. * Throttle the calls to a function. Arguments and context are maintained
  1440. * for the throttled function.
  1441. *
  1442. * @param {function} fn Function to be called
  1443. * @param {integer} freq Call frequency in mS
  1444. * @return {function} Wrapped function
  1445. */
  1446. throttle: function ( fn, freq ) {
  1447. var
  1448. frequency = freq !== undefined ? freq : 200,
  1449. last,
  1450. timer;
  1451. return function () {
  1452. var
  1453. that = this,
  1454. now = +new Date(),
  1455. args = arguments;
  1456. if ( last && now < last + frequency ) {
  1457. clearTimeout( timer );
  1458. timer = setTimeout( function () {
  1459. last = undefined;
  1460. fn.apply( that, args );
  1461. }, frequency );
  1462. }
  1463. else {
  1464. last = now;
  1465. fn.apply( that, args );
  1466. }
  1467. };
  1468. },
  1469. /**
  1470. * Escape a string such that it can be used in a regular expression
  1471. *
  1472. * @param {string} val string to escape
  1473. * @returns {string} escaped string
  1474. */
  1475. escapeRegex: function ( val ) {
  1476. return val.replace( _re_escape_regex, '\\$1' );
  1477. },
  1478. /**
  1479. * Create a function that will write to a nested object or array
  1480. * @param {*} source JSON notation string
  1481. * @returns Write function
  1482. */
  1483. set: function ( source ) {
  1484. if ( $.isPlainObject( source ) ) {
  1485. /* Unlike get, only the underscore (global) option is used for for
  1486. * setting data since we don't know the type here. This is why an object
  1487. * option is not documented for `mData` (which is read/write), but it is
  1488. * for `mRender` which is read only.
  1489. */
  1490. return DataTable.util.set( source._ );
  1491. }
  1492. else if ( source === null ) {
  1493. // Nothing to do when the data source is null
  1494. return function () {};
  1495. }
  1496. else if ( typeof source === 'function' ) {
  1497. return function (data, val, meta) {
  1498. source( data, 'set', val, meta );
  1499. };
  1500. }
  1501. else if ( typeof source === 'string' && (source.indexOf('.') !== -1 ||
  1502. source.indexOf('[') !== -1 || source.indexOf('(') !== -1) )
  1503. {
  1504. // Like the get, we need to get data from a nested object
  1505. var setData = function (data, val, src) {
  1506. var a = _fnSplitObjNotation( src ), b;
  1507. var aLast = a[a.length-1];
  1508. var arrayNotation, funcNotation, o, innerSrc;
  1509. for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ ) {
  1510. // Protect against prototype pollution
  1511. if (a[i] === '__proto__' || a[i] === 'constructor') {
  1512. throw new Error('Cannot set prototype values');
  1513. }
  1514. // Check if we are dealing with an array notation request
  1515. arrayNotation = a[i].match(__reArray);
  1516. funcNotation = a[i].match(__reFn);
  1517. if ( arrayNotation ) {
  1518. a[i] = a[i].replace(__reArray, '');
  1519. data[ a[i] ] = [];
  1520. // Get the remainder of the nested object to set so we can recurse
  1521. b = a.slice();
  1522. b.splice( 0, i+1 );
  1523. innerSrc = b.join('.');
  1524. // Traverse each entry in the array setting the properties requested
  1525. if ( Array.isArray( val ) ) {
  1526. for ( var j=0, jLen=val.length ; j<jLen ; j++ ) {
  1527. o = {};
  1528. setData( o, val[j], innerSrc );
  1529. data[ a[i] ].push( o );
  1530. }
  1531. }
  1532. else {
  1533. // We've been asked to save data to an array, but it
  1534. // isn't array data to be saved. Best that can be done
  1535. // is to just save the value.
  1536. data[ a[i] ] = val;
  1537. }
  1538. // The inner call to setData has already traversed through the remainder
  1539. // of the source and has set the data, thus we can exit here
  1540. return;
  1541. }
  1542. else if ( funcNotation ) {
  1543. // Function call
  1544. a[i] = a[i].replace(__reFn, '');
  1545. data = data[ a[i] ]( val );
  1546. }
  1547. // If the nested object doesn't currently exist - since we are
  1548. // trying to set the value - create it
  1549. if ( data[ a[i] ] === null || data[ a[i] ] === undefined ) {
  1550. data[ a[i] ] = {};
  1551. }
  1552. data = data[ a[i] ];
  1553. }
  1554. // Last item in the input - i.e, the actual set
  1555. if ( aLast.match(__reFn ) ) {
  1556. // Function call
  1557. data = data[ aLast.replace(__reFn, '') ]( val );
  1558. }
  1559. else {
  1560. // If array notation is used, we just want to strip it and use the property name
  1561. // and assign the value. If it isn't used, then we get the result we want anyway
  1562. data[ aLast.replace(__reArray, '') ] = val;
  1563. }
  1564. };
  1565. return function (data, val) { // meta is also passed in, but not used
  1566. return setData( data, val, source );
  1567. };
  1568. }
  1569. else {
  1570. // Array or flat object mapping
  1571. return function (data, val) { // meta is also passed in, but not used
  1572. data[source] = val;
  1573. };
  1574. }
  1575. },
  1576. /**
  1577. * Create a function that will read nested objects from arrays, based on JSON notation
  1578. * @param {*} source JSON notation string
  1579. * @returns Value read
  1580. */
  1581. get: function ( source ) {
  1582. if ( $.isPlainObject( source ) ) {
  1583. // Build an object of get functions, and wrap them in a single call
  1584. var o = {};
  1585. $.each( source, function (key, val) {
  1586. if ( val ) {
  1587. o[key] = DataTable.util.get( val );
  1588. }
  1589. } );
  1590. return function (data, type, row, meta) {
  1591. var t = o[type] || o._;
  1592. return t !== undefined ?
  1593. t(data, type, row, meta) :
  1594. data;
  1595. };
  1596. }
  1597. else if ( source === null ) {
  1598. // Give an empty string for rendering / sorting etc
  1599. return function (data) { // type, row and meta also passed, but not used
  1600. return data;
  1601. };
  1602. }
  1603. else if ( typeof source === 'function' ) {
  1604. return function (data, type, row, meta) {
  1605. return source( data, type, row, meta );
  1606. };
  1607. }
  1608. else if ( typeof source === 'string' && (source.indexOf('.') !== -1 ||
  1609. source.indexOf('[') !== -1 || source.indexOf('(') !== -1) )
  1610. {
  1611. /* If there is a . in the source string then the data source is in a
  1612. * nested object so we loop over the data for each level to get the next
  1613. * level down. On each loop we test for undefined, and if found immediately
  1614. * return. This allows entire objects to be missing and sDefaultContent to
  1615. * be used if defined, rather than throwing an error
  1616. */
  1617. var fetchData = function (data, type, src) {
  1618. var arrayNotation, funcNotation, out, innerSrc;
  1619. if ( src !== "" ) {
  1620. var a = _fnSplitObjNotation( src );
  1621. for ( var i=0, iLen=a.length ; i<iLen ; i++ ) {
  1622. // Check if we are dealing with special notation
  1623. arrayNotation = a[i].match(__reArray);
  1624. funcNotation = a[i].match(__reFn);
  1625. if ( arrayNotation ) {
  1626. // Array notation
  1627. a[i] = a[i].replace(__reArray, '');
  1628. // Condition allows simply [] to be passed in
  1629. if ( a[i] !== "" ) {
  1630. data = data[ a[i] ];
  1631. }
  1632. out = [];
  1633. // Get the remainder of the nested object to get
  1634. a.splice( 0, i+1 );
  1635. innerSrc = a.join('.');
  1636. // Traverse each entry in the array getting the properties requested
  1637. if ( Array.isArray( data ) ) {
  1638. for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
  1639. out.push( fetchData( data[j], type, innerSrc ) );
  1640. }
  1641. }
  1642. // If a string is given in between the array notation indicators, that
  1643. // is used to join the strings together, otherwise an array is returned
  1644. var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
  1645. data = (join==="") ? out : out.join(join);
  1646. // The inner call to fetchData has already traversed through the remainder
  1647. // of the source requested, so we exit from the loop
  1648. break;
  1649. }
  1650. else if ( funcNotation ) {
  1651. // Function call
  1652. a[i] = a[i].replace(__reFn, '');
  1653. data = data[ a[i] ]();
  1654. continue;
  1655. }
  1656. if (data === null || data[ a[i] ] === null) {
  1657. return null;
  1658. }
  1659. else if ( data === undefined || data[ a[i] ] === undefined ) {
  1660. return undefined;
  1661. }
  1662. data = data[ a[i] ];
  1663. }
  1664. }
  1665. return data;
  1666. };
  1667. return function (data, type) { // row and meta also passed, but not used
  1668. return fetchData( data, type, source );
  1669. };
  1670. }
  1671. else {
  1672. // Array or flat object mapping
  1673. return function (data, type) { // row and meta also passed, but not used
  1674. return data[source];
  1675. };
  1676. }
  1677. }
  1678. };
  1679. /**
  1680. * Create a mapping object that allows camel case parameters to be looked up
  1681. * for their Hungarian counterparts. The mapping is stored in a private
  1682. * parameter called `_hungarianMap` which can be accessed on the source object.
  1683. * @param {object} o
  1684. * @memberof DataTable#oApi
  1685. */
  1686. function _fnHungarianMap ( o )
  1687. {
  1688. var
  1689. hungarian = 'a aa ai ao as b fn i m o s ',
  1690. match,
  1691. newKey,
  1692. map = {};
  1693. $.each( o, function (key, val) {
  1694. match = key.match(/^([^A-Z]+?)([A-Z])/);
  1695. if ( match && hungarian.indexOf(match[1]+' ') !== -1 )
  1696. {
  1697. newKey = key.replace( match[0], match[2].toLowerCase() );
  1698. map[ newKey ] = key;
  1699. if ( match[1] === 'o' )
  1700. {
  1701. _fnHungarianMap( o[key] );
  1702. }
  1703. }
  1704. } );
  1705. o._hungarianMap = map;
  1706. }
  1707. /**
  1708. * Convert from camel case parameters to Hungarian, based on a Hungarian map
  1709. * created by _fnHungarianMap.
  1710. * @param {object} src The model object which holds all parameters that can be
  1711. * mapped.
  1712. * @param {object} user The object to convert from camel case to Hungarian.
  1713. * @param {boolean} force When set to `true`, properties which already have a
  1714. * Hungarian value in the `user` object will be overwritten. Otherwise they
  1715. * won't be.
  1716. * @memberof DataTable#oApi
  1717. */
  1718. function _fnCamelToHungarian ( src, user, force )
  1719. {
  1720. if ( ! src._hungarianMap ) {
  1721. _fnHungarianMap( src );
  1722. }
  1723. var hungarianKey;
  1724. $.each( user, function (key, val) {
  1725. hungarianKey = src._hungarianMap[ key ];
  1726. if ( hungarianKey !== undefined && (force || user[hungarianKey] === undefined) )
  1727. {
  1728. // For objects, we need to buzz down into the object to copy parameters
  1729. if ( hungarianKey.charAt(0) === 'o' )
  1730. {
  1731. // Copy the camelCase options over to the hungarian
  1732. if ( ! user[ hungarianKey ] ) {
  1733. user[ hungarianKey ] = {};
  1734. }
  1735. $.extend( true, user[hungarianKey], user[key] );
  1736. _fnCamelToHungarian( src[hungarianKey], user[hungarianKey], force );
  1737. }
  1738. else {
  1739. user[hungarianKey] = user[ key ];
  1740. }
  1741. }
  1742. } );
  1743. }
  1744. /**
  1745. * Language compatibility - when certain options are given, and others aren't, we
  1746. * need to duplicate the values over, in order to provide backwards compatibility
  1747. * with older language files.
  1748. * @param {object} oSettings dataTables settings object
  1749. * @memberof DataTable#oApi
  1750. */
  1751. function _fnLanguageCompat( lang )
  1752. {
  1753. // Note the use of the Hungarian notation for the parameters in this method as
  1754. // this is called after the mapping of camelCase to Hungarian
  1755. var defaults = DataTable.defaults.oLanguage;
  1756. // Default mapping
  1757. var defaultDecimal = defaults.sDecimal;
  1758. if ( defaultDecimal ) {
  1759. _addNumericSort( defaultDecimal );
  1760. }
  1761. if ( lang ) {
  1762. var zeroRecords = lang.sZeroRecords;
  1763. // Backwards compatibility - if there is no sEmptyTable given, then use the same as
  1764. // sZeroRecords - assuming that is given.
  1765. if ( ! lang.sEmptyTable && zeroRecords &&
  1766. defaults.sEmptyTable === "No data available in table" )
  1767. {
  1768. _fnMap( lang, lang, 'sZeroRecords', 'sEmptyTable' );
  1769. }
  1770. // Likewise with loading records
  1771. if ( ! lang.sLoadingRecords && zeroRecords &&
  1772. defaults.sLoadingRecords === "Loading..." )
  1773. {
  1774. _fnMap( lang, lang, 'sZeroRecords', 'sLoadingRecords' );
  1775. }
  1776. // Old parameter name of the thousands separator mapped onto the new
  1777. if ( lang.sInfoThousands ) {
  1778. lang.sThousands = lang.sInfoThousands;
  1779. }
  1780. var decimal = lang.sDecimal;
  1781. if ( decimal && defaultDecimal !== decimal ) {
  1782. _addNumericSort( decimal );
  1783. }
  1784. }
  1785. }
  1786. /**
  1787. * Map one parameter onto another
  1788. * @param {object} o Object to map
  1789. * @param {*} knew The new parameter name
  1790. * @param {*} old The old parameter name
  1791. */
  1792. var _fnCompatMap = function ( o, knew, old ) {
  1793. if ( o[ knew ] !== undefined ) {
  1794. o[ old ] = o[ knew ];
  1795. }
  1796. };
  1797. /**
  1798. * Provide backwards compatibility for the main DT options. Note that the new
  1799. * options are mapped onto the old parameters, so this is an external interface
  1800. * change only.
  1801. * @param {object} init Object to map
  1802. */
  1803. function _fnCompatOpts ( init )
  1804. {
  1805. _fnCompatMap( init, 'ordering', 'bSort' );
  1806. _fnCompatMap( init, 'orderMulti', 'bSortMulti' );
  1807. _fnCompatMap( init, 'orderClasses', 'bSortClasses' );
  1808. _fnCompatMap( init, 'orderCellsTop', 'bSortCellsTop' );
  1809. _fnCompatMap( init, 'order', 'aaSorting' );
  1810. _fnCompatMap( init, 'orderFixed', 'aaSortingFixed' );
  1811. _fnCompatMap( init, 'paging', 'bPaginate' );
  1812. _fnCompatMap( init, 'pagingType', 'sPaginationType' );
  1813. _fnCompatMap( init, 'pageLength', 'iDisplayLength' );
  1814. _fnCompatMap( init, 'searching', 'bFilter' );
  1815. // Boolean initialisation of x-scrolling
  1816. if ( typeof init.sScrollX === 'boolean' ) {
  1817. init.sScrollX = init.sScrollX ? '100%' : '';
  1818. }
  1819. if ( typeof init.scrollX === 'boolean' ) {
  1820. init.scrollX = init.scrollX ? '100%' : '';
  1821. }
  1822. // Column search objects are in an array, so it needs to be converted
  1823. // element by element
  1824. var searchCols = init.aoSearchCols;
  1825. if ( searchCols ) {
  1826. for ( var i=0, ien=searchCols.length ; i<ien ; i++ ) {
  1827. if ( searchCols[i] ) {
  1828. _fnCamelToHungarian( DataTable.models.oSearch, searchCols[i] );
  1829. }
  1830. }
  1831. }
  1832. }
  1833. /**
  1834. * Provide backwards compatibility for column options. Note that the new options
  1835. * are mapped onto the old parameters, so this is an external interface change
  1836. * only.
  1837. * @param {object} init Object to map
  1838. */
  1839. function _fnCompatCols ( init )
  1840. {
  1841. _fnCompatMap( init, 'orderable', 'bSortable' );
  1842. _fnCompatMap( init, 'orderData', 'aDataSort' );
  1843. _fnCompatMap( init, 'orderSequence', 'asSorting' );
  1844. _fnCompatMap( init, 'orderDataType', 'sortDataType' );
  1845. // orderData can be given as an integer
  1846. var dataSort = init.aDataSort;
  1847. if ( typeof dataSort === 'number' && ! Array.isArray( dataSort ) ) {
  1848. init.aDataSort = [ dataSort ];
  1849. }
  1850. }
  1851. /**
  1852. * Browser feature detection for capabilities, quirks
  1853. * @param {object} settings dataTables settings object
  1854. * @memberof DataTable#oApi
  1855. */
  1856. function _fnBrowserDetect( settings )
  1857. {
  1858. // We don't need to do this every time DataTables is constructed, the values
  1859. // calculated are specific to the browser and OS configuration which we
  1860. // don't expect to change between initialisations
  1861. if ( ! DataTable.__browser ) {
  1862. var browser = {};
  1863. DataTable.__browser = browser;
  1864. // Scrolling feature / quirks detection
  1865. var n = $('<div/>')
  1866. .css( {
  1867. position: 'fixed',
  1868. top: 0,
  1869. left: $(window).scrollLeft()*-1, // allow for scrolling
  1870. height: 1,
  1871. width: 1,
  1872. overflow: 'hidden'
  1873. } )
  1874. .append(
  1875. $('<div/>')
  1876. .css( {
  1877. position: 'absolute',
  1878. top: 1,
  1879. left: 1,
  1880. width: 100,
  1881. overflow: 'scroll'
  1882. } )
  1883. .append(
  1884. $('<div/>')
  1885. .css( {
  1886. width: '100%',
  1887. height: 10
  1888. } )
  1889. )
  1890. )
  1891. .appendTo( 'body' );
  1892. var outer = n.children();
  1893. var inner = outer.children();
  1894. // Numbers below, in order, are:
  1895. // inner.offsetWidth, inner.clientWidth, outer.offsetWidth, outer.clientWidth
  1896. //
  1897. // IE6 XP: 100 100 100 83
  1898. // IE7 Vista: 100 100 100 83
  1899. // IE 8+ Windows: 83 83 100 83
  1900. // Evergreen Windows: 83 83 100 83
  1901. // Evergreen Mac with scrollbars: 85 85 100 85
  1902. // Evergreen Mac without scrollbars: 100 100 100 100
  1903. // Get scrollbar width
  1904. browser.barWidth = outer[0].offsetWidth - outer[0].clientWidth;
  1905. // IE6/7 will oversize a width 100% element inside a scrolling element, to
  1906. // include the width of the scrollbar, while other browsers ensure the inner
  1907. // element is contained without forcing scrolling
  1908. browser.bScrollOversize = inner[0].offsetWidth === 100 && outer[0].clientWidth !== 100;
  1909. // In rtl text layout, some browsers (most, but not all) will place the
  1910. // scrollbar on the left, rather than the right.
  1911. browser.bScrollbarLeft = Math.round( inner.offset().left ) !== 1;
  1912. // IE8- don't provide height and width for getBoundingClientRect
  1913. browser.bBounding = n[0].getBoundingClientRect().width ? true : false;
  1914. n.remove();
  1915. }
  1916. $.extend( settings.oBrowser, DataTable.__browser );
  1917. settings.oScroll.iBarWidth = DataTable.__browser.barWidth;
  1918. }
  1919. /**
  1920. * Array.prototype reduce[Right] method, used for browsers which don't support
  1921. * JS 1.6. Done this way to reduce code size, since we iterate either way
  1922. * @param {object} settings dataTables settings object
  1923. * @memberof DataTable#oApi
  1924. */
  1925. function _fnReduce ( that, fn, init, start, end, inc )
  1926. {
  1927. var
  1928. i = start,
  1929. value,
  1930. isSet = false;
  1931. if ( init !== undefined ) {
  1932. value = init;
  1933. isSet = true;
  1934. }
  1935. while ( i !== end ) {
  1936. if ( ! that.hasOwnProperty(i) ) {
  1937. continue;
  1938. }
  1939. value = isSet ?
  1940. fn( value, that[i], i, that ) :
  1941. that[i];
  1942. isSet = true;
  1943. i += inc;
  1944. }
  1945. return value;
  1946. }
  1947. /**
  1948. * Add a column to the list used for the table with default values
  1949. * @param {object} oSettings dataTables settings object
  1950. * @param {node} nTh The th element for this column
  1951. * @memberof DataTable#oApi
  1952. */
  1953. function _fnAddColumn( oSettings, nTh )
  1954. {
  1955. // Add column to aoColumns array
  1956. var oDefaults = DataTable.defaults.column;
  1957. var iCol = oSettings.aoColumns.length;
  1958. var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
  1959. "nTh": nTh ? nTh : document.createElement('th'),
  1960. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  1961. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  1962. "mData": oDefaults.mData ? oDefaults.mData : iCol,
  1963. idx: iCol
  1964. } );
  1965. oSettings.aoColumns.push( oCol );
  1966. // Add search object for column specific search. Note that the `searchCols[ iCol ]`
  1967. // passed into extend can be undefined. This allows the user to give a default
  1968. // with only some of the parameters defined, and also not give a default
  1969. var searchCols = oSettings.aoPreSearchCols;
  1970. searchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch, searchCols[ iCol ] );
  1971. // Use the default column options function to initialise classes etc
  1972. _fnColumnOptions( oSettings, iCol, $(nTh).data() );
  1973. }
  1974. /**
  1975. * Apply options for a column
  1976. * @param {object} oSettings dataTables settings object
  1977. * @param {int} iCol column index to consider
  1978. * @param {object} oOptions object with sType, bVisible and bSearchable etc
  1979. * @memberof DataTable#oApi
  1980. */
  1981. function _fnColumnOptions( oSettings, iCol, oOptions )
  1982. {
  1983. var oCol = oSettings.aoColumns[ iCol ];
  1984. var oClasses = oSettings.oClasses;
  1985. var th = $(oCol.nTh);
  1986. // Try to get width information from the DOM. We can't get it from CSS
  1987. // as we'd need to parse the CSS stylesheet. `width` option can override
  1988. if ( ! oCol.sWidthOrig ) {
  1989. // Width attribute
  1990. oCol.sWidthOrig = th.attr('width') || null;
  1991. // Style attribute
  1992. var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
  1993. if ( t ) {
  1994. oCol.sWidthOrig = t[1];
  1995. }
  1996. }
  1997. /* User specified column options */
  1998. if ( oOptions !== undefined && oOptions !== null )
  1999. {
  2000. // Backwards compatibility
  2001. _fnCompatCols( oOptions );
  2002. // Map camel case parameters to their Hungarian counterparts
  2003. _fnCamelToHungarian( DataTable.defaults.column, oOptions, true );
  2004. /* Backwards compatibility for mDataProp */
  2005. if ( oOptions.mDataProp !== undefined && !oOptions.mData )
  2006. {
  2007. oOptions.mData = oOptions.mDataProp;
  2008. }
  2009. if ( oOptions.sType )
  2010. {
  2011. oCol._sManualType = oOptions.sType;
  2012. }
  2013. // `class` is a reserved word in Javascript, so we need to provide
  2014. // the ability to use a valid name for the camel case input
  2015. if ( oOptions.className && ! oOptions.sClass )
  2016. {
  2017. oOptions.sClass = oOptions.className;
  2018. }
  2019. if ( oOptions.sClass ) {
  2020. th.addClass( oOptions.sClass );
  2021. }
  2022. var origClass = oCol.sClass;
  2023. $.extend( oCol, oOptions );
  2024. _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
  2025. // Merge class from previously defined classes with this one, rather than just
  2026. // overwriting it in the extend above
  2027. if (origClass !== oCol.sClass) {
  2028. oCol.sClass = origClass + ' ' + oCol.sClass;
  2029. }
  2030. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  2031. * priority if defined
  2032. */
  2033. if ( oOptions.iDataSort !== undefined )
  2034. {
  2035. oCol.aDataSort = [ oOptions.iDataSort ];
  2036. }
  2037. _fnMap( oCol, oOptions, "aDataSort" );
  2038. }
  2039. /* Cache the data get and set functions for speed */
  2040. var mDataSrc = oCol.mData;
  2041. var mData = _fnGetObjectDataFn( mDataSrc );
  2042. var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
  2043. var attrTest = function( src ) {
  2044. return typeof src === 'string' && src.indexOf('@') !== -1;
  2045. };
  2046. oCol._bAttrSrc = $.isPlainObject( mDataSrc ) && (
  2047. attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter)
  2048. );
  2049. oCol._setter = null;
  2050. oCol.fnGetData = function (rowData, type, meta) {
  2051. var innerData = mData( rowData, type, undefined, meta );
  2052. return mRender && type ?
  2053. mRender( innerData, type, rowData, meta ) :
  2054. innerData;
  2055. };
  2056. oCol.fnSetData = function ( rowData, val, meta ) {
  2057. return _fnSetObjectDataFn( mDataSrc )( rowData, val, meta );
  2058. };
  2059. // Indicate if DataTables should read DOM data as an object or array
  2060. // Used in _fnGetRowElements
  2061. if ( typeof mDataSrc !== 'number' && ! oCol._isArrayHost ) {
  2062. oSettings._rowReadObject = true;
  2063. }
  2064. /* Feature sorting overrides column specific when off */
  2065. if ( !oSettings.oFeatures.bSort )
  2066. {
  2067. oCol.bSortable = false;
  2068. th.addClass( oClasses.sSortableNone ); // Have to add class here as order event isn't called
  2069. }
  2070. /* Check that the class assignment is correct for sorting */
  2071. var bAsc = $.inArray('asc', oCol.asSorting) !== -1;
  2072. var bDesc = $.inArray('desc', oCol.asSorting) !== -1;
  2073. if ( !oCol.bSortable || (!bAsc && !bDesc) )
  2074. {
  2075. oCol.sSortingClass = oClasses.sSortableNone;
  2076. oCol.sSortingClassJUI = "";
  2077. }
  2078. else if ( bAsc && !bDesc )
  2079. {
  2080. oCol.sSortingClass = oClasses.sSortableAsc;
  2081. oCol.sSortingClassJUI = oClasses.sSortJUIAscAllowed;
  2082. }
  2083. else if ( !bAsc && bDesc )
  2084. {
  2085. oCol.sSortingClass = oClasses.sSortableDesc;
  2086. oCol.sSortingClassJUI = oClasses.sSortJUIDescAllowed;
  2087. }
  2088. else
  2089. {
  2090. oCol.sSortingClass = oClasses.sSortable;
  2091. oCol.sSortingClassJUI = oClasses.sSortJUI;
  2092. }
  2093. }
  2094. /**
  2095. * Adjust the table column widths for new data. Note: you would probably want to
  2096. * do a redraw after calling this function!
  2097. * @param {object} settings dataTables settings object
  2098. * @memberof DataTable#oApi
  2099. */
  2100. function _fnAdjustColumnSizing ( settings )
  2101. {
  2102. /* Not interested in doing column width calculation if auto-width is disabled */
  2103. if ( settings.oFeatures.bAutoWidth !== false )
  2104. {
  2105. var columns = settings.aoColumns;
  2106. _fnCalculateColumnWidths( settings );
  2107. for ( var i=0 , iLen=columns.length ; i<iLen ; i++ )
  2108. {
  2109. columns[i].nTh.style.width = columns[i].sWidth;
  2110. }
  2111. }
  2112. var scroll = settings.oScroll;
  2113. if ( scroll.sY !== '' || scroll.sX !== '')
  2114. {
  2115. _fnScrollDraw( settings );
  2116. }
  2117. _fnCallbackFire( settings, null, 'column-sizing', [settings] );
  2118. }
  2119. /**
  2120. * Convert the index of a visible column to the index in the data array (take account
  2121. * of hidden columns)
  2122. * @param {object} oSettings dataTables settings object
  2123. * @param {int} iMatch Visible column index to lookup
  2124. * @returns {int} i the data index
  2125. * @memberof DataTable#oApi
  2126. */
  2127. function _fnVisibleToColumnIndex( oSettings, iMatch )
  2128. {
  2129. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  2130. return typeof aiVis[iMatch] === 'number' ?
  2131. aiVis[iMatch] :
  2132. null;
  2133. }
  2134. /**
  2135. * Convert the index of an index in the data array and convert it to the visible
  2136. * column index (take account of hidden columns)
  2137. * @param {int} iMatch Column index to lookup
  2138. * @param {object} oSettings dataTables settings object
  2139. * @returns {int} i the data index
  2140. * @memberof DataTable#oApi
  2141. */
  2142. function _fnColumnIndexToVisible( oSettings, iMatch )
  2143. {
  2144. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  2145. var iPos = $.inArray( iMatch, aiVis );
  2146. return iPos !== -1 ? iPos : null;
  2147. }
  2148. /**
  2149. * Get the number of visible columns
  2150. * @param {object} oSettings dataTables settings object
  2151. * @returns {int} i the number of visible columns
  2152. * @memberof DataTable#oApi
  2153. */
  2154. function _fnVisbleColumns( oSettings )
  2155. {
  2156. var vis = 0;
  2157. // No reduce in IE8, use a loop for now
  2158. $.each( oSettings.aoColumns, function ( i, col ) {
  2159. if ( col.bVisible && $(col.nTh).css('display') !== 'none' ) {
  2160. vis++;
  2161. }
  2162. } );
  2163. return vis;
  2164. }
  2165. /**
  2166. * Get an array of column indexes that match a given property
  2167. * @param {object} oSettings dataTables settings object
  2168. * @param {string} sParam Parameter in aoColumns to look for - typically
  2169. * bVisible or bSearchable
  2170. * @returns {array} Array of indexes with matched properties
  2171. * @memberof DataTable#oApi
  2172. */
  2173. function _fnGetColumns( oSettings, sParam )
  2174. {
  2175. var a = [];
  2176. $.map( oSettings.aoColumns, function(val, i) {
  2177. if ( val[sParam] ) {
  2178. a.push( i );
  2179. }
  2180. } );
  2181. return a;
  2182. }
  2183. /**
  2184. * Calculate the 'type' of a column
  2185. * @param {object} settings dataTables settings object
  2186. * @memberof DataTable#oApi
  2187. */
  2188. function _fnColumnTypes ( settings )
  2189. {
  2190. var columns = settings.aoColumns;
  2191. var data = settings.aoData;
  2192. var types = DataTable.ext.type.detect;
  2193. var i, ien, j, jen, k, ken;
  2194. var col, cell, detectedType, cache;
  2195. // For each column, spin over the
  2196. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  2197. col = columns[i];
  2198. cache = [];
  2199. if ( ! col.sType && col._sManualType ) {
  2200. col.sType = col._sManualType;
  2201. }
  2202. else if ( ! col.sType ) {
  2203. for ( j=0, jen=types.length ; j<jen ; j++ ) {
  2204. for ( k=0, ken=data.length ; k<ken ; k++ ) {
  2205. // Use a cache array so we only need to get the type data
  2206. // from the formatter once (when using multiple detectors)
  2207. if ( cache[k] === undefined ) {
  2208. cache[k] = _fnGetCellData( settings, k, i, 'type' );
  2209. }
  2210. detectedType = types[j]( cache[k], settings );
  2211. // If null, then this type can't apply to this column, so
  2212. // rather than testing all cells, break out. There is an
  2213. // exception for the last type which is `html`. We need to
  2214. // scan all rows since it is possible to mix string and HTML
  2215. // types
  2216. if ( ! detectedType && j !== types.length-1 ) {
  2217. break;
  2218. }
  2219. // Only a single match is needed for html type since it is
  2220. // bottom of the pile and very similar to string - but it
  2221. // must not be empty
  2222. if ( detectedType === 'html' && ! _empty(cache[k]) ) {
  2223. break;
  2224. }
  2225. }
  2226. // Type is valid for all data points in the column - use this
  2227. // type
  2228. if ( detectedType ) {
  2229. col.sType = detectedType;
  2230. break;
  2231. }
  2232. }
  2233. // Fall back - if no type was detected, always use string
  2234. if ( ! col.sType ) {
  2235. col.sType = 'string';
  2236. }
  2237. }
  2238. }
  2239. }
  2240. /**
  2241. * Take the column definitions and static columns arrays and calculate how
  2242. * they relate to column indexes. The callback function will then apply the
  2243. * definition found for a column to a suitable configuration object.
  2244. * @param {object} oSettings dataTables settings object
  2245. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  2246. * @param {array} aoCols The aoColumns array that defines columns individually
  2247. * @param {function} fn Callback function - takes two parameters, the calculated
  2248. * column index and the definition for that column.
  2249. * @memberof DataTable#oApi
  2250. */
  2251. function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
  2252. {
  2253. var i, iLen, j, jLen, k, kLen, def;
  2254. var columns = oSettings.aoColumns;
  2255. // Column definitions with aTargets
  2256. if ( aoColDefs )
  2257. {
  2258. /* Loop over the definitions array - loop in reverse so first instance has priority */
  2259. for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
  2260. {
  2261. def = aoColDefs[i];
  2262. /* Each definition can target multiple columns, as it is an array */
  2263. var aTargets = def.target !== undefined
  2264. ? def.target
  2265. : def.targets !== undefined
  2266. ? def.targets
  2267. : def.aTargets;
  2268. if ( ! Array.isArray( aTargets ) )
  2269. {
  2270. aTargets = [ aTargets ];
  2271. }
  2272. for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
  2273. {
  2274. if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
  2275. {
  2276. /* Add columns that we don't yet know about */
  2277. while( columns.length <= aTargets[j] )
  2278. {
  2279. _fnAddColumn( oSettings );
  2280. }
  2281. /* Integer, basic index */
  2282. fn( aTargets[j], def );
  2283. }
  2284. else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
  2285. {
  2286. /* Negative integer, right to left column counting */
  2287. fn( columns.length+aTargets[j], def );
  2288. }
  2289. else if ( typeof aTargets[j] === 'string' )
  2290. {
  2291. /* Class name matching on TH element */
  2292. for ( k=0, kLen=columns.length ; k<kLen ; k++ )
  2293. {
  2294. if ( aTargets[j] == "_all" ||
  2295. $(columns[k].nTh).hasClass( aTargets[j] ) )
  2296. {
  2297. fn( k, def );
  2298. }
  2299. }
  2300. }
  2301. }
  2302. }
  2303. }
  2304. // Statically defined columns array
  2305. if ( aoCols )
  2306. {
  2307. for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
  2308. {
  2309. fn( i, aoCols[i] );
  2310. }
  2311. }
  2312. }
  2313. /**
  2314. * Add a data array to the table, creating DOM node etc. This is the parallel to
  2315. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  2316. * DOM source.
  2317. * @param {object} oSettings dataTables settings object
  2318. * @param {array} aData data array to be added
  2319. * @param {node} [nTr] TR element to add to the table - optional. If not given,
  2320. * DataTables will create a row automatically
  2321. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2322. * if nTr is.
  2323. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  2324. * @memberof DataTable#oApi
  2325. */
  2326. function _fnAddData ( oSettings, aDataIn, nTr, anTds )
  2327. {
  2328. /* Create the object for storing information about this new row */
  2329. var iRow = oSettings.aoData.length;
  2330. var oData = $.extend( true, {}, DataTable.models.oRow, {
  2331. src: nTr ? 'dom' : 'data',
  2332. idx: iRow
  2333. } );
  2334. oData._aData = aDataIn;
  2335. oSettings.aoData.push( oData );
  2336. /* Create the cells */
  2337. var nTd, sThisType;
  2338. var columns = oSettings.aoColumns;
  2339. // Invalidate the column types as the new data needs to be revalidated
  2340. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  2341. {
  2342. columns[i].sType = null;
  2343. }
  2344. /* Add to the display array */
  2345. oSettings.aiDisplayMaster.push( iRow );
  2346. var id = oSettings.rowIdFn( aDataIn );
  2347. if ( id !== undefined ) {
  2348. oSettings.aIds[ id ] = oData;
  2349. }
  2350. /* Create the DOM information, or register it if already present */
  2351. if ( nTr || ! oSettings.oFeatures.bDeferRender )
  2352. {
  2353. _fnCreateTr( oSettings, iRow, nTr, anTds );
  2354. }
  2355. return iRow;
  2356. }
  2357. /**
  2358. * Add one or more TR elements to the table. Generally we'd expect to
  2359. * use this for reading data from a DOM sourced table, but it could be
  2360. * used for an TR element. Note that if a TR is given, it is used (i.e.
  2361. * it is not cloned).
  2362. * @param {object} settings dataTables settings object
  2363. * @param {array|node|jQuery} trs The TR element(s) to add to the table
  2364. * @returns {array} Array of indexes for the added rows
  2365. * @memberof DataTable#oApi
  2366. */
  2367. function _fnAddTr( settings, trs )
  2368. {
  2369. var row;
  2370. // Allow an individual node to be passed in
  2371. if ( ! (trs instanceof $) ) {
  2372. trs = $(trs);
  2373. }
  2374. return trs.map( function (i, el) {
  2375. row = _fnGetRowElements( settings, el );
  2376. return _fnAddData( settings, row.data, el, row.cells );
  2377. } );
  2378. }
  2379. /**
  2380. * Take a TR element and convert it to an index in aoData
  2381. * @param {object} oSettings dataTables settings object
  2382. * @param {node} n the TR element to find
  2383. * @returns {int} index if the node is found, null if not
  2384. * @memberof DataTable#oApi
  2385. */
  2386. function _fnNodeToDataIndex( oSettings, n )
  2387. {
  2388. return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
  2389. }
  2390. /**
  2391. * Take a TD element and convert it into a column data index (not the visible index)
  2392. * @param {object} oSettings dataTables settings object
  2393. * @param {int} iRow The row number the TD/TH can be found in
  2394. * @param {node} n The TD/TH element to find
  2395. * @returns {int} index if the node is found, -1 if not
  2396. * @memberof DataTable#oApi
  2397. */
  2398. function _fnNodeToColumnIndex( oSettings, iRow, n )
  2399. {
  2400. return $.inArray( n, oSettings.aoData[ iRow ].anCells );
  2401. }
  2402. /**
  2403. * Get the data for a given cell from the internal cache, taking into account data mapping
  2404. * @param {object} settings dataTables settings object
  2405. * @param {int} rowIdx aoData row id
  2406. * @param {int} colIdx Column index
  2407. * @param {string} type data get type ('display', 'type' 'filter|search' 'sort|order')
  2408. * @returns {*} Cell data
  2409. * @memberof DataTable#oApi
  2410. */
  2411. function _fnGetCellData( settings, rowIdx, colIdx, type )
  2412. {
  2413. if (type === 'search') {
  2414. type = 'filter';
  2415. }
  2416. else if (type === 'order') {
  2417. type = 'sort';
  2418. }
  2419. var draw = settings.iDraw;
  2420. var col = settings.aoColumns[colIdx];
  2421. var rowData = settings.aoData[rowIdx]._aData;
  2422. var defaultContent = col.sDefaultContent;
  2423. var cellData = col.fnGetData( rowData, type, {
  2424. settings: settings,
  2425. row: rowIdx,
  2426. col: colIdx
  2427. } );
  2428. if ( cellData === undefined ) {
  2429. if ( settings.iDrawError != draw && defaultContent === null ) {
  2430. _fnLog( settings, 0, "Requested unknown parameter "+
  2431. (typeof col.mData=='function' ? '{function}' : "'"+col.mData+"'")+
  2432. " for row "+rowIdx+", column "+colIdx, 4 );
  2433. settings.iDrawError = draw;
  2434. }
  2435. return defaultContent;
  2436. }
  2437. // When the data source is null and a specific data type is requested (i.e.
  2438. // not the original data), we can use default column data
  2439. if ( (cellData === rowData || cellData === null) && defaultContent !== null && type !== undefined ) {
  2440. cellData = defaultContent;
  2441. }
  2442. else if ( typeof cellData === 'function' ) {
  2443. // If the data source is a function, then we run it and use the return,
  2444. // executing in the scope of the data object (for instances)
  2445. return cellData.call( rowData );
  2446. }
  2447. if ( cellData === null && type === 'display' ) {
  2448. return '';
  2449. }
  2450. if ( type === 'filter' ) {
  2451. var fomatters = DataTable.ext.type.search;
  2452. if ( fomatters[ col.sType ] ) {
  2453. cellData = fomatters[ col.sType ]( cellData );
  2454. }
  2455. }
  2456. return cellData;
  2457. }
  2458. /**
  2459. * Set the value for a specific cell, into the internal data cache
  2460. * @param {object} settings dataTables settings object
  2461. * @param {int} rowIdx aoData row id
  2462. * @param {int} colIdx Column index
  2463. * @param {*} val Value to set
  2464. * @memberof DataTable#oApi
  2465. */
  2466. function _fnSetCellData( settings, rowIdx, colIdx, val )
  2467. {
  2468. var col = settings.aoColumns[colIdx];
  2469. var rowData = settings.aoData[rowIdx]._aData;
  2470. col.fnSetData( rowData, val, {
  2471. settings: settings,
  2472. row: rowIdx,
  2473. col: colIdx
  2474. } );
  2475. }
  2476. // Private variable that is used to match action syntax in the data property object
  2477. var __reArray = /\[.*?\]$/;
  2478. var __reFn = /\(\)$/;
  2479. /**
  2480. * Split string on periods, taking into account escaped periods
  2481. * @param {string} str String to split
  2482. * @return {array} Split string
  2483. */
  2484. function _fnSplitObjNotation( str )
  2485. {
  2486. return $.map( str.match(/(\\.|[^\.])+/g) || [''], function ( s ) {
  2487. return s.replace(/\\\./g, '.');
  2488. } );
  2489. }
  2490. /**
  2491. * Return a function that can be used to get data from a source object, taking
  2492. * into account the ability to use nested objects as a source
  2493. * @param {string|int|function} mSource The data source for the object
  2494. * @returns {function} Data get function
  2495. * @memberof DataTable#oApi
  2496. */
  2497. var _fnGetObjectDataFn = DataTable.util.get;
  2498. /**
  2499. * Return a function that can be used to set data from a source object, taking
  2500. * into account the ability to use nested objects as a source
  2501. * @param {string|int|function} mSource The data source for the object
  2502. * @returns {function} Data set function
  2503. * @memberof DataTable#oApi
  2504. */
  2505. var _fnSetObjectDataFn = DataTable.util.set;
  2506. /**
  2507. * Return an array with the full table data
  2508. * @param {object} oSettings dataTables settings object
  2509. * @returns array {array} aData Master data array
  2510. * @memberof DataTable#oApi
  2511. */
  2512. function _fnGetDataMaster ( settings )
  2513. {
  2514. return _pluck( settings.aoData, '_aData' );
  2515. }
  2516. /**
  2517. * Nuke the table
  2518. * @param {object} oSettings dataTables settings object
  2519. * @memberof DataTable#oApi
  2520. */
  2521. function _fnClearTable( settings )
  2522. {
  2523. settings.aoData.length = 0;
  2524. settings.aiDisplayMaster.length = 0;
  2525. settings.aiDisplay.length = 0;
  2526. settings.aIds = {};
  2527. }
  2528. /**
  2529. * Take an array of integers (index array) and remove a target integer (value - not
  2530. * the key!)
  2531. * @param {array} a Index array to target
  2532. * @param {int} iTarget value to find
  2533. * @memberof DataTable#oApi
  2534. */
  2535. function _fnDeleteIndex( a, iTarget, splice )
  2536. {
  2537. var iTargetIndex = -1;
  2538. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  2539. {
  2540. if ( a[i] == iTarget )
  2541. {
  2542. iTargetIndex = i;
  2543. }
  2544. else if ( a[i] > iTarget )
  2545. {
  2546. a[i]--;
  2547. }
  2548. }
  2549. if ( iTargetIndex != -1 && splice === undefined )
  2550. {
  2551. a.splice( iTargetIndex, 1 );
  2552. }
  2553. }
  2554. /**
  2555. * Mark cached data as invalid such that a re-read of the data will occur when
  2556. * the cached data is next requested. Also update from the data source object.
  2557. *
  2558. * @param {object} settings DataTables settings object
  2559. * @param {int} rowIdx Row index to invalidate
  2560. * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
  2561. * or 'data'
  2562. * @param {int} [colIdx] Column index to invalidate. If undefined the whole
  2563. * row will be invalidated
  2564. * @memberof DataTable#oApi
  2565. *
  2566. * @todo For the modularisation of v1.11 this will need to become a callback, so
  2567. * the sort and filter methods can subscribe to it. That will required
  2568. * initialisation options for sorting, which is why it is not already baked in
  2569. */
  2570. function _fnInvalidate( settings, rowIdx, src, colIdx )
  2571. {
  2572. var row = settings.aoData[ rowIdx ];
  2573. var i, ien;
  2574. var cellWrite = function ( cell, col ) {
  2575. // This is very frustrating, but in IE if you just write directly
  2576. // to innerHTML, and elements that are overwritten are GC'ed,
  2577. // even if there is a reference to them elsewhere
  2578. while ( cell.childNodes.length ) {
  2579. cell.removeChild( cell.firstChild );
  2580. }
  2581. cell.innerHTML = _fnGetCellData( settings, rowIdx, col, 'display' );
  2582. };
  2583. // Are we reading last data from DOM or the data object?
  2584. if ( src === 'dom' || ((! src || src === 'auto') && row.src === 'dom') ) {
  2585. // Read the data from the DOM
  2586. row._aData = _fnGetRowElements(
  2587. settings, row, colIdx, colIdx === undefined ? undefined : row._aData
  2588. )
  2589. .data;
  2590. }
  2591. else {
  2592. // Reading from data object, update the DOM
  2593. var cells = row.anCells;
  2594. if ( cells ) {
  2595. if ( colIdx !== undefined ) {
  2596. cellWrite( cells[colIdx], colIdx );
  2597. }
  2598. else {
  2599. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2600. cellWrite( cells[i], i );
  2601. }
  2602. }
  2603. }
  2604. }
  2605. // For both row and cell invalidation, the cached data for sorting and
  2606. // filtering is nulled out
  2607. row._aSortData = null;
  2608. row._aFilterData = null;
  2609. // Invalidate the type for a specific column (if given) or all columns since
  2610. // the data might have changed
  2611. var cols = settings.aoColumns;
  2612. if ( colIdx !== undefined ) {
  2613. cols[ colIdx ].sType = null;
  2614. }
  2615. else {
  2616. for ( i=0, ien=cols.length ; i<ien ; i++ ) {
  2617. cols[i].sType = null;
  2618. }
  2619. // Update DataTables special `DT_*` attributes for the row
  2620. _fnRowAttributes( settings, row );
  2621. }
  2622. }
  2623. /**
  2624. * Build a data source object from an HTML row, reading the contents of the
  2625. * cells that are in the row.
  2626. *
  2627. * @param {object} settings DataTables settings object
  2628. * @param {node|object} TR element from which to read data or existing row
  2629. * object from which to re-read the data from the cells
  2630. * @param {int} [colIdx] Optional column index
  2631. * @param {array|object} [d] Data source object. If `colIdx` is given then this
  2632. * parameter should also be given and will be used to write the data into.
  2633. * Only the column in question will be written
  2634. * @returns {object} Object with two parameters: `data` the data read, in
  2635. * document order, and `cells` and array of nodes (they can be useful to the
  2636. * caller, so rather than needing a second traversal to get them, just return
  2637. * them from here).
  2638. * @memberof DataTable#oApi
  2639. */
  2640. function _fnGetRowElements( settings, row, colIdx, d )
  2641. {
  2642. var
  2643. tds = [],
  2644. td = row.firstChild,
  2645. name, col, o, i=0, contents,
  2646. columns = settings.aoColumns,
  2647. objectRead = settings._rowReadObject;
  2648. // Allow the data object to be passed in, or construct
  2649. d = d !== undefined ?
  2650. d :
  2651. objectRead ?
  2652. {} :
  2653. [];
  2654. var attr = function ( str, td ) {
  2655. if ( typeof str === 'string' ) {
  2656. var idx = str.indexOf('@');
  2657. if ( idx !== -1 ) {
  2658. var attr = str.substring( idx+1 );
  2659. var setter = _fnSetObjectDataFn( str );
  2660. setter( d, td.getAttribute( attr ) );
  2661. }
  2662. }
  2663. };
  2664. // Read data from a cell and store into the data object
  2665. var cellProcess = function ( cell ) {
  2666. if ( colIdx === undefined || colIdx === i ) {
  2667. col = columns[i];
  2668. contents = (cell.innerHTML).trim();
  2669. if ( col && col._bAttrSrc ) {
  2670. var setter = _fnSetObjectDataFn( col.mData._ );
  2671. setter( d, contents );
  2672. attr( col.mData.sort, cell );
  2673. attr( col.mData.type, cell );
  2674. attr( col.mData.filter, cell );
  2675. }
  2676. else {
  2677. // Depending on the `data` option for the columns the data can
  2678. // be read to either an object or an array.
  2679. if ( objectRead ) {
  2680. if ( ! col._setter ) {
  2681. // Cache the setter function
  2682. col._setter = _fnSetObjectDataFn( col.mData );
  2683. }
  2684. col._setter( d, contents );
  2685. }
  2686. else {
  2687. d[i] = contents;
  2688. }
  2689. }
  2690. }
  2691. i++;
  2692. };
  2693. if ( td ) {
  2694. // `tr` element was passed in
  2695. while ( td ) {
  2696. name = td.nodeName.toUpperCase();
  2697. if ( name == "TD" || name == "TH" ) {
  2698. cellProcess( td );
  2699. tds.push( td );
  2700. }
  2701. td = td.nextSibling;
  2702. }
  2703. }
  2704. else {
  2705. // Existing row object passed in
  2706. tds = row.anCells;
  2707. for ( var j=0, jen=tds.length ; j<jen ; j++ ) {
  2708. cellProcess( tds[j] );
  2709. }
  2710. }
  2711. // Read the ID from the DOM if present
  2712. var rowNode = row.firstChild ? row : row.nTr;
  2713. if ( rowNode ) {
  2714. var id = rowNode.getAttribute( 'id' );
  2715. if ( id ) {
  2716. _fnSetObjectDataFn( settings.rowId )( d, id );
  2717. }
  2718. }
  2719. return {
  2720. data: d,
  2721. cells: tds
  2722. };
  2723. }
  2724. /**
  2725. * Create a new TR element (and it's TD children) for a row
  2726. * @param {object} oSettings dataTables settings object
  2727. * @param {int} iRow Row to consider
  2728. * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
  2729. * DataTables will create a row automatically
  2730. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2731. * if nTr is.
  2732. * @memberof DataTable#oApi
  2733. */
  2734. function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
  2735. {
  2736. var
  2737. row = oSettings.aoData[iRow],
  2738. rowData = row._aData,
  2739. cells = [],
  2740. nTr, nTd, oCol,
  2741. i, iLen, create;
  2742. if ( row.nTr === null )
  2743. {
  2744. nTr = nTrIn || document.createElement('tr');
  2745. row.nTr = nTr;
  2746. row.anCells = cells;
  2747. /* Use a private property on the node to allow reserve mapping from the node
  2748. * to the aoData array for fast look up
  2749. */
  2750. nTr._DT_RowIndex = iRow;
  2751. /* Special parameters can be given by the data source to be used on the row */
  2752. _fnRowAttributes( oSettings, row );
  2753. /* Process each column */
  2754. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  2755. {
  2756. oCol = oSettings.aoColumns[i];
  2757. create = nTrIn ? false : true;
  2758. nTd = create ? document.createElement( oCol.sCellType ) : anTds[i];
  2759. if (! nTd) {
  2760. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  2761. }
  2762. nTd._DT_CellIndex = {
  2763. row: iRow,
  2764. column: i
  2765. };
  2766. cells.push( nTd );
  2767. // Need to create the HTML if new, or if a rendering function is defined
  2768. if ( create || ((oCol.mRender || oCol.mData !== i) &&
  2769. (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i+'.display')
  2770. )) {
  2771. nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' );
  2772. }
  2773. /* Add user defined class */
  2774. if ( oCol.sClass )
  2775. {
  2776. nTd.className += ' '+oCol.sClass;
  2777. }
  2778. // Visibility - add or remove as required
  2779. if ( oCol.bVisible && ! nTrIn )
  2780. {
  2781. nTr.appendChild( nTd );
  2782. }
  2783. else if ( ! oCol.bVisible && nTrIn )
  2784. {
  2785. nTd.parentNode.removeChild( nTd );
  2786. }
  2787. if ( oCol.fnCreatedCell )
  2788. {
  2789. oCol.fnCreatedCell.call( oSettings.oInstance,
  2790. nTd, _fnGetCellData( oSettings, iRow, i ), rowData, iRow, i
  2791. );
  2792. }
  2793. }
  2794. _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow, cells] );
  2795. }
  2796. }
  2797. /**
  2798. * Add attributes to a row based on the special `DT_*` parameters in a data
  2799. * source object.
  2800. * @param {object} settings DataTables settings object
  2801. * @param {object} DataTables row object for the row to be modified
  2802. * @memberof DataTable#oApi
  2803. */
  2804. function _fnRowAttributes( settings, row )
  2805. {
  2806. var tr = row.nTr;
  2807. var data = row._aData;
  2808. if ( tr ) {
  2809. var id = settings.rowIdFn( data );
  2810. if ( id ) {
  2811. tr.id = id;
  2812. }
  2813. if ( data.DT_RowClass ) {
  2814. // Remove any classes added by DT_RowClass before
  2815. var a = data.DT_RowClass.split(' ');
  2816. row.__rowc = row.__rowc ?
  2817. _unique( row.__rowc.concat( a ) ) :
  2818. a;
  2819. $(tr)
  2820. .removeClass( row.__rowc.join(' ') )
  2821. .addClass( data.DT_RowClass );
  2822. }
  2823. if ( data.DT_RowAttr ) {
  2824. $(tr).attr( data.DT_RowAttr );
  2825. }
  2826. if ( data.DT_RowData ) {
  2827. $(tr).data( data.DT_RowData );
  2828. }
  2829. }
  2830. }
  2831. /**
  2832. * Create the HTML header for the table
  2833. * @param {object} oSettings dataTables settings object
  2834. * @memberof DataTable#oApi
  2835. */
  2836. function _fnBuildHead( oSettings )
  2837. {
  2838. var i, ien, cell, row, column;
  2839. var thead = oSettings.nTHead;
  2840. var tfoot = oSettings.nTFoot;
  2841. var createHeader = $('th, td', thead).length === 0;
  2842. var classes = oSettings.oClasses;
  2843. var columns = oSettings.aoColumns;
  2844. if ( createHeader ) {
  2845. row = $('<tr/>').appendTo( thead );
  2846. }
  2847. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  2848. column = columns[i];
  2849. cell = $( column.nTh ).addClass( column.sClass );
  2850. if ( createHeader ) {
  2851. cell.appendTo( row );
  2852. }
  2853. // 1.11 move into sorting
  2854. if ( oSettings.oFeatures.bSort ) {
  2855. cell.addClass( column.sSortingClass );
  2856. if ( column.bSortable !== false ) {
  2857. cell
  2858. .attr( 'tabindex', oSettings.iTabIndex )
  2859. .attr( 'aria-controls', oSettings.sTableId );
  2860. _fnSortAttachListener( oSettings, column.nTh, i );
  2861. }
  2862. }
  2863. if ( column.sTitle != cell[0].innerHTML ) {
  2864. cell.html( column.sTitle );
  2865. }
  2866. _fnRenderer( oSettings, 'header' )(
  2867. oSettings, cell, column, classes
  2868. );
  2869. }
  2870. if ( createHeader ) {
  2871. _fnDetectHeader( oSettings.aoHeader, thead );
  2872. }
  2873. /* Deal with the footer - add classes if required */
  2874. $(thead).children('tr').children('th, td').addClass( classes.sHeaderTH );
  2875. $(tfoot).children('tr').children('th, td').addClass( classes.sFooterTH );
  2876. // Cache the footer cells. Note that we only take the cells from the first
  2877. // row in the footer. If there is more than one row the user wants to
  2878. // interact with, they need to use the table().foot() method. Note also this
  2879. // allows cells to be used for multiple columns using colspan
  2880. if ( tfoot !== null ) {
  2881. var cells = oSettings.aoFooter[0];
  2882. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2883. column = columns[i];
  2884. if (column) {
  2885. column.nTf = cells[i].cell;
  2886. if ( column.sClass ) {
  2887. $(column.nTf).addClass( column.sClass );
  2888. }
  2889. }
  2890. else {
  2891. _fnLog( oSettings, 0, 'Incorrect column count', 18 );
  2892. }
  2893. }
  2894. }
  2895. }
  2896. /**
  2897. * Draw the header (or footer) element based on the column visibility states. The
  2898. * methodology here is to use the layout array from _fnDetectHeader, modified for
  2899. * the instantaneous column visibility, to construct the new layout. The grid is
  2900. * traversed over cell at a time in a rows x columns grid fashion, although each
  2901. * cell insert can cover multiple elements in the grid - which is tracks using the
  2902. * aApplied array. Cell inserts in the grid will only occur where there isn't
  2903. * already a cell in that position.
  2904. * @param {object} oSettings dataTables settings object
  2905. * @param array {objects} aoSource Layout array from _fnDetectHeader
  2906. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  2907. * @memberof DataTable#oApi
  2908. */
  2909. function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
  2910. {
  2911. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  2912. var aoLocal = [];
  2913. var aApplied = [];
  2914. var iColumns = oSettings.aoColumns.length;
  2915. var iRowspan, iColspan;
  2916. if ( ! aoSource )
  2917. {
  2918. return;
  2919. }
  2920. if ( bIncludeHidden === undefined )
  2921. {
  2922. bIncludeHidden = false;
  2923. }
  2924. /* Make a copy of the master layout array, but without the visible columns in it */
  2925. for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
  2926. {
  2927. aoLocal[i] = aoSource[i].slice();
  2928. aoLocal[i].nTr = aoSource[i].nTr;
  2929. /* Remove any columns which are currently hidden */
  2930. for ( j=iColumns-1 ; j>=0 ; j-- )
  2931. {
  2932. if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
  2933. {
  2934. aoLocal[i].splice( j, 1 );
  2935. }
  2936. }
  2937. /* Prep the applied array - it needs an element for each row */
  2938. aApplied.push( [] );
  2939. }
  2940. for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
  2941. {
  2942. nLocalTr = aoLocal[i].nTr;
  2943. /* All cells are going to be replaced, so empty out the row */
  2944. if ( nLocalTr )
  2945. {
  2946. while( (n = nLocalTr.firstChild) )
  2947. {
  2948. nLocalTr.removeChild( n );
  2949. }
  2950. }
  2951. for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
  2952. {
  2953. iRowspan = 1;
  2954. iColspan = 1;
  2955. /* Check to see if there is already a cell (row/colspan) covering our target
  2956. * insert point. If there is, then there is nothing to do.
  2957. */
  2958. if ( aApplied[i][j] === undefined )
  2959. {
  2960. nLocalTr.appendChild( aoLocal[i][j].cell );
  2961. aApplied[i][j] = 1;
  2962. /* Expand the cell to cover as many rows as needed */
  2963. while ( aoLocal[i+iRowspan] !== undefined &&
  2964. aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
  2965. {
  2966. aApplied[i+iRowspan][j] = 1;
  2967. iRowspan++;
  2968. }
  2969. /* Expand the cell to cover as many columns as needed */
  2970. while ( aoLocal[i][j+iColspan] !== undefined &&
  2971. aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
  2972. {
  2973. /* Must update the applied array over the rows for the columns */
  2974. for ( k=0 ; k<iRowspan ; k++ )
  2975. {
  2976. aApplied[i+k][j+iColspan] = 1;
  2977. }
  2978. iColspan++;
  2979. }
  2980. /* Do the actual expansion in the DOM */
  2981. $(aoLocal[i][j].cell)
  2982. .attr('rowspan', iRowspan)
  2983. .attr('colspan', iColspan);
  2984. }
  2985. }
  2986. }
  2987. }
  2988. /**
  2989. * Insert the required TR nodes into the table for display
  2990. * @param {object} oSettings dataTables settings object
  2991. * @param ajaxComplete true after ajax call to complete rendering
  2992. * @memberof DataTable#oApi
  2993. */
  2994. function _fnDraw( oSettings, ajaxComplete )
  2995. {
  2996. // Allow for state saving and a custom start position
  2997. _fnStart( oSettings );
  2998. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  2999. var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
  3000. if ( $.inArray( false, aPreDraw ) !== -1 )
  3001. {
  3002. _fnProcessingDisplay( oSettings, false );
  3003. return;
  3004. }
  3005. var anRows = [];
  3006. var iRowCount = 0;
  3007. var asStripeClasses = oSettings.asStripeClasses;
  3008. var iStripes = asStripeClasses.length;
  3009. var oLang = oSettings.oLanguage;
  3010. var bServerSide = _fnDataSource( oSettings ) == 'ssp';
  3011. var aiDisplay = oSettings.aiDisplay;
  3012. var iDisplayStart = oSettings._iDisplayStart;
  3013. var iDisplayEnd = oSettings.fnDisplayEnd();
  3014. oSettings.bDrawing = true;
  3015. /* Server-side processing draw intercept */
  3016. if ( oSettings.bDeferLoading )
  3017. {
  3018. oSettings.bDeferLoading = false;
  3019. oSettings.iDraw++;
  3020. _fnProcessingDisplay( oSettings, false );
  3021. }
  3022. else if ( !bServerSide )
  3023. {
  3024. oSettings.iDraw++;
  3025. }
  3026. else if ( !oSettings.bDestroying && !ajaxComplete)
  3027. {
  3028. _fnAjaxUpdate( oSettings );
  3029. return;
  3030. }
  3031. if ( aiDisplay.length !== 0 )
  3032. {
  3033. var iStart = bServerSide ? 0 : iDisplayStart;
  3034. var iEnd = bServerSide ? oSettings.aoData.length : iDisplayEnd;
  3035. for ( var j=iStart ; j<iEnd ; j++ )
  3036. {
  3037. var iDataIndex = aiDisplay[j];
  3038. var aoData = oSettings.aoData[ iDataIndex ];
  3039. if ( aoData.nTr === null )
  3040. {
  3041. _fnCreateTr( oSettings, iDataIndex );
  3042. }
  3043. var nRow = aoData.nTr;
  3044. /* Remove the old striping classes and then add the new one */
  3045. if ( iStripes !== 0 )
  3046. {
  3047. var sStripe = asStripeClasses[ iRowCount % iStripes ];
  3048. if ( aoData._sRowStripe != sStripe )
  3049. {
  3050. $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
  3051. aoData._sRowStripe = sStripe;
  3052. }
  3053. }
  3054. // Row callback functions - might want to manipulate the row
  3055. // iRowCount and j are not currently documented. Are they at all
  3056. // useful?
  3057. _fnCallbackFire( oSettings, 'aoRowCallback', null,
  3058. [nRow, aoData._aData, iRowCount, j, iDataIndex] );
  3059. anRows.push( nRow );
  3060. iRowCount++;
  3061. }
  3062. }
  3063. else
  3064. {
  3065. /* Table is empty - create a row with an empty message in it */
  3066. var sZero = oLang.sZeroRecords;
  3067. if ( oSettings.iDraw == 1 && _fnDataSource( oSettings ) == 'ajax' )
  3068. {
  3069. sZero = oLang.sLoadingRecords;
  3070. }
  3071. else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
  3072. {
  3073. sZero = oLang.sEmptyTable;
  3074. }
  3075. anRows[ 0 ] = $( '<tr/>', { 'class': iStripes ? asStripeClasses[0] : '' } )
  3076. .append( $('<td />', {
  3077. 'valign': 'top',
  3078. 'colSpan': _fnVisbleColumns( oSettings ),
  3079. 'class': oSettings.oClasses.sRowEmpty
  3080. } ).html( sZero ) )[0];
  3081. }
  3082. /* Header and footer callbacks */
  3083. _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
  3084. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3085. _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
  3086. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3087. var body = $(oSettings.nTBody);
  3088. body.children().detach();
  3089. body.append( $(anRows) );
  3090. /* Call all required callback functions for the end of a draw */
  3091. _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
  3092. /* Draw is complete, sorting and filtering must be as well */
  3093. oSettings.bSorted = false;
  3094. oSettings.bFiltered = false;
  3095. oSettings.bDrawing = false;
  3096. }
  3097. /**
  3098. * Redraw the table - taking account of the various features which are enabled
  3099. * @param {object} oSettings dataTables settings object
  3100. * @param {boolean} [holdPosition] Keep the current paging position. By default
  3101. * the paging is reset to the first page
  3102. * @memberof DataTable#oApi
  3103. */
  3104. function _fnReDraw( settings, holdPosition )
  3105. {
  3106. var
  3107. features = settings.oFeatures,
  3108. sort = features.bSort,
  3109. filter = features.bFilter;
  3110. if ( sort ) {
  3111. _fnSort( settings );
  3112. }
  3113. if ( filter ) {
  3114. _fnFilterComplete( settings, settings.oPreviousSearch );
  3115. }
  3116. else {
  3117. // No filtering, so we want to just use the display master
  3118. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3119. }
  3120. if ( holdPosition !== true ) {
  3121. settings._iDisplayStart = 0;
  3122. }
  3123. // Let any modules know about the draw hold position state (used by
  3124. // scrolling internally)
  3125. settings._drawHold = holdPosition;
  3126. _fnDraw( settings );
  3127. settings._drawHold = false;
  3128. }
  3129. /**
  3130. * Add the options to the page HTML for the table
  3131. * @param {object} oSettings dataTables settings object
  3132. * @memberof DataTable#oApi
  3133. */
  3134. function _fnAddOptionsHtml ( oSettings )
  3135. {
  3136. var classes = oSettings.oClasses;
  3137. var table = $(oSettings.nTable);
  3138. var holding = $('<div/>').insertBefore( table ); // Holding element for speed
  3139. var features = oSettings.oFeatures;
  3140. // All DataTables are wrapped in a div
  3141. var insert = $('<div/>', {
  3142. id: oSettings.sTableId+'_wrapper',
  3143. 'class': classes.sWrapper + (oSettings.nTFoot ? '' : ' '+classes.sNoFooter)
  3144. } );
  3145. oSettings.nHolding = holding[0];
  3146. oSettings.nTableWrapper = insert[0];
  3147. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  3148. /* Loop over the user set positioning and place the elements as needed */
  3149. var aDom = oSettings.sDom.split('');
  3150. var featureNode, cOption, nNewNode, cNext, sAttr, j;
  3151. for ( var i=0 ; i<aDom.length ; i++ )
  3152. {
  3153. featureNode = null;
  3154. cOption = aDom[i];
  3155. if ( cOption == '<' )
  3156. {
  3157. /* New container div */
  3158. nNewNode = $('<div/>')[0];
  3159. /* Check to see if we should append an id and/or a class name to the container */
  3160. cNext = aDom[i+1];
  3161. if ( cNext == "'" || cNext == '"' )
  3162. {
  3163. sAttr = "";
  3164. j = 2;
  3165. while ( aDom[i+j] != cNext )
  3166. {
  3167. sAttr += aDom[i+j];
  3168. j++;
  3169. }
  3170. /* Replace jQuery UI constants @todo depreciated */
  3171. if ( sAttr == "H" )
  3172. {
  3173. sAttr = classes.sJUIHeader;
  3174. }
  3175. else if ( sAttr == "F" )
  3176. {
  3177. sAttr = classes.sJUIFooter;
  3178. }
  3179. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  3180. * breaks the string into parts and applies them as needed
  3181. */
  3182. if ( sAttr.indexOf('.') != -1 )
  3183. {
  3184. var aSplit = sAttr.split('.');
  3185. nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
  3186. nNewNode.className = aSplit[1];
  3187. }
  3188. else if ( sAttr.charAt(0) == "#" )
  3189. {
  3190. nNewNode.id = sAttr.substr(1, sAttr.length-1);
  3191. }
  3192. else
  3193. {
  3194. nNewNode.className = sAttr;
  3195. }
  3196. i += j; /* Move along the position array */
  3197. }
  3198. insert.append( nNewNode );
  3199. insert = $(nNewNode);
  3200. }
  3201. else if ( cOption == '>' )
  3202. {
  3203. /* End container div */
  3204. insert = insert.parent();
  3205. }
  3206. // @todo Move options into their own plugins?
  3207. else if ( cOption == 'l' && features.bPaginate && features.bLengthChange )
  3208. {
  3209. /* Length */
  3210. featureNode = _fnFeatureHtmlLength( oSettings );
  3211. }
  3212. else if ( cOption == 'f' && features.bFilter )
  3213. {
  3214. /* Filter */
  3215. featureNode = _fnFeatureHtmlFilter( oSettings );
  3216. }
  3217. else if ( cOption == 'r' && features.bProcessing )
  3218. {
  3219. /* pRocessing */
  3220. featureNode = _fnFeatureHtmlProcessing( oSettings );
  3221. }
  3222. else if ( cOption == 't' )
  3223. {
  3224. /* Table */
  3225. featureNode = _fnFeatureHtmlTable( oSettings );
  3226. }
  3227. else if ( cOption == 'i' && features.bInfo )
  3228. {
  3229. /* Info */
  3230. featureNode = _fnFeatureHtmlInfo( oSettings );
  3231. }
  3232. else if ( cOption == 'p' && features.bPaginate )
  3233. {
  3234. /* Pagination */
  3235. featureNode = _fnFeatureHtmlPaginate( oSettings );
  3236. }
  3237. else if ( DataTable.ext.feature.length !== 0 )
  3238. {
  3239. /* Plug-in features */
  3240. var aoFeatures = DataTable.ext.feature;
  3241. for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
  3242. {
  3243. if ( cOption == aoFeatures[k].cFeature )
  3244. {
  3245. featureNode = aoFeatures[k].fnInit( oSettings );
  3246. break;
  3247. }
  3248. }
  3249. }
  3250. /* Add to the 2D features array */
  3251. if ( featureNode )
  3252. {
  3253. var aanFeatures = oSettings.aanFeatures;
  3254. if ( ! aanFeatures[cOption] )
  3255. {
  3256. aanFeatures[cOption] = [];
  3257. }
  3258. aanFeatures[cOption].push( featureNode );
  3259. insert.append( featureNode );
  3260. }
  3261. }
  3262. /* Built our DOM structure - replace the holding div with what we want */
  3263. holding.replaceWith( insert );
  3264. oSettings.nHolding = null;
  3265. }
  3266. /**
  3267. * Use the DOM source to create up an array of header cells. The idea here is to
  3268. * create a layout grid (array) of rows x columns, which contains a reference
  3269. * to the cell that that point in the grid (regardless of col/rowspan), such that
  3270. * any column / row could be removed and the new grid constructed
  3271. * @param array {object} aLayout Array to store the calculated layout in
  3272. * @param {node} nThead The header/footer element for the table
  3273. * @memberof DataTable#oApi
  3274. */
  3275. function _fnDetectHeader ( aLayout, nThead )
  3276. {
  3277. var nTrs = $(nThead).children('tr');
  3278. var nTr, nCell;
  3279. var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
  3280. var bUnique;
  3281. var fnShiftCol = function ( a, i, j ) {
  3282. var k = a[i];
  3283. while ( k[j] ) {
  3284. j++;
  3285. }
  3286. return j;
  3287. };
  3288. aLayout.splice( 0, aLayout.length );
  3289. /* We know how many rows there are in the layout - so prep it */
  3290. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3291. {
  3292. aLayout.push( [] );
  3293. }
  3294. /* Calculate a layout array */
  3295. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3296. {
  3297. nTr = nTrs[i];
  3298. iColumn = 0;
  3299. /* For every cell in the row... */
  3300. nCell = nTr.firstChild;
  3301. while ( nCell ) {
  3302. if ( nCell.nodeName.toUpperCase() == "TD" ||
  3303. nCell.nodeName.toUpperCase() == "TH" )
  3304. {
  3305. /* Get the col and rowspan attributes from the DOM and sanitise them */
  3306. iColspan = nCell.getAttribute('colspan') * 1;
  3307. iRowspan = nCell.getAttribute('rowspan') * 1;
  3308. iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
  3309. iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
  3310. /* There might be colspan cells already in this row, so shift our target
  3311. * accordingly
  3312. */
  3313. iColShifted = fnShiftCol( aLayout, i, iColumn );
  3314. /* Cache calculation for unique columns */
  3315. bUnique = iColspan === 1 ? true : false;
  3316. /* If there is col / rowspan, copy the information into the layout grid */
  3317. for ( l=0 ; l<iColspan ; l++ )
  3318. {
  3319. for ( k=0 ; k<iRowspan ; k++ )
  3320. {
  3321. aLayout[i+k][iColShifted+l] = {
  3322. "cell": nCell,
  3323. "unique": bUnique
  3324. };
  3325. aLayout[i+k].nTr = nTr;
  3326. }
  3327. }
  3328. }
  3329. nCell = nCell.nextSibling;
  3330. }
  3331. }
  3332. }
  3333. /**
  3334. * Get an array of unique th elements, one for each column
  3335. * @param {object} oSettings dataTables settings object
  3336. * @param {node} nHeader automatically detect the layout from this node - optional
  3337. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  3338. * @returns array {node} aReturn list of unique th's
  3339. * @memberof DataTable#oApi
  3340. */
  3341. function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
  3342. {
  3343. var aReturn = [];
  3344. if ( !aLayout )
  3345. {
  3346. aLayout = oSettings.aoHeader;
  3347. if ( nHeader )
  3348. {
  3349. aLayout = [];
  3350. _fnDetectHeader( aLayout, nHeader );
  3351. }
  3352. }
  3353. for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
  3354. {
  3355. for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
  3356. {
  3357. if ( aLayout[i][j].unique &&
  3358. (!aReturn[j] || !oSettings.bSortCellsTop) )
  3359. {
  3360. aReturn[j] = aLayout[i][j].cell;
  3361. }
  3362. }
  3363. }
  3364. return aReturn;
  3365. }
  3366. /**
  3367. * Set the start position for draw
  3368. * @param {object} oSettings dataTables settings object
  3369. */
  3370. function _fnStart( oSettings )
  3371. {
  3372. var bServerSide = _fnDataSource( oSettings ) == 'ssp';
  3373. var iInitDisplayStart = oSettings.iInitDisplayStart;
  3374. // Check and see if we have an initial draw position from state saving
  3375. if ( iInitDisplayStart !== undefined && iInitDisplayStart !== -1 )
  3376. {
  3377. oSettings._iDisplayStart = bServerSide ?
  3378. iInitDisplayStart :
  3379. iInitDisplayStart >= oSettings.fnRecordsDisplay() ?
  3380. 0 :
  3381. iInitDisplayStart;
  3382. oSettings.iInitDisplayStart = -1;
  3383. }
  3384. }
  3385. /**
  3386. * Create an Ajax call based on the table's settings, taking into account that
  3387. * parameters can have multiple forms, and backwards compatibility.
  3388. *
  3389. * @param {object} oSettings dataTables settings object
  3390. * @param {array} data Data to send to the server, required by
  3391. * DataTables - may be augmented by developer callbacks
  3392. * @param {function} fn Callback function to run when data is obtained
  3393. */
  3394. function _fnBuildAjax( oSettings, data, fn )
  3395. {
  3396. // Compatibility with 1.9-, allow fnServerData and event to manipulate
  3397. _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [data] );
  3398. // Convert to object based for 1.10+ if using the old array scheme which can
  3399. // come from server-side processing or serverParams
  3400. if ( data && Array.isArray(data) ) {
  3401. var tmp = {};
  3402. var rbracket = /(.*?)\[\]$/;
  3403. $.each( data, function (key, val) {
  3404. var match = val.name.match(rbracket);
  3405. if ( match ) {
  3406. // Support for arrays
  3407. var name = match[0];
  3408. if ( ! tmp[ name ] ) {
  3409. tmp[ name ] = [];
  3410. }
  3411. tmp[ name ].push( val.value );
  3412. }
  3413. else {
  3414. tmp[val.name] = val.value;
  3415. }
  3416. } );
  3417. data = tmp;
  3418. }
  3419. var ajaxData;
  3420. var ajax = oSettings.ajax;
  3421. var instance = oSettings.oInstance;
  3422. var callback = function ( json ) {
  3423. var status = oSettings.jqXHR
  3424. ? oSettings.jqXHR.status
  3425. : null;
  3426. if ( json === null || (typeof status === 'number' && status == 204 ) ) {
  3427. json = {};
  3428. _fnAjaxDataSrc( oSettings, json, [] );
  3429. }
  3430. var error = json.error || json.sError;
  3431. if ( error ) {
  3432. _fnLog( oSettings, 0, error );
  3433. }
  3434. oSettings.json = json;
  3435. _fnCallbackFire( oSettings, null, 'xhr', [oSettings, json, oSettings.jqXHR] );
  3436. fn( json );
  3437. };
  3438. if ( $.isPlainObject( ajax ) && ajax.data )
  3439. {
  3440. ajaxData = ajax.data;
  3441. var newData = typeof ajaxData === 'function' ?
  3442. ajaxData( data, oSettings ) : // fn can manipulate data or return
  3443. ajaxData; // an object object or array to merge
  3444. // If the function returned something, use that alone
  3445. data = typeof ajaxData === 'function' && newData ?
  3446. newData :
  3447. $.extend( true, data, newData );
  3448. // Remove the data property as we've resolved it already and don't want
  3449. // jQuery to do it again (it is restored at the end of the function)
  3450. delete ajax.data;
  3451. }
  3452. var baseAjax = {
  3453. "data": data,
  3454. "success": callback,
  3455. "dataType": "json",
  3456. "cache": false,
  3457. "type": oSettings.sServerMethod,
  3458. "error": function (xhr, error, thrown) {
  3459. var ret = _fnCallbackFire( oSettings, null, 'xhr', [oSettings, null, oSettings.jqXHR] );
  3460. if ( $.inArray( true, ret ) === -1 ) {
  3461. if ( error == "parsererror" ) {
  3462. _fnLog( oSettings, 0, 'Invalid JSON response', 1 );
  3463. }
  3464. else if ( xhr.readyState === 4 ) {
  3465. _fnLog( oSettings, 0, 'Ajax error', 7 );
  3466. }
  3467. }
  3468. _fnProcessingDisplay( oSettings, false );
  3469. }
  3470. };
  3471. // Store the data submitted for the API
  3472. oSettings.oAjaxData = data;
  3473. // Allow plug-ins and external processes to modify the data
  3474. _fnCallbackFire( oSettings, null, 'preXhr', [oSettings, data] );
  3475. if ( oSettings.fnServerData )
  3476. {
  3477. // DataTables 1.9- compatibility
  3478. oSettings.fnServerData.call( instance,
  3479. oSettings.sAjaxSource,
  3480. $.map( data, function (val, key) { // Need to convert back to 1.9 trad format
  3481. return { name: key, value: val };
  3482. } ),
  3483. callback,
  3484. oSettings
  3485. );
  3486. }
  3487. else if ( oSettings.sAjaxSource || typeof ajax === 'string' )
  3488. {
  3489. // DataTables 1.9- compatibility
  3490. oSettings.jqXHR = $.ajax( $.extend( baseAjax, {
  3491. url: ajax || oSettings.sAjaxSource
  3492. } ) );
  3493. }
  3494. else if ( typeof ajax === 'function' )
  3495. {
  3496. // Is a function - let the caller define what needs to be done
  3497. oSettings.jqXHR = ajax.call( instance, data, callback, oSettings );
  3498. }
  3499. else
  3500. {
  3501. // Object to extend the base settings
  3502. oSettings.jqXHR = $.ajax( $.extend( baseAjax, ajax ) );
  3503. // Restore for next time around
  3504. ajax.data = ajaxData;
  3505. }
  3506. }
  3507. /**
  3508. * Update the table using an Ajax call
  3509. * @param {object} settings dataTables settings object
  3510. * @returns {boolean} Block the table drawing or not
  3511. * @memberof DataTable#oApi
  3512. */
  3513. function _fnAjaxUpdate( settings )
  3514. {
  3515. settings.iDraw++;
  3516. _fnProcessingDisplay( settings, true );
  3517. // Keep track of drawHold state to handle scrolling after the Ajax call
  3518. var drawHold = settings._drawHold;
  3519. _fnBuildAjax(
  3520. settings,
  3521. _fnAjaxParameters( settings ),
  3522. function(json) {
  3523. settings._drawHold = drawHold;
  3524. _fnAjaxUpdateDraw( settings, json );
  3525. settings._drawHold = false;
  3526. }
  3527. );
  3528. }
  3529. /**
  3530. * Build up the parameters in an object needed for a server-side processing
  3531. * request. Note that this is basically done twice, is different ways - a modern
  3532. * method which is used by default in DataTables 1.10 which uses objects and
  3533. * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
  3534. * the sAjaxSource option is used in the initialisation, or the legacyAjax
  3535. * option is set.
  3536. * @param {object} oSettings dataTables settings object
  3537. * @returns {bool} block the table drawing or not
  3538. * @memberof DataTable#oApi
  3539. */
  3540. function _fnAjaxParameters( settings )
  3541. {
  3542. var
  3543. columns = settings.aoColumns,
  3544. columnCount = columns.length,
  3545. features = settings.oFeatures,
  3546. preSearch = settings.oPreviousSearch,
  3547. preColSearch = settings.aoPreSearchCols,
  3548. i, data = [], dataProp, column, columnSearch,
  3549. sort = _fnSortFlatten( settings ),
  3550. displayStart = settings._iDisplayStart,
  3551. displayLength = features.bPaginate !== false ?
  3552. settings._iDisplayLength :
  3553. -1;
  3554. var param = function ( name, value ) {
  3555. data.push( { 'name': name, 'value': value } );
  3556. };
  3557. // DataTables 1.9- compatible method
  3558. param( 'sEcho', settings.iDraw );
  3559. param( 'iColumns', columnCount );
  3560. param( 'sColumns', _pluck( columns, 'sName' ).join(',') );
  3561. param( 'iDisplayStart', displayStart );
  3562. param( 'iDisplayLength', displayLength );
  3563. // DataTables 1.10+ method
  3564. var d = {
  3565. draw: settings.iDraw,
  3566. columns: [],
  3567. order: [],
  3568. start: displayStart,
  3569. length: displayLength,
  3570. search: {
  3571. value: preSearch.sSearch,
  3572. regex: preSearch.bRegex
  3573. }
  3574. };
  3575. for ( i=0 ; i<columnCount ; i++ ) {
  3576. column = columns[i];
  3577. columnSearch = preColSearch[i];
  3578. dataProp = typeof column.mData=="function" ? 'function' : column.mData ;
  3579. d.columns.push( {
  3580. data: dataProp,
  3581. name: column.sName,
  3582. searchable: column.bSearchable,
  3583. orderable: column.bSortable,
  3584. search: {
  3585. value: columnSearch.sSearch,
  3586. regex: columnSearch.bRegex
  3587. }
  3588. } );
  3589. param( "mDataProp_"+i, dataProp );
  3590. if ( features.bFilter ) {
  3591. param( 'sSearch_'+i, columnSearch.sSearch );
  3592. param( 'bRegex_'+i, columnSearch.bRegex );
  3593. param( 'bSearchable_'+i, column.bSearchable );
  3594. }
  3595. if ( features.bSort ) {
  3596. param( 'bSortable_'+i, column.bSortable );
  3597. }
  3598. }
  3599. if ( features.bFilter ) {
  3600. param( 'sSearch', preSearch.sSearch );
  3601. param( 'bRegex', preSearch.bRegex );
  3602. }
  3603. if ( features.bSort ) {
  3604. $.each( sort, function ( i, val ) {
  3605. d.order.push( { column: val.col, dir: val.dir } );
  3606. param( 'iSortCol_'+i, val.col );
  3607. param( 'sSortDir_'+i, val.dir );
  3608. } );
  3609. param( 'iSortingCols', sort.length );
  3610. }
  3611. // If the legacy.ajax parameter is null, then we automatically decide which
  3612. // form to use, based on sAjaxSource
  3613. var legacy = DataTable.ext.legacy.ajax;
  3614. if ( legacy === null ) {
  3615. return settings.sAjaxSource ? data : d;
  3616. }
  3617. // Otherwise, if legacy has been specified then we use that to decide on the
  3618. // form
  3619. return legacy ? data : d;
  3620. }
  3621. /**
  3622. * Data the data from the server (nuking the old) and redraw the table
  3623. * @param {object} oSettings dataTables settings object
  3624. * @param {object} json json data return from the server.
  3625. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  3626. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  3627. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  3628. * @param {array} json.aaData The data to display on this page
  3629. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  3630. * @memberof DataTable#oApi
  3631. */
  3632. function _fnAjaxUpdateDraw ( settings, json )
  3633. {
  3634. // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
  3635. // Support both
  3636. var compat = function ( old, modern ) {
  3637. return json[old] !== undefined ? json[old] : json[modern];
  3638. };
  3639. var data = _fnAjaxDataSrc( settings, json );
  3640. var draw = compat( 'sEcho', 'draw' );
  3641. var recordsTotal = compat( 'iTotalRecords', 'recordsTotal' );
  3642. var recordsFiltered = compat( 'iTotalDisplayRecords', 'recordsFiltered' );
  3643. if ( draw !== undefined ) {
  3644. // Protect against out of sequence returns
  3645. if ( draw*1 < settings.iDraw ) {
  3646. return;
  3647. }
  3648. settings.iDraw = draw * 1;
  3649. }
  3650. // No data in returned object, so rather than an array, we show an empty table
  3651. if ( ! data ) {
  3652. data = [];
  3653. }
  3654. _fnClearTable( settings );
  3655. settings._iRecordsTotal = parseInt(recordsTotal, 10);
  3656. settings._iRecordsDisplay = parseInt(recordsFiltered, 10);
  3657. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  3658. _fnAddData( settings, data[i] );
  3659. }
  3660. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3661. _fnDraw( settings, true );
  3662. if ( ! settings._bInitComplete ) {
  3663. _fnInitComplete( settings, json );
  3664. }
  3665. _fnProcessingDisplay( settings, false );
  3666. }
  3667. /**
  3668. * Get the data from the JSON data source to use for drawing a table. Using
  3669. * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
  3670. * source object, or from a processing function.
  3671. * @param {object} oSettings dataTables settings object
  3672. * @param {object} json Data source object / array from the server
  3673. * @return {array} Array of data to use
  3674. */
  3675. function _fnAjaxDataSrc ( oSettings, json, write )
  3676. {
  3677. var dataSrc = $.isPlainObject( oSettings.ajax ) && oSettings.ajax.dataSrc !== undefined ?
  3678. oSettings.ajax.dataSrc :
  3679. oSettings.sAjaxDataProp; // Compatibility with 1.9-.
  3680. if ( ! write ) {
  3681. if ( dataSrc === 'data' ) {
  3682. // If the default, then we still want to support the old style, and safely ignore
  3683. // it if possible
  3684. return json.aaData || json[dataSrc];
  3685. }
  3686. return dataSrc !== "" ?
  3687. _fnGetObjectDataFn( dataSrc )( json ) :
  3688. json;
  3689. }
  3690. // set
  3691. _fnSetObjectDataFn( dataSrc )( json, write );
  3692. }
  3693. /**
  3694. * Generate the node required for filtering text
  3695. * @returns {node} Filter control element
  3696. * @param {object} oSettings dataTables settings object
  3697. * @memberof DataTable#oApi
  3698. */
  3699. function _fnFeatureHtmlFilter ( settings )
  3700. {
  3701. var classes = settings.oClasses;
  3702. var tableId = settings.sTableId;
  3703. var language = settings.oLanguage;
  3704. var previousSearch = settings.oPreviousSearch;
  3705. var features = settings.aanFeatures;
  3706. var input = '<input type="search" class="'+classes.sFilterInput+'"/>';
  3707. var str = language.sSearch;
  3708. str = str.match(/_INPUT_/) ?
  3709. str.replace('_INPUT_', input) :
  3710. str+input;
  3711. var filter = $('<div/>', {
  3712. 'id': ! features.f ? tableId+'_filter' : null,
  3713. 'class': classes.sFilter
  3714. } )
  3715. .append( $('<label/>' ).append( str ) );
  3716. var searchFn = function(event) {
  3717. /* Update all other filter input elements for the new display */
  3718. var n = features.f;
  3719. var val = !this.value ? "" : this.value; // mental IE8 fix :-(
  3720. if(previousSearch.return && event.key !== "Enter") {
  3721. return;
  3722. }
  3723. /* Now do the filter */
  3724. if ( val != previousSearch.sSearch ) {
  3725. _fnFilterComplete( settings, {
  3726. "sSearch": val,
  3727. "bRegex": previousSearch.bRegex,
  3728. "bSmart": previousSearch.bSmart ,
  3729. "bCaseInsensitive": previousSearch.bCaseInsensitive,
  3730. "return": previousSearch.return
  3731. } );
  3732. // Need to redraw, without resorting
  3733. settings._iDisplayStart = 0;
  3734. _fnDraw( settings );
  3735. }
  3736. };
  3737. var searchDelay = settings.searchDelay !== null ?
  3738. settings.searchDelay :
  3739. _fnDataSource( settings ) === 'ssp' ?
  3740. 400 :
  3741. 0;
  3742. var jqFilter = $('input', filter)
  3743. .val( previousSearch.sSearch )
  3744. .attr( 'placeholder', language.sSearchPlaceholder )
  3745. .on(
  3746. 'keyup.DT search.DT input.DT paste.DT cut.DT',
  3747. searchDelay ?
  3748. _fnThrottle( searchFn, searchDelay ) :
  3749. searchFn
  3750. )
  3751. .on( 'mouseup.DT', function(e) {
  3752. // Edge fix! Edge 17 does not trigger anything other than mouse events when clicking
  3753. // on the clear icon (Edge bug 17584515). This is safe in other browsers as `searchFn`
  3754. // checks the value to see if it has changed. In other browsers it won't have.
  3755. setTimeout( function () {
  3756. searchFn.call(jqFilter[0], e);
  3757. }, 10);
  3758. } )
  3759. .on( 'keypress.DT', function(e) {
  3760. /* Prevent form submission */
  3761. if ( e.keyCode == 13 ) {
  3762. return false;
  3763. }
  3764. } )
  3765. .attr('aria-controls', tableId);
  3766. // Update the input elements whenever the table is filtered
  3767. $(settings.nTable).on( 'search.dt.DT', function ( ev, s ) {
  3768. if ( settings === s ) {
  3769. // IE9 throws an 'unknown error' if document.activeElement is used
  3770. // inside an iframe or frame...
  3771. try {
  3772. if ( jqFilter[0] !== document.activeElement ) {
  3773. jqFilter.val( previousSearch.sSearch );
  3774. }
  3775. }
  3776. catch ( e ) {}
  3777. }
  3778. } );
  3779. return filter[0];
  3780. }
  3781. /**
  3782. * Filter the table using both the global filter and column based filtering
  3783. * @param {object} oSettings dataTables settings object
  3784. * @param {object} oSearch search information
  3785. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  3786. * @memberof DataTable#oApi
  3787. */
  3788. function _fnFilterComplete ( oSettings, oInput, iForce )
  3789. {
  3790. var oPrevSearch = oSettings.oPreviousSearch;
  3791. var aoPrevSearch = oSettings.aoPreSearchCols;
  3792. var fnSaveFilter = function ( oFilter ) {
  3793. /* Save the filtering values */
  3794. oPrevSearch.sSearch = oFilter.sSearch;
  3795. oPrevSearch.bRegex = oFilter.bRegex;
  3796. oPrevSearch.bSmart = oFilter.bSmart;
  3797. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  3798. oPrevSearch.return = oFilter.return;
  3799. };
  3800. var fnRegex = function ( o ) {
  3801. // Backwards compatibility with the bEscapeRegex option
  3802. return o.bEscapeRegex !== undefined ? !o.bEscapeRegex : o.bRegex;
  3803. };
  3804. // Resolve any column types that are unknown due to addition or invalidation
  3805. // @todo As per sort - can this be moved into an event handler?
  3806. _fnColumnTypes( oSettings );
  3807. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  3808. if ( _fnDataSource( oSettings ) != 'ssp' )
  3809. {
  3810. /* Global filter */
  3811. _fnFilter( oSettings, oInput.sSearch, iForce, fnRegex(oInput), oInput.bSmart, oInput.bCaseInsensitive );
  3812. fnSaveFilter( oInput );
  3813. /* Now do the individual column filter */
  3814. for ( var i=0 ; i<aoPrevSearch.length ; i++ )
  3815. {
  3816. _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, fnRegex(aoPrevSearch[i]),
  3817. aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
  3818. }
  3819. /* Custom filtering */
  3820. _fnFilterCustom( oSettings );
  3821. }
  3822. else
  3823. {
  3824. fnSaveFilter( oInput );
  3825. }
  3826. /* Tell the draw function we have been filtering */
  3827. oSettings.bFiltered = true;
  3828. _fnCallbackFire( oSettings, null, 'search', [oSettings] );
  3829. }
  3830. /**
  3831. * Apply custom filtering functions
  3832. * @param {object} oSettings dataTables settings object
  3833. * @memberof DataTable#oApi
  3834. */
  3835. function _fnFilterCustom( settings )
  3836. {
  3837. var filters = DataTable.ext.search;
  3838. var displayRows = settings.aiDisplay;
  3839. var row, rowIdx;
  3840. for ( var i=0, ien=filters.length ; i<ien ; i++ ) {
  3841. var rows = [];
  3842. // Loop over each row and see if it should be included
  3843. for ( var j=0, jen=displayRows.length ; j<jen ; j++ ) {
  3844. rowIdx = displayRows[ j ];
  3845. row = settings.aoData[ rowIdx ];
  3846. if ( filters[i]( settings, row._aFilterData, rowIdx, row._aData, j ) ) {
  3847. rows.push( rowIdx );
  3848. }
  3849. }
  3850. // So the array reference doesn't break set the results into the
  3851. // existing array
  3852. displayRows.length = 0;
  3853. $.merge( displayRows, rows );
  3854. }
  3855. }
  3856. /**
  3857. * Filter the table on a per-column basis
  3858. * @param {object} oSettings dataTables settings object
  3859. * @param {string} sInput string to filter on
  3860. * @param {int} iColumn column to filter
  3861. * @param {bool} bRegex treat search string as a regular expression or not
  3862. * @param {bool} bSmart use smart filtering or not
  3863. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3864. * @memberof DataTable#oApi
  3865. */
  3866. function _fnFilterColumn ( settings, searchStr, colIdx, regex, smart, caseInsensitive )
  3867. {
  3868. if ( searchStr === '' ) {
  3869. return;
  3870. }
  3871. var data;
  3872. var out = [];
  3873. var display = settings.aiDisplay;
  3874. var rpSearch = _fnFilterCreateSearch( searchStr, regex, smart, caseInsensitive );
  3875. for ( var i=0 ; i<display.length ; i++ ) {
  3876. data = settings.aoData[ display[i] ]._aFilterData[ colIdx ];
  3877. if ( rpSearch.test( data ) ) {
  3878. out.push( display[i] );
  3879. }
  3880. }
  3881. settings.aiDisplay = out;
  3882. }
  3883. /**
  3884. * Filter the data table based on user input and draw the table
  3885. * @param {object} settings dataTables settings object
  3886. * @param {string} input string to filter on
  3887. * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
  3888. * @param {bool} regex treat as a regular expression or not
  3889. * @param {bool} smart perform smart filtering or not
  3890. * @param {bool} caseInsensitive Do case insensitive matching or not
  3891. * @memberof DataTable#oApi
  3892. */
  3893. function _fnFilter( settings, input, force, regex, smart, caseInsensitive )
  3894. {
  3895. var rpSearch = _fnFilterCreateSearch( input, regex, smart, caseInsensitive );
  3896. var prevSearch = settings.oPreviousSearch.sSearch;
  3897. var displayMaster = settings.aiDisplayMaster;
  3898. var display, invalidated, i;
  3899. var filtered = [];
  3900. // Need to take account of custom filtering functions - always filter
  3901. if ( DataTable.ext.search.length !== 0 ) {
  3902. force = true;
  3903. }
  3904. // Check if any of the rows were invalidated
  3905. invalidated = _fnFilterData( settings );
  3906. // If the input is blank - we just want the full data set
  3907. if ( input.length <= 0 ) {
  3908. settings.aiDisplay = displayMaster.slice();
  3909. }
  3910. else {
  3911. // New search - start from the master array
  3912. if ( invalidated ||
  3913. force ||
  3914. regex ||
  3915. prevSearch.length > input.length ||
  3916. input.indexOf(prevSearch) !== 0 ||
  3917. settings.bSorted // On resort, the display master needs to be
  3918. // re-filtered since indexes will have changed
  3919. ) {
  3920. settings.aiDisplay = displayMaster.slice();
  3921. }
  3922. // Search the display array
  3923. display = settings.aiDisplay;
  3924. for ( i=0 ; i<display.length ; i++ ) {
  3925. if ( rpSearch.test( settings.aoData[ display[i] ]._sFilterRow ) ) {
  3926. filtered.push( display[i] );
  3927. }
  3928. }
  3929. settings.aiDisplay = filtered;
  3930. }
  3931. }
  3932. /**
  3933. * Build a regular expression object suitable for searching a table
  3934. * @param {string} sSearch string to search for
  3935. * @param {bool} bRegex treat as a regular expression or not
  3936. * @param {bool} bSmart perform smart filtering or not
  3937. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3938. * @returns {RegExp} constructed object
  3939. * @memberof DataTable#oApi
  3940. */
  3941. function _fnFilterCreateSearch( search, regex, smart, caseInsensitive )
  3942. {
  3943. search = regex ?
  3944. search :
  3945. _fnEscapeRegex( search );
  3946. if ( smart ) {
  3947. /* For smart filtering we want to allow the search to work regardless of
  3948. * word order. We also want double quoted text to be preserved, so word
  3949. * order is important - a la google. So this is what we want to
  3950. * generate:
  3951. *
  3952. * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
  3953. */
  3954. var a = $.map( search.match( /["\u201C][^"\u201D]+["\u201D]|[^ ]+/g ) || [''], function ( word ) {
  3955. if ( word.charAt(0) === '"' ) {
  3956. var m = word.match( /^"(.*)"$/ );
  3957. word = m ? m[1] : word;
  3958. }
  3959. else if ( word.charAt(0) === '\u201C' ) {
  3960. var m = word.match( /^\u201C(.*)\u201D$/ );
  3961. word = m ? m[1] : word;
  3962. }
  3963. return word.replace('"', '');
  3964. } );
  3965. search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$';
  3966. }
  3967. return new RegExp( search, caseInsensitive ? 'i' : '' );
  3968. }
  3969. /**
  3970. * Escape a string such that it can be used in a regular expression
  3971. * @param {string} sVal string to escape
  3972. * @returns {string} escaped string
  3973. * @memberof DataTable#oApi
  3974. */
  3975. var _fnEscapeRegex = DataTable.util.escapeRegex;
  3976. var __filter_div = $('<div>')[0];
  3977. var __filter_div_textContent = __filter_div.textContent !== undefined;
  3978. // Update the filtering data for each row if needed (by invalidation or first run)
  3979. function _fnFilterData ( settings )
  3980. {
  3981. var columns = settings.aoColumns;
  3982. var column;
  3983. var i, j, ien, jen, filterData, cellData, row;
  3984. var wasInvalidated = false;
  3985. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  3986. row = settings.aoData[i];
  3987. if ( ! row._aFilterData ) {
  3988. filterData = [];
  3989. for ( j=0, jen=columns.length ; j<jen ; j++ ) {
  3990. column = columns[j];
  3991. if ( column.bSearchable ) {
  3992. cellData = _fnGetCellData( settings, i, j, 'filter' );
  3993. // Search in DataTables 1.10 is string based. In 1.11 this
  3994. // should be altered to also allow strict type checking.
  3995. if ( cellData === null ) {
  3996. cellData = '';
  3997. }
  3998. if ( typeof cellData !== 'string' && cellData.toString ) {
  3999. cellData = cellData.toString();
  4000. }
  4001. }
  4002. else {
  4003. cellData = '';
  4004. }
  4005. // If it looks like there is an HTML entity in the string,
  4006. // attempt to decode it so sorting works as expected. Note that
  4007. // we could use a single line of jQuery to do this, but the DOM
  4008. // method used here is much faster http://jsperf.com/html-decode
  4009. if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) {
  4010. __filter_div.innerHTML = cellData;
  4011. cellData = __filter_div_textContent ?
  4012. __filter_div.textContent :
  4013. __filter_div.innerText;
  4014. }
  4015. if ( cellData.replace ) {
  4016. cellData = cellData.replace(/[\r\n\u2028]/g, '');
  4017. }
  4018. filterData.push( cellData );
  4019. }
  4020. row._aFilterData = filterData;
  4021. row._sFilterRow = filterData.join(' ');
  4022. wasInvalidated = true;
  4023. }
  4024. }
  4025. return wasInvalidated;
  4026. }
  4027. /**
  4028. * Convert from the internal Hungarian notation to camelCase for external
  4029. * interaction
  4030. * @param {object} obj Object to convert
  4031. * @returns {object} Inverted object
  4032. * @memberof DataTable#oApi
  4033. */
  4034. function _fnSearchToCamel ( obj )
  4035. {
  4036. return {
  4037. search: obj.sSearch,
  4038. smart: obj.bSmart,
  4039. regex: obj.bRegex,
  4040. caseInsensitive: obj.bCaseInsensitive
  4041. };
  4042. }
  4043. /**
  4044. * Convert from camelCase notation to the internal Hungarian. We could use the
  4045. * Hungarian convert function here, but this is cleaner
  4046. * @param {object} obj Object to convert
  4047. * @returns {object} Inverted object
  4048. * @memberof DataTable#oApi
  4049. */
  4050. function _fnSearchToHung ( obj )
  4051. {
  4052. return {
  4053. sSearch: obj.search,
  4054. bSmart: obj.smart,
  4055. bRegex: obj.regex,
  4056. bCaseInsensitive: obj.caseInsensitive
  4057. };
  4058. }
  4059. /**
  4060. * Generate the node required for the info display
  4061. * @param {object} oSettings dataTables settings object
  4062. * @returns {node} Information element
  4063. * @memberof DataTable#oApi
  4064. */
  4065. function _fnFeatureHtmlInfo ( settings )
  4066. {
  4067. var
  4068. tid = settings.sTableId,
  4069. nodes = settings.aanFeatures.i,
  4070. n = $('<div/>', {
  4071. 'class': settings.oClasses.sInfo,
  4072. 'id': ! nodes ? tid+'_info' : null
  4073. } );
  4074. if ( ! nodes ) {
  4075. // Update display on each draw
  4076. settings.aoDrawCallback.push( {
  4077. "fn": _fnUpdateInfo,
  4078. "sName": "information"
  4079. } );
  4080. n
  4081. .attr( 'role', 'status' )
  4082. .attr( 'aria-live', 'polite' );
  4083. // Table is described by our info div
  4084. $(settings.nTable).attr( 'aria-describedby', tid+'_info' );
  4085. }
  4086. return n[0];
  4087. }
  4088. /**
  4089. * Update the information elements in the display
  4090. * @param {object} settings dataTables settings object
  4091. * @memberof DataTable#oApi
  4092. */
  4093. function _fnUpdateInfo ( settings )
  4094. {
  4095. /* Show information about the table */
  4096. var nodes = settings.aanFeatures.i;
  4097. if ( nodes.length === 0 ) {
  4098. return;
  4099. }
  4100. var
  4101. lang = settings.oLanguage,
  4102. start = settings._iDisplayStart+1,
  4103. end = settings.fnDisplayEnd(),
  4104. max = settings.fnRecordsTotal(),
  4105. total = settings.fnRecordsDisplay(),
  4106. out = total ?
  4107. lang.sInfo :
  4108. lang.sInfoEmpty;
  4109. if ( total !== max ) {
  4110. /* Record set after filtering */
  4111. out += ' ' + lang.sInfoFiltered;
  4112. }
  4113. // Convert the macros
  4114. out += lang.sInfoPostFix;
  4115. out = _fnInfoMacros( settings, out );
  4116. var callback = lang.fnInfoCallback;
  4117. if ( callback !== null ) {
  4118. out = callback.call( settings.oInstance,
  4119. settings, start, end, max, total, out
  4120. );
  4121. }
  4122. $(nodes).html( out );
  4123. }
  4124. function _fnInfoMacros ( settings, str )
  4125. {
  4126. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  4127. // internally
  4128. var
  4129. formatter = settings.fnFormatNumber,
  4130. start = settings._iDisplayStart+1,
  4131. len = settings._iDisplayLength,
  4132. vis = settings.fnRecordsDisplay(),
  4133. all = len === -1;
  4134. return str.
  4135. replace(/_START_/g, formatter.call( settings, start ) ).
  4136. replace(/_END_/g, formatter.call( settings, settings.fnDisplayEnd() ) ).
  4137. replace(/_MAX_/g, formatter.call( settings, settings.fnRecordsTotal() ) ).
  4138. replace(/_TOTAL_/g, formatter.call( settings, vis ) ).
  4139. replace(/_PAGE_/g, formatter.call( settings, all ? 1 : Math.ceil( start / len ) ) ).
  4140. replace(/_PAGES_/g, formatter.call( settings, all ? 1 : Math.ceil( vis / len ) ) );
  4141. }
  4142. /**
  4143. * Draw the table for the first time, adding all required features
  4144. * @param {object} settings dataTables settings object
  4145. * @memberof DataTable#oApi
  4146. */
  4147. function _fnInitialise ( settings )
  4148. {
  4149. var i, iLen, iAjaxStart=settings.iInitDisplayStart;
  4150. var columns = settings.aoColumns, column;
  4151. var features = settings.oFeatures;
  4152. var deferLoading = settings.bDeferLoading; // value modified by the draw
  4153. /* Ensure that the table data is fully initialised */
  4154. if ( ! settings.bInitialised ) {
  4155. setTimeout( function(){ _fnInitialise( settings ); }, 200 );
  4156. return;
  4157. }
  4158. /* Show the display HTML options */
  4159. _fnAddOptionsHtml( settings );
  4160. /* Build and draw the header / footer for the table */
  4161. _fnBuildHead( settings );
  4162. _fnDrawHead( settings, settings.aoHeader );
  4163. _fnDrawHead( settings, settings.aoFooter );
  4164. /* Okay to show that something is going on now */
  4165. _fnProcessingDisplay( settings, true );
  4166. /* Calculate sizes for columns */
  4167. if ( features.bAutoWidth ) {
  4168. _fnCalculateColumnWidths( settings );
  4169. }
  4170. for ( i=0, iLen=columns.length ; i<iLen ; i++ ) {
  4171. column = columns[i];
  4172. if ( column.sWidth ) {
  4173. column.nTh.style.width = _fnStringToCss( column.sWidth );
  4174. }
  4175. }
  4176. _fnCallbackFire( settings, null, 'preInit', [settings] );
  4177. // If there is default sorting required - let's do it. The sort function
  4178. // will do the drawing for us. Otherwise we draw the table regardless of the
  4179. // Ajax source - this allows the table to look initialised for Ajax sourcing
  4180. // data (show 'loading' message possibly)
  4181. _fnReDraw( settings );
  4182. // Server-side processing init complete is done by _fnAjaxUpdateDraw
  4183. var dataSrc = _fnDataSource( settings );
  4184. if ( dataSrc != 'ssp' || deferLoading ) {
  4185. // if there is an ajax source load the data
  4186. if ( dataSrc == 'ajax' ) {
  4187. _fnBuildAjax( settings, [], function(json) {
  4188. var aData = _fnAjaxDataSrc( settings, json );
  4189. // Got the data - add it to the table
  4190. for ( i=0 ; i<aData.length ; i++ ) {
  4191. _fnAddData( settings, aData[i] );
  4192. }
  4193. // Reset the init display for cookie saving. We've already done
  4194. // a filter, and therefore cleared it before. So we need to make
  4195. // it appear 'fresh'
  4196. settings.iInitDisplayStart = iAjaxStart;
  4197. _fnReDraw( settings );
  4198. _fnProcessingDisplay( settings, false );
  4199. _fnInitComplete( settings, json );
  4200. }, settings );
  4201. }
  4202. else {
  4203. _fnProcessingDisplay( settings, false );
  4204. _fnInitComplete( settings );
  4205. }
  4206. }
  4207. }
  4208. /**
  4209. * Draw the table for the first time, adding all required features
  4210. * @param {object} oSettings dataTables settings object
  4211. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  4212. * with client-side processing (optional)
  4213. * @memberof DataTable#oApi
  4214. */
  4215. function _fnInitComplete ( settings, json )
  4216. {
  4217. settings._bInitComplete = true;
  4218. // When data was added after the initialisation (data or Ajax) we need to
  4219. // calculate the column sizing
  4220. if ( json || settings.oInit.aaData ) {
  4221. _fnAdjustColumnSizing( settings );
  4222. }
  4223. _fnCallbackFire( settings, null, 'plugin-init', [settings, json] );
  4224. _fnCallbackFire( settings, 'aoInitComplete', 'init', [settings, json] );
  4225. }
  4226. function _fnLengthChange ( settings, val )
  4227. {
  4228. var len = parseInt( val, 10 );
  4229. settings._iDisplayLength = len;
  4230. _fnLengthOverflow( settings );
  4231. // Fire length change event
  4232. _fnCallbackFire( settings, null, 'length', [settings, len] );
  4233. }
  4234. /**
  4235. * Generate the node required for user display length changing
  4236. * @param {object} settings dataTables settings object
  4237. * @returns {node} Display length feature node
  4238. * @memberof DataTable#oApi
  4239. */
  4240. function _fnFeatureHtmlLength ( settings )
  4241. {
  4242. var
  4243. classes = settings.oClasses,
  4244. tableId = settings.sTableId,
  4245. menu = settings.aLengthMenu,
  4246. d2 = Array.isArray( menu[0] ),
  4247. lengths = d2 ? menu[0] : menu,
  4248. language = d2 ? menu[1] : menu;
  4249. var select = $('<select/>', {
  4250. 'name': tableId+'_length',
  4251. 'aria-controls': tableId,
  4252. 'class': classes.sLengthSelect
  4253. } );
  4254. for ( var i=0, ien=lengths.length ; i<ien ; i++ ) {
  4255. select[0][ i ] = new Option(
  4256. typeof language[i] === 'number' ?
  4257. settings.fnFormatNumber( language[i] ) :
  4258. language[i],
  4259. lengths[i]
  4260. );
  4261. }
  4262. var div = $('<div><label/></div>').addClass( classes.sLength );
  4263. if ( ! settings.aanFeatures.l ) {
  4264. div[0].id = tableId+'_length';
  4265. }
  4266. div.children().append(
  4267. settings.oLanguage.sLengthMenu.replace( '_MENU_', select[0].outerHTML )
  4268. );
  4269. // Can't use `select` variable as user might provide their own and the
  4270. // reference is broken by the use of outerHTML
  4271. $('select', div)
  4272. .val( settings._iDisplayLength )
  4273. .on( 'change.DT', function(e) {
  4274. _fnLengthChange( settings, $(this).val() );
  4275. _fnDraw( settings );
  4276. } );
  4277. // Update node value whenever anything changes the table's length
  4278. $(settings.nTable).on( 'length.dt.DT', function (e, s, len) {
  4279. if ( settings === s ) {
  4280. $('select', div).val( len );
  4281. }
  4282. } );
  4283. return div[0];
  4284. }
  4285. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4286. * Note that most of the paging logic is done in
  4287. * DataTable.ext.pager
  4288. */
  4289. /**
  4290. * Generate the node required for default pagination
  4291. * @param {object} oSettings dataTables settings object
  4292. * @returns {node} Pagination feature node
  4293. * @memberof DataTable#oApi
  4294. */
  4295. function _fnFeatureHtmlPaginate ( settings )
  4296. {
  4297. var
  4298. type = settings.sPaginationType,
  4299. plugin = DataTable.ext.pager[ type ],
  4300. modern = typeof plugin === 'function',
  4301. redraw = function( settings ) {
  4302. _fnDraw( settings );
  4303. },
  4304. node = $('<div/>').addClass( settings.oClasses.sPaging + type )[0],
  4305. features = settings.aanFeatures;
  4306. if ( ! modern ) {
  4307. plugin.fnInit( settings, node, redraw );
  4308. }
  4309. /* Add a draw callback for the pagination on first instance, to update the paging display */
  4310. if ( ! features.p )
  4311. {
  4312. node.id = settings.sTableId+'_paginate';
  4313. settings.aoDrawCallback.push( {
  4314. "fn": function( settings ) {
  4315. if ( modern ) {
  4316. var
  4317. start = settings._iDisplayStart,
  4318. len = settings._iDisplayLength,
  4319. visRecords = settings.fnRecordsDisplay(),
  4320. all = len === -1,
  4321. page = all ? 0 : Math.ceil( start / len ),
  4322. pages = all ? 1 : Math.ceil( visRecords / len ),
  4323. buttons = plugin(page, pages),
  4324. i, ien;
  4325. for ( i=0, ien=features.p.length ; i<ien ; i++ ) {
  4326. _fnRenderer( settings, 'pageButton' )(
  4327. settings, features.p[i], i, buttons, page, pages
  4328. );
  4329. }
  4330. }
  4331. else {
  4332. plugin.fnUpdate( settings, redraw );
  4333. }
  4334. },
  4335. "sName": "pagination"
  4336. } );
  4337. }
  4338. return node;
  4339. }
  4340. /**
  4341. * Alter the display settings to change the page
  4342. * @param {object} settings DataTables settings object
  4343. * @param {string|int} action Paging action to take: "first", "previous",
  4344. * "next" or "last" or page number to jump to (integer)
  4345. * @param [bool] redraw Automatically draw the update or not
  4346. * @returns {bool} true page has changed, false - no change
  4347. * @memberof DataTable#oApi
  4348. */
  4349. function _fnPageChange ( settings, action, redraw )
  4350. {
  4351. var
  4352. start = settings._iDisplayStart,
  4353. len = settings._iDisplayLength,
  4354. records = settings.fnRecordsDisplay();
  4355. if ( records === 0 || len === -1 )
  4356. {
  4357. start = 0;
  4358. }
  4359. else if ( typeof action === "number" )
  4360. {
  4361. start = action * len;
  4362. if ( start > records )
  4363. {
  4364. start = 0;
  4365. }
  4366. }
  4367. else if ( action == "first" )
  4368. {
  4369. start = 0;
  4370. }
  4371. else if ( action == "previous" )
  4372. {
  4373. start = len >= 0 ?
  4374. start - len :
  4375. 0;
  4376. if ( start < 0 )
  4377. {
  4378. start = 0;
  4379. }
  4380. }
  4381. else if ( action == "next" )
  4382. {
  4383. if ( start + len < records )
  4384. {
  4385. start += len;
  4386. }
  4387. }
  4388. else if ( action == "last" )
  4389. {
  4390. start = Math.floor( (records-1) / len) * len;
  4391. }
  4392. else
  4393. {
  4394. _fnLog( settings, 0, "Unknown paging action: "+action, 5 );
  4395. }
  4396. var changed = settings._iDisplayStart !== start;
  4397. settings._iDisplayStart = start;
  4398. if ( changed ) {
  4399. _fnCallbackFire( settings, null, 'page', [settings] );
  4400. if ( redraw ) {
  4401. _fnDraw( settings );
  4402. }
  4403. }
  4404. else {
  4405. // No change event - paging was called, but no change
  4406. _fnCallbackFire( settings, null, 'page-nc', [settings] );
  4407. }
  4408. return changed;
  4409. }
  4410. /**
  4411. * Generate the node required for the processing node
  4412. * @param {object} settings dataTables settings object
  4413. * @returns {node} Processing element
  4414. * @memberof DataTable#oApi
  4415. */
  4416. function _fnFeatureHtmlProcessing ( settings )
  4417. {
  4418. return $('<div/>', {
  4419. 'id': ! settings.aanFeatures.r ? settings.sTableId+'_processing' : null,
  4420. 'class': settings.oClasses.sProcessing,
  4421. 'role': 'status'
  4422. } )
  4423. .html( settings.oLanguage.sProcessing )
  4424. .append('<div><div></div><div></div><div></div><div></div></div>')
  4425. .insertBefore( settings.nTable )[0];
  4426. }
  4427. /**
  4428. * Display or hide the processing indicator
  4429. * @param {object} settings dataTables settings object
  4430. * @param {bool} show Show the processing indicator (true) or not (false)
  4431. * @memberof DataTable#oApi
  4432. */
  4433. function _fnProcessingDisplay ( settings, show )
  4434. {
  4435. if ( settings.oFeatures.bProcessing ) {
  4436. $(settings.aanFeatures.r).css( 'display', show ? 'block' : 'none' );
  4437. }
  4438. _fnCallbackFire( settings, null, 'processing', [settings, show] );
  4439. }
  4440. /**
  4441. * Add any control elements for the table - specifically scrolling
  4442. * @param {object} settings dataTables settings object
  4443. * @returns {node} Node to add to the DOM
  4444. * @memberof DataTable#oApi
  4445. */
  4446. function _fnFeatureHtmlTable ( settings )
  4447. {
  4448. var table = $(settings.nTable);
  4449. // Scrolling from here on in
  4450. var scroll = settings.oScroll;
  4451. if ( scroll.sX === '' && scroll.sY === '' ) {
  4452. return settings.nTable;
  4453. }
  4454. var scrollX = scroll.sX;
  4455. var scrollY = scroll.sY;
  4456. var classes = settings.oClasses;
  4457. var caption = table.children('caption');
  4458. var captionSide = caption.length ? caption[0]._captionSide : null;
  4459. var headerClone = $( table[0].cloneNode(false) );
  4460. var footerClone = $( table[0].cloneNode(false) );
  4461. var footer = table.children('tfoot');
  4462. var _div = '<div/>';
  4463. var size = function ( s ) {
  4464. return !s ? null : _fnStringToCss( s );
  4465. };
  4466. if ( ! footer.length ) {
  4467. footer = null;
  4468. }
  4469. /*
  4470. * The HTML structure that we want to generate in this function is:
  4471. * div - scroller
  4472. * div - scroll head
  4473. * div - scroll head inner
  4474. * table - scroll head table
  4475. * thead - thead
  4476. * div - scroll body
  4477. * table - table (master table)
  4478. * thead - thead clone for sizing
  4479. * tbody - tbody
  4480. * div - scroll foot
  4481. * div - scroll foot inner
  4482. * table - scroll foot table
  4483. * tfoot - tfoot
  4484. */
  4485. var scroller = $( _div, { 'class': classes.sScrollWrapper } )
  4486. .append(
  4487. $(_div, { 'class': classes.sScrollHead } )
  4488. .css( {
  4489. overflow: 'hidden',
  4490. position: 'relative',
  4491. border: 0,
  4492. width: scrollX ? size(scrollX) : '100%'
  4493. } )
  4494. .append(
  4495. $(_div, { 'class': classes.sScrollHeadInner } )
  4496. .css( {
  4497. 'box-sizing': 'content-box',
  4498. width: scroll.sXInner || '100%'
  4499. } )
  4500. .append(
  4501. headerClone
  4502. .removeAttr('id')
  4503. .css( 'margin-left', 0 )
  4504. .append( captionSide === 'top' ? caption : null )
  4505. .append(
  4506. table.children('thead')
  4507. )
  4508. )
  4509. )
  4510. )
  4511. .append(
  4512. $(_div, { 'class': classes.sScrollBody } )
  4513. .css( {
  4514. position: 'relative',
  4515. overflow: 'auto',
  4516. width: size( scrollX )
  4517. } )
  4518. .append( table )
  4519. );
  4520. if ( footer ) {
  4521. scroller.append(
  4522. $(_div, { 'class': classes.sScrollFoot } )
  4523. .css( {
  4524. overflow: 'hidden',
  4525. border: 0,
  4526. width: scrollX ? size(scrollX) : '100%'
  4527. } )
  4528. .append(
  4529. $(_div, { 'class': classes.sScrollFootInner } )
  4530. .append(
  4531. footerClone
  4532. .removeAttr('id')
  4533. .css( 'margin-left', 0 )
  4534. .append( captionSide === 'bottom' ? caption : null )
  4535. .append(
  4536. table.children('tfoot')
  4537. )
  4538. )
  4539. )
  4540. );
  4541. }
  4542. var children = scroller.children();
  4543. var scrollHead = children[0];
  4544. var scrollBody = children[1];
  4545. var scrollFoot = footer ? children[2] : null;
  4546. // When the body is scrolled, then we also want to scroll the headers
  4547. if ( scrollX ) {
  4548. $(scrollBody).on( 'scroll.DT', function (e) {
  4549. var scrollLeft = this.scrollLeft;
  4550. scrollHead.scrollLeft = scrollLeft;
  4551. if ( footer ) {
  4552. scrollFoot.scrollLeft = scrollLeft;
  4553. }
  4554. } );
  4555. }
  4556. $(scrollBody).css('max-height', scrollY);
  4557. if (! scroll.bCollapse) {
  4558. $(scrollBody).css('height', scrollY);
  4559. }
  4560. settings.nScrollHead = scrollHead;
  4561. settings.nScrollBody = scrollBody;
  4562. settings.nScrollFoot = scrollFoot;
  4563. // On redraw - align columns
  4564. settings.aoDrawCallback.push( {
  4565. "fn": _fnScrollDraw,
  4566. "sName": "scrolling"
  4567. } );
  4568. return scroller[0];
  4569. }
  4570. /**
  4571. * Update the header, footer and body tables for resizing - i.e. column
  4572. * alignment.
  4573. *
  4574. * Welcome to the most horrible function DataTables. The process that this
  4575. * function follows is basically:
  4576. * 1. Re-create the table inside the scrolling div
  4577. * 2. Take live measurements from the DOM
  4578. * 3. Apply the measurements to align the columns
  4579. * 4. Clean up
  4580. *
  4581. * @param {object} settings dataTables settings object
  4582. * @memberof DataTable#oApi
  4583. */
  4584. function _fnScrollDraw ( settings )
  4585. {
  4586. // Given that this is such a monster function, a lot of variables are use
  4587. // to try and keep the minimised size as small as possible
  4588. var
  4589. scroll = settings.oScroll,
  4590. scrollX = scroll.sX,
  4591. scrollXInner = scroll.sXInner,
  4592. scrollY = scroll.sY,
  4593. barWidth = scroll.iBarWidth,
  4594. divHeader = $(settings.nScrollHead),
  4595. divHeaderStyle = divHeader[0].style,
  4596. divHeaderInner = divHeader.children('div'),
  4597. divHeaderInnerStyle = divHeaderInner[0].style,
  4598. divHeaderTable = divHeaderInner.children('table'),
  4599. divBodyEl = settings.nScrollBody,
  4600. divBody = $(divBodyEl),
  4601. divBodyStyle = divBodyEl.style,
  4602. divFooter = $(settings.nScrollFoot),
  4603. divFooterInner = divFooter.children('div'),
  4604. divFooterTable = divFooterInner.children('table'),
  4605. header = $(settings.nTHead),
  4606. table = $(settings.nTable),
  4607. tableEl = table[0],
  4608. tableStyle = tableEl.style,
  4609. footer = settings.nTFoot ? $(settings.nTFoot) : null,
  4610. browser = settings.oBrowser,
  4611. ie67 = browser.bScrollOversize,
  4612. dtHeaderCells = _pluck( settings.aoColumns, 'nTh' ),
  4613. headerTrgEls, footerTrgEls,
  4614. headerSrcEls, footerSrcEls,
  4615. headerCopy, footerCopy,
  4616. headerWidths=[], footerWidths=[],
  4617. headerContent=[], footerContent=[],
  4618. idx, correction, sanityWidth,
  4619. zeroOut = function(nSizer) {
  4620. var style = nSizer.style;
  4621. style.paddingTop = "0";
  4622. style.paddingBottom = "0";
  4623. style.borderTopWidth = "0";
  4624. style.borderBottomWidth = "0";
  4625. style.height = 0;
  4626. };
  4627. // If the scrollbar visibility has changed from the last draw, we need to
  4628. // adjust the column sizes as the table width will have changed to account
  4629. // for the scrollbar
  4630. var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
  4631. if ( settings.scrollBarVis !== scrollBarVis && settings.scrollBarVis !== undefined ) {
  4632. settings.scrollBarVis = scrollBarVis;
  4633. _fnAdjustColumnSizing( settings );
  4634. return; // adjust column sizing will call this function again
  4635. }
  4636. else {
  4637. settings.scrollBarVis = scrollBarVis;
  4638. }
  4639. /*
  4640. * 1. Re-create the table inside the scrolling div
  4641. */
  4642. // Remove the old minimised thead and tfoot elements in the inner table
  4643. table.children('thead, tfoot').remove();
  4644. if ( footer ) {
  4645. footerCopy = footer.clone().prependTo( table );
  4646. footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized
  4647. footerSrcEls = footerCopy.find('tr');
  4648. footerCopy.find('[id]').removeAttr('id');
  4649. }
  4650. // Clone the current header and footer elements and then place it into the inner table
  4651. headerCopy = header.clone().prependTo( table );
  4652. headerTrgEls = header.find('tr'); // original header is in its own table
  4653. headerSrcEls = headerCopy.find('tr');
  4654. headerCopy.find('th, td').removeAttr('tabindex');
  4655. headerCopy.find('[id]').removeAttr('id');
  4656. /*
  4657. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  4658. */
  4659. // Remove old sizing and apply the calculated column widths
  4660. // Get the unique column headers in the newly created (cloned) header. We want to apply the
  4661. // calculated sizes to this header
  4662. if ( ! scrollX )
  4663. {
  4664. divBodyStyle.width = '100%';
  4665. divHeader[0].style.width = '100%';
  4666. }
  4667. $.each( _fnGetUniqueThs( settings, headerCopy ), function ( i, el ) {
  4668. idx = _fnVisibleToColumnIndex( settings, i );
  4669. el.style.width = settings.aoColumns[idx].sWidth;
  4670. } );
  4671. if ( footer ) {
  4672. _fnApplyToChildren( function(n) {
  4673. n.style.width = "";
  4674. }, footerSrcEls );
  4675. }
  4676. // Size the table as a whole
  4677. sanityWidth = table.outerWidth();
  4678. if ( scrollX === "" ) {
  4679. // No x scrolling
  4680. tableStyle.width = "100%";
  4681. // IE7 will make the width of the table when 100% include the scrollbar
  4682. // - which is shouldn't. When there is a scrollbar we need to take this
  4683. // into account.
  4684. if ( ie67 && (table.find('tbody').height() > divBodyEl.offsetHeight ||
  4685. divBody.css('overflow-y') == "scroll")
  4686. ) {
  4687. tableStyle.width = _fnStringToCss( table.outerWidth() - barWidth);
  4688. }
  4689. // Recalculate the sanity width
  4690. sanityWidth = table.outerWidth();
  4691. }
  4692. else if ( scrollXInner !== "" ) {
  4693. // legacy x scroll inner has been given - use it
  4694. tableStyle.width = _fnStringToCss(scrollXInner);
  4695. // Recalculate the sanity width
  4696. sanityWidth = table.outerWidth();
  4697. }
  4698. // Hidden header should have zero height, so remove padding and borders. Then
  4699. // set the width based on the real headers
  4700. // Apply all styles in one pass
  4701. _fnApplyToChildren( zeroOut, headerSrcEls );
  4702. // Read all widths in next pass
  4703. _fnApplyToChildren( function(nSizer) {
  4704. var style = window.getComputedStyle ?
  4705. window.getComputedStyle(nSizer).width :
  4706. _fnStringToCss( $(nSizer).width() );
  4707. headerContent.push( nSizer.innerHTML );
  4708. headerWidths.push( style );
  4709. }, headerSrcEls );
  4710. // Apply all widths in final pass
  4711. _fnApplyToChildren( function(nToSize, i) {
  4712. nToSize.style.width = headerWidths[i];
  4713. }, headerTrgEls );
  4714. $(headerSrcEls).css('height', 0);
  4715. /* Same again with the footer if we have one */
  4716. if ( footer )
  4717. {
  4718. _fnApplyToChildren( zeroOut, footerSrcEls );
  4719. _fnApplyToChildren( function(nSizer) {
  4720. footerContent.push( nSizer.innerHTML );
  4721. footerWidths.push( _fnStringToCss( $(nSizer).css('width') ) );
  4722. }, footerSrcEls );
  4723. _fnApplyToChildren( function(nToSize, i) {
  4724. nToSize.style.width = footerWidths[i];
  4725. }, footerTrgEls );
  4726. $(footerSrcEls).height(0);
  4727. }
  4728. /*
  4729. * 3. Apply the measurements
  4730. */
  4731. // "Hide" the header and footer that we used for the sizing. We need to keep
  4732. // the content of the cell so that the width applied to the header and body
  4733. // both match, but we want to hide it completely. We want to also fix their
  4734. // width to what they currently are
  4735. _fnApplyToChildren( function(nSizer, i) {
  4736. nSizer.innerHTML = '<div class="dataTables_sizing">'+headerContent[i]+'</div>';
  4737. nSizer.childNodes[0].style.height = "0";
  4738. nSizer.childNodes[0].style.overflow = "hidden";
  4739. nSizer.style.width = headerWidths[i];
  4740. }, headerSrcEls );
  4741. if ( footer )
  4742. {
  4743. _fnApplyToChildren( function(nSizer, i) {
  4744. nSizer.innerHTML = '<div class="dataTables_sizing">'+footerContent[i]+'</div>';
  4745. nSizer.childNodes[0].style.height = "0";
  4746. nSizer.childNodes[0].style.overflow = "hidden";
  4747. nSizer.style.width = footerWidths[i];
  4748. }, footerSrcEls );
  4749. }
  4750. // Sanity check that the table is of a sensible width. If not then we are going to get
  4751. // misalignment - try to prevent this by not allowing the table to shrink below its min width
  4752. if ( Math.round(table.outerWidth()) < Math.round(sanityWidth) )
  4753. {
  4754. // The min width depends upon if we have a vertical scrollbar visible or not */
  4755. correction = ((divBodyEl.scrollHeight > divBodyEl.offsetHeight ||
  4756. divBody.css('overflow-y') == "scroll")) ?
  4757. sanityWidth+barWidth :
  4758. sanityWidth;
  4759. // IE6/7 are a law unto themselves...
  4760. if ( ie67 && (divBodyEl.scrollHeight >
  4761. divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")
  4762. ) {
  4763. tableStyle.width = _fnStringToCss( correction-barWidth );
  4764. }
  4765. // And give the user a warning that we've stopped the table getting too small
  4766. if ( scrollX === "" || scrollXInner !== "" ) {
  4767. _fnLog( settings, 1, 'Possible column misalignment', 6 );
  4768. }
  4769. }
  4770. else
  4771. {
  4772. correction = '100%';
  4773. }
  4774. // Apply to the container elements
  4775. divBodyStyle.width = _fnStringToCss( correction );
  4776. divHeaderStyle.width = _fnStringToCss( correction );
  4777. if ( footer ) {
  4778. settings.nScrollFoot.style.width = _fnStringToCss( correction );
  4779. }
  4780. /*
  4781. * 4. Clean up
  4782. */
  4783. if ( ! scrollY ) {
  4784. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  4785. * the scrollbar height from the visible display, rather than adding it on. We need to
  4786. * set the height in order to sort this. Don't want to do it in any other browsers.
  4787. */
  4788. if ( ie67 ) {
  4789. divBodyStyle.height = _fnStringToCss( tableEl.offsetHeight+barWidth );
  4790. }
  4791. }
  4792. /* Finally set the width's of the header and footer tables */
  4793. var iOuterWidth = table.outerWidth();
  4794. divHeaderTable[0].style.width = _fnStringToCss( iOuterWidth );
  4795. divHeaderInnerStyle.width = _fnStringToCss( iOuterWidth );
  4796. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  4797. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  4798. var bScrolling = table.height() > divBodyEl.clientHeight || divBody.css('overflow-y') == "scroll";
  4799. var padding = 'padding' + (browser.bScrollbarLeft ? 'Left' : 'Right' );
  4800. divHeaderInnerStyle[ padding ] = bScrolling ? barWidth+"px" : "0px";
  4801. if ( footer ) {
  4802. divFooterTable[0].style.width = _fnStringToCss( iOuterWidth );
  4803. divFooterInner[0].style.width = _fnStringToCss( iOuterWidth );
  4804. divFooterInner[0].style[padding] = bScrolling ? barWidth+"px" : "0px";
  4805. }
  4806. // Correct DOM ordering for colgroup - comes before the thead
  4807. table.children('colgroup').insertBefore( table.children('thead') );
  4808. /* Adjust the position of the header in case we loose the y-scrollbar */
  4809. divBody.trigger('scroll');
  4810. // If sorting or filtering has occurred, jump the scrolling back to the top
  4811. // only if we aren't holding the position
  4812. if ( (settings.bSorted || settings.bFiltered) && ! settings._drawHold ) {
  4813. divBodyEl.scrollTop = 0;
  4814. }
  4815. }
  4816. /**
  4817. * Apply a given function to the display child nodes of an element array (typically
  4818. * TD children of TR rows
  4819. * @param {function} fn Method to apply to the objects
  4820. * @param array {nodes} an1 List of elements to look through for display children
  4821. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  4822. * @memberof DataTable#oApi
  4823. */
  4824. function _fnApplyToChildren( fn, an1, an2 )
  4825. {
  4826. var index=0, i=0, iLen=an1.length;
  4827. var nNode1, nNode2;
  4828. while ( i < iLen ) {
  4829. nNode1 = an1[i].firstChild;
  4830. nNode2 = an2 ? an2[i].firstChild : null;
  4831. while ( nNode1 ) {
  4832. if ( nNode1.nodeType === 1 ) {
  4833. if ( an2 ) {
  4834. fn( nNode1, nNode2, index );
  4835. }
  4836. else {
  4837. fn( nNode1, index );
  4838. }
  4839. index++;
  4840. }
  4841. nNode1 = nNode1.nextSibling;
  4842. nNode2 = an2 ? nNode2.nextSibling : null;
  4843. }
  4844. i++;
  4845. }
  4846. }
  4847. var __re_html_remove = /<.*?>/g;
  4848. /**
  4849. * Calculate the width of columns for the table
  4850. * @param {object} oSettings dataTables settings object
  4851. * @memberof DataTable#oApi
  4852. */
  4853. function _fnCalculateColumnWidths ( oSettings )
  4854. {
  4855. var
  4856. table = oSettings.nTable,
  4857. columns = oSettings.aoColumns,
  4858. scroll = oSettings.oScroll,
  4859. scrollY = scroll.sY,
  4860. scrollX = scroll.sX,
  4861. scrollXInner = scroll.sXInner,
  4862. columnCount = columns.length,
  4863. visibleColumns = _fnGetColumns( oSettings, 'bVisible' ),
  4864. headerCells = $('th', oSettings.nTHead),
  4865. tableWidthAttr = table.getAttribute('width'), // from DOM element
  4866. tableContainer = table.parentNode,
  4867. userInputs = false,
  4868. i, column, columnIdx, width, outerWidth,
  4869. browser = oSettings.oBrowser,
  4870. ie67 = browser.bScrollOversize;
  4871. var styleWidth = table.style.width;
  4872. if ( styleWidth && styleWidth.indexOf('%') !== -1 ) {
  4873. tableWidthAttr = styleWidth;
  4874. }
  4875. /* Convert any user input sizes into pixel sizes */
  4876. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4877. column = columns[ visibleColumns[i] ];
  4878. if ( column.sWidth !== null ) {
  4879. column.sWidth = _fnConvertToWidth( column.sWidthOrig, tableContainer );
  4880. userInputs = true;
  4881. }
  4882. }
  4883. /* If the number of columns in the DOM equals the number that we have to
  4884. * process in DataTables, then we can use the offsets that are created by
  4885. * the web- browser. No custom sizes can be set in order for this to happen,
  4886. * nor scrolling used
  4887. */
  4888. if ( ie67 || ! userInputs && ! scrollX && ! scrollY &&
  4889. columnCount == _fnVisbleColumns( oSettings ) &&
  4890. columnCount == headerCells.length
  4891. ) {
  4892. for ( i=0 ; i<columnCount ; i++ ) {
  4893. var colIdx = _fnVisibleToColumnIndex( oSettings, i );
  4894. if ( colIdx !== null ) {
  4895. columns[ colIdx ].sWidth = _fnStringToCss( headerCells.eq(i).width() );
  4896. }
  4897. }
  4898. }
  4899. else
  4900. {
  4901. // Otherwise construct a single row, worst case, table with the widest
  4902. // node in the data, assign any user defined widths, then insert it into
  4903. // the DOM and allow the browser to do all the hard work of calculating
  4904. // table widths
  4905. var tmpTable = $(table).clone() // don't use cloneNode - IE8 will remove events on the main table
  4906. .css( 'visibility', 'hidden' )
  4907. .removeAttr( 'id' );
  4908. // Clean up the table body
  4909. tmpTable.find('tbody tr').remove();
  4910. var tr = $('<tr/>').appendTo( tmpTable.find('tbody') );
  4911. // Clone the table header and footer - we can't use the header / footer
  4912. // from the cloned table, since if scrolling is active, the table's
  4913. // real header and footer are contained in different table tags
  4914. tmpTable.find('thead, tfoot').remove();
  4915. tmpTable
  4916. .append( $(oSettings.nTHead).clone() )
  4917. .append( $(oSettings.nTFoot).clone() );
  4918. // Remove any assigned widths from the footer (from scrolling)
  4919. tmpTable.find('tfoot th, tfoot td').css('width', '');
  4920. // Apply custom sizing to the cloned header
  4921. headerCells = _fnGetUniqueThs( oSettings, tmpTable.find('thead')[0] );
  4922. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4923. column = columns[ visibleColumns[i] ];
  4924. headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ?
  4925. _fnStringToCss( column.sWidthOrig ) :
  4926. '';
  4927. // For scrollX we need to force the column width otherwise the
  4928. // browser will collapse it. If this width is smaller than the
  4929. // width the column requires, then it will have no effect
  4930. if ( column.sWidthOrig && scrollX ) {
  4931. $( headerCells[i] ).append( $('<div/>').css( {
  4932. width: column.sWidthOrig,
  4933. margin: 0,
  4934. padding: 0,
  4935. border: 0,
  4936. height: 1
  4937. } ) );
  4938. }
  4939. }
  4940. // Find the widest cell for each column and put it into the table
  4941. if ( oSettings.aoData.length ) {
  4942. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4943. columnIdx = visibleColumns[i];
  4944. column = columns[ columnIdx ];
  4945. $( _fnGetWidestNode( oSettings, columnIdx ) )
  4946. .clone( false )
  4947. .append( column.sContentPadding )
  4948. .appendTo( tr );
  4949. }
  4950. }
  4951. // Tidy the temporary table - remove name attributes so there aren't
  4952. // duplicated in the dom (radio elements for example)
  4953. $('[name]', tmpTable).removeAttr('name');
  4954. // Table has been built, attach to the document so we can work with it.
  4955. // A holding element is used, positioned at the top of the container
  4956. // with minimal height, so it has no effect on if the container scrolls
  4957. // or not. Otherwise it might trigger scrolling when it actually isn't
  4958. // needed
  4959. var holder = $('<div/>').css( scrollX || scrollY ?
  4960. {
  4961. position: 'absolute',
  4962. top: 0,
  4963. left: 0,
  4964. height: 1,
  4965. right: 0,
  4966. overflow: 'hidden'
  4967. } :
  4968. {}
  4969. )
  4970. .append( tmpTable )
  4971. .appendTo( tableContainer );
  4972. // When scrolling (X or Y) we want to set the width of the table as
  4973. // appropriate. However, when not scrolling leave the table width as it
  4974. // is. This results in slightly different, but I think correct behaviour
  4975. if ( scrollX && scrollXInner ) {
  4976. tmpTable.width( scrollXInner );
  4977. }
  4978. else if ( scrollX ) {
  4979. tmpTable.css( 'width', 'auto' );
  4980. tmpTable.removeAttr('width');
  4981. // If there is no width attribute or style, then allow the table to
  4982. // collapse
  4983. if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) {
  4984. tmpTable.width( tableContainer.clientWidth );
  4985. }
  4986. }
  4987. else if ( scrollY ) {
  4988. tmpTable.width( tableContainer.clientWidth );
  4989. }
  4990. else if ( tableWidthAttr ) {
  4991. tmpTable.width( tableWidthAttr );
  4992. }
  4993. // Get the width of each column in the constructed table - we need to
  4994. // know the inner width (so it can be assigned to the other table's
  4995. // cells) and the outer width so we can calculate the full width of the
  4996. // table. This is safe since DataTables requires a unique cell for each
  4997. // column, but if ever a header can span multiple columns, this will
  4998. // need to be modified.
  4999. var total = 0;
  5000. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  5001. var cell = $(headerCells[i]);
  5002. var border = cell.outerWidth() - cell.width();
  5003. // Use getBounding... where possible (not IE8-) because it can give
  5004. // sub-pixel accuracy, which we then want to round up!
  5005. var bounding = browser.bBounding ?
  5006. Math.ceil( headerCells[i].getBoundingClientRect().width ) :
  5007. cell.outerWidth();
  5008. // Total is tracked to remove any sub-pixel errors as the outerWidth
  5009. // of the table might not equal the total given here (IE!).
  5010. total += bounding;
  5011. // Width for each column to use
  5012. columns[ visibleColumns[i] ].sWidth = _fnStringToCss( bounding - border );
  5013. }
  5014. table.style.width = _fnStringToCss( total );
  5015. // Finished with the table - ditch it
  5016. holder.remove();
  5017. }
  5018. // If there is a width attr, we want to attach an event listener which
  5019. // allows the table sizing to automatically adjust when the window is
  5020. // resized. Use the width attr rather than CSS, since we can't know if the
  5021. // CSS is a relative value or absolute - DOM read is always px.
  5022. if ( tableWidthAttr ) {
  5023. table.style.width = _fnStringToCss( tableWidthAttr );
  5024. }
  5025. if ( (tableWidthAttr || scrollX) && ! oSettings._reszEvt ) {
  5026. var bindResize = function () {
  5027. $(window).on('resize.DT-'+oSettings.sInstance, _fnThrottle( function () {
  5028. _fnAdjustColumnSizing( oSettings );
  5029. } ) );
  5030. };
  5031. // IE6/7 will crash if we bind a resize event handler on page load.
  5032. // To be removed in 1.11 which drops IE6/7 support
  5033. if ( ie67 ) {
  5034. setTimeout( bindResize, 1000 );
  5035. }
  5036. else {
  5037. bindResize();
  5038. }
  5039. oSettings._reszEvt = true;
  5040. }
  5041. }
  5042. /**
  5043. * Throttle the calls to a function. Arguments and context are maintained for
  5044. * the throttled function
  5045. * @param {function} fn Function to be called
  5046. * @param {int} [freq=200] call frequency in mS
  5047. * @returns {function} wrapped function
  5048. * @memberof DataTable#oApi
  5049. */
  5050. var _fnThrottle = DataTable.util.throttle;
  5051. /**
  5052. * Convert a CSS unit width to pixels (e.g. 2em)
  5053. * @param {string} width width to be converted
  5054. * @param {node} parent parent to get the with for (required for relative widths) - optional
  5055. * @returns {int} width in pixels
  5056. * @memberof DataTable#oApi
  5057. */
  5058. function _fnConvertToWidth ( width, parent )
  5059. {
  5060. if ( ! width ) {
  5061. return 0;
  5062. }
  5063. var n = $('<div/>')
  5064. .css( 'width', _fnStringToCss( width ) )
  5065. .appendTo( parent || document.body );
  5066. var val = n[0].offsetWidth;
  5067. n.remove();
  5068. return val;
  5069. }
  5070. /**
  5071. * Get the widest node
  5072. * @param {object} settings dataTables settings object
  5073. * @param {int} colIdx column of interest
  5074. * @returns {node} widest table node
  5075. * @memberof DataTable#oApi
  5076. */
  5077. function _fnGetWidestNode( settings, colIdx )
  5078. {
  5079. var idx = _fnGetMaxLenString( settings, colIdx );
  5080. if ( idx < 0 ) {
  5081. return null;
  5082. }
  5083. var data = settings.aoData[ idx ];
  5084. return ! data.nTr ? // Might not have been created when deferred rendering
  5085. $('<td/>').html( _fnGetCellData( settings, idx, colIdx, 'display' ) )[0] :
  5086. data.anCells[ colIdx ];
  5087. }
  5088. /**
  5089. * Get the maximum strlen for each data column
  5090. * @param {object} settings dataTables settings object
  5091. * @param {int} colIdx column of interest
  5092. * @returns {string} max string length for each column
  5093. * @memberof DataTable#oApi
  5094. */
  5095. function _fnGetMaxLenString( settings, colIdx )
  5096. {
  5097. var s, max=-1, maxIdx = -1;
  5098. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5099. s = _fnGetCellData( settings, i, colIdx, 'display' )+'';
  5100. s = s.replace( __re_html_remove, '' );
  5101. s = s.replace( /&nbsp;/g, ' ' );
  5102. if ( s.length > max ) {
  5103. max = s.length;
  5104. maxIdx = i;
  5105. }
  5106. }
  5107. return maxIdx;
  5108. }
  5109. /**
  5110. * Append a CSS unit (only if required) to a string
  5111. * @param {string} value to css-ify
  5112. * @returns {string} value with css unit
  5113. * @memberof DataTable#oApi
  5114. */
  5115. function _fnStringToCss( s )
  5116. {
  5117. if ( s === null ) {
  5118. return '0px';
  5119. }
  5120. if ( typeof s == 'number' ) {
  5121. return s < 0 ?
  5122. '0px' :
  5123. s+'px';
  5124. }
  5125. // Check it has a unit character already
  5126. return s.match(/\d$/) ?
  5127. s+'px' :
  5128. s;
  5129. }
  5130. function _fnSortFlatten ( settings )
  5131. {
  5132. var
  5133. i, iLen, k, kLen,
  5134. aSort = [],
  5135. aiOrig = [],
  5136. aoColumns = settings.aoColumns,
  5137. aDataSort, iCol, sType, srcCol,
  5138. fixed = settings.aaSortingFixed,
  5139. fixedObj = $.isPlainObject( fixed ),
  5140. nestedSort = [],
  5141. add = function ( a ) {
  5142. if ( a.length && ! Array.isArray( a[0] ) ) {
  5143. // 1D array
  5144. nestedSort.push( a );
  5145. }
  5146. else {
  5147. // 2D array
  5148. $.merge( nestedSort, a );
  5149. }
  5150. };
  5151. // Build the sort array, with pre-fix and post-fix options if they have been
  5152. // specified
  5153. if ( Array.isArray( fixed ) ) {
  5154. add( fixed );
  5155. }
  5156. if ( fixedObj && fixed.pre ) {
  5157. add( fixed.pre );
  5158. }
  5159. add( settings.aaSorting );
  5160. if (fixedObj && fixed.post ) {
  5161. add( fixed.post );
  5162. }
  5163. for ( i=0 ; i<nestedSort.length ; i++ )
  5164. {
  5165. srcCol = nestedSort[i][0];
  5166. aDataSort = aoColumns[ srcCol ].aDataSort;
  5167. for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
  5168. {
  5169. iCol = aDataSort[k];
  5170. sType = aoColumns[ iCol ].sType || 'string';
  5171. if ( nestedSort[i]._idx === undefined ) {
  5172. nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting );
  5173. }
  5174. aSort.push( {
  5175. src: srcCol,
  5176. col: iCol,
  5177. dir: nestedSort[i][1],
  5178. index: nestedSort[i]._idx,
  5179. type: sType,
  5180. formatter: DataTable.ext.type.order[ sType+"-pre" ]
  5181. } );
  5182. }
  5183. }
  5184. return aSort;
  5185. }
  5186. /**
  5187. * Change the order of the table
  5188. * @param {object} oSettings dataTables settings object
  5189. * @memberof DataTable#oApi
  5190. * @todo This really needs split up!
  5191. */
  5192. function _fnSort ( oSettings )
  5193. {
  5194. var
  5195. i, ien, iLen, j, jLen, k, kLen,
  5196. sDataType, nTh,
  5197. aiOrig = [],
  5198. oExtSort = DataTable.ext.type.order,
  5199. aoData = oSettings.aoData,
  5200. aoColumns = oSettings.aoColumns,
  5201. aDataSort, data, iCol, sType, oSort,
  5202. formatters = 0,
  5203. sortCol,
  5204. displayMaster = oSettings.aiDisplayMaster,
  5205. aSort;
  5206. // Resolve any column types that are unknown due to addition or invalidation
  5207. // @todo Can this be moved into a 'data-ready' handler which is called when
  5208. // data is going to be used in the table?
  5209. _fnColumnTypes( oSettings );
  5210. aSort = _fnSortFlatten( oSettings );
  5211. for ( i=0, ien=aSort.length ; i<ien ; i++ ) {
  5212. sortCol = aSort[i];
  5213. // Track if we can use the fast sort algorithm
  5214. if ( sortCol.formatter ) {
  5215. formatters++;
  5216. }
  5217. // Load the data needed for the sort, for each cell
  5218. _fnSortData( oSettings, sortCol.col );
  5219. }
  5220. /* No sorting required if server-side or no sorting array */
  5221. if ( _fnDataSource( oSettings ) != 'ssp' && aSort.length !== 0 )
  5222. {
  5223. // Create a value - key array of the current row positions such that we can use their
  5224. // current position during the sort, if values match, in order to perform stable sorting
  5225. for ( i=0, iLen=displayMaster.length ; i<iLen ; i++ ) {
  5226. aiOrig[ displayMaster[i] ] = i;
  5227. }
  5228. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  5229. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  5230. * follow on it's own, but this is what we want (example two column sorting):
  5231. * fnLocalSorting = function(a,b){
  5232. * var iTest;
  5233. * iTest = oSort['string-asc']('data11', 'data12');
  5234. * if (iTest !== 0)
  5235. * return iTest;
  5236. * iTest = oSort['numeric-desc']('data21', 'data22');
  5237. * if (iTest !== 0)
  5238. * return iTest;
  5239. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  5240. * }
  5241. * Basically we have a test for each sorting column, if the data in that column is equal,
  5242. * test the next column. If all columns match, then we use a numeric sort on the row
  5243. * positions in the original data array to provide a stable sort.
  5244. *
  5245. * Note - I know it seems excessive to have two sorting methods, but the first is around
  5246. * 15% faster, so the second is only maintained for backwards compatibility with sorting
  5247. * methods which do not have a pre-sort formatting function.
  5248. */
  5249. if ( formatters === aSort.length ) {
  5250. // All sort types have formatting functions
  5251. displayMaster.sort( function ( a, b ) {
  5252. var
  5253. x, y, k, test, sort,
  5254. len=aSort.length,
  5255. dataA = aoData[a]._aSortData,
  5256. dataB = aoData[b]._aSortData;
  5257. for ( k=0 ; k<len ; k++ ) {
  5258. sort = aSort[k];
  5259. x = dataA[ sort.col ];
  5260. y = dataB[ sort.col ];
  5261. test = x<y ? -1 : x>y ? 1 : 0;
  5262. if ( test !== 0 ) {
  5263. return sort.dir === 'asc' ? test : -test;
  5264. }
  5265. }
  5266. x = aiOrig[a];
  5267. y = aiOrig[b];
  5268. return x<y ? -1 : x>y ? 1 : 0;
  5269. } );
  5270. }
  5271. else {
  5272. // Depreciated - remove in 1.11 (providing a plug-in option)
  5273. // Not all sort types have formatting methods, so we have to call their sorting
  5274. // methods.
  5275. displayMaster.sort( function ( a, b ) {
  5276. var
  5277. x, y, k, l, test, sort, fn,
  5278. len=aSort.length,
  5279. dataA = aoData[a]._aSortData,
  5280. dataB = aoData[b]._aSortData;
  5281. for ( k=0 ; k<len ; k++ ) {
  5282. sort = aSort[k];
  5283. x = dataA[ sort.col ];
  5284. y = dataB[ sort.col ];
  5285. fn = oExtSort[ sort.type+"-"+sort.dir ] || oExtSort[ "string-"+sort.dir ];
  5286. test = fn( x, y );
  5287. if ( test !== 0 ) {
  5288. return test;
  5289. }
  5290. }
  5291. x = aiOrig[a];
  5292. y = aiOrig[b];
  5293. return x<y ? -1 : x>y ? 1 : 0;
  5294. } );
  5295. }
  5296. }
  5297. /* Tell the draw function that we have sorted the data */
  5298. oSettings.bSorted = true;
  5299. }
  5300. function _fnSortAria ( settings )
  5301. {
  5302. var label;
  5303. var nextSort;
  5304. var columns = settings.aoColumns;
  5305. var aSort = _fnSortFlatten( settings );
  5306. var oAria = settings.oLanguage.oAria;
  5307. // ARIA attributes - need to loop all columns, to update all (removing old
  5308. // attributes as needed)
  5309. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  5310. {
  5311. var col = columns[i];
  5312. var asSorting = col.asSorting;
  5313. var sTitle = col.ariaTitle || col.sTitle.replace( /<.*?>/g, "" );
  5314. var th = col.nTh;
  5315. // IE7 is throwing an error when setting these properties with jQuery's
  5316. // attr() and removeAttr() methods...
  5317. th.removeAttribute('aria-sort');
  5318. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  5319. if ( col.bSortable ) {
  5320. if ( aSort.length > 0 && aSort[0].col == i ) {
  5321. th.setAttribute('aria-sort', aSort[0].dir=="asc" ? "ascending" : "descending" );
  5322. nextSort = asSorting[ aSort[0].index+1 ] || asSorting[0];
  5323. }
  5324. else {
  5325. nextSort = asSorting[0];
  5326. }
  5327. label = sTitle + ( nextSort === "asc" ?
  5328. oAria.sSortAscending :
  5329. oAria.sSortDescending
  5330. );
  5331. }
  5332. else {
  5333. label = sTitle;
  5334. }
  5335. th.setAttribute('aria-label', label);
  5336. }
  5337. }
  5338. /**
  5339. * Function to run on user sort request
  5340. * @param {object} settings dataTables settings object
  5341. * @param {node} attachTo node to attach the handler to
  5342. * @param {int} colIdx column sorting index
  5343. * @param {boolean} [append=false] Append the requested sort to the existing
  5344. * sort if true (i.e. multi-column sort)
  5345. * @param {function} [callback] callback function
  5346. * @memberof DataTable#oApi
  5347. */
  5348. function _fnSortListener ( settings, colIdx, append, callback )
  5349. {
  5350. var col = settings.aoColumns[ colIdx ];
  5351. var sorting = settings.aaSorting;
  5352. var asSorting = col.asSorting;
  5353. var nextSortIdx;
  5354. var next = function ( a, overflow ) {
  5355. var idx = a._idx;
  5356. if ( idx === undefined ) {
  5357. idx = $.inArray( a[1], asSorting );
  5358. }
  5359. return idx+1 < asSorting.length ?
  5360. idx+1 :
  5361. overflow ?
  5362. null :
  5363. 0;
  5364. };
  5365. // Convert to 2D array if needed
  5366. if ( typeof sorting[0] === 'number' ) {
  5367. sorting = settings.aaSorting = [ sorting ];
  5368. }
  5369. // If appending the sort then we are multi-column sorting
  5370. if ( append && settings.oFeatures.bSortMulti ) {
  5371. // Are we already doing some kind of sort on this column?
  5372. var sortIdx = $.inArray( colIdx, _pluck(sorting, '0') );
  5373. if ( sortIdx !== -1 ) {
  5374. // Yes, modify the sort
  5375. nextSortIdx = next( sorting[sortIdx], true );
  5376. if ( nextSortIdx === null && sorting.length === 1 ) {
  5377. nextSortIdx = 0; // can't remove sorting completely
  5378. }
  5379. if ( nextSortIdx === null ) {
  5380. sorting.splice( sortIdx, 1 );
  5381. }
  5382. else {
  5383. sorting[sortIdx][1] = asSorting[ nextSortIdx ];
  5384. sorting[sortIdx]._idx = nextSortIdx;
  5385. }
  5386. }
  5387. else {
  5388. // No sort on this column yet
  5389. sorting.push( [ colIdx, asSorting[0], 0 ] );
  5390. sorting[sorting.length-1]._idx = 0;
  5391. }
  5392. }
  5393. else if ( sorting.length && sorting[0][0] == colIdx ) {
  5394. // Single column - already sorting on this column, modify the sort
  5395. nextSortIdx = next( sorting[0] );
  5396. sorting.length = 1;
  5397. sorting[0][1] = asSorting[ nextSortIdx ];
  5398. sorting[0]._idx = nextSortIdx;
  5399. }
  5400. else {
  5401. // Single column - sort only on this column
  5402. sorting.length = 0;
  5403. sorting.push( [ colIdx, asSorting[0] ] );
  5404. sorting[0]._idx = 0;
  5405. }
  5406. // Run the sort by calling a full redraw
  5407. _fnReDraw( settings );
  5408. // callback used for async user interaction
  5409. if ( typeof callback == 'function' ) {
  5410. callback( settings );
  5411. }
  5412. }
  5413. /**
  5414. * Attach a sort handler (click) to a node
  5415. * @param {object} settings dataTables settings object
  5416. * @param {node} attachTo node to attach the handler to
  5417. * @param {int} colIdx column sorting index
  5418. * @param {function} [callback] callback function
  5419. * @memberof DataTable#oApi
  5420. */
  5421. function _fnSortAttachListener ( settings, attachTo, colIdx, callback )
  5422. {
  5423. var col = settings.aoColumns[ colIdx ];
  5424. _fnBindAction( attachTo, {}, function (e) {
  5425. /* If the column is not sortable - don't to anything */
  5426. if ( col.bSortable === false ) {
  5427. return;
  5428. }
  5429. // If processing is enabled use a timeout to allow the processing
  5430. // display to be shown - otherwise to it synchronously
  5431. if ( settings.oFeatures.bProcessing ) {
  5432. _fnProcessingDisplay( settings, true );
  5433. setTimeout( function() {
  5434. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5435. // In server-side processing, the draw callback will remove the
  5436. // processing display
  5437. if ( _fnDataSource( settings ) !== 'ssp' ) {
  5438. _fnProcessingDisplay( settings, false );
  5439. }
  5440. }, 0 );
  5441. }
  5442. else {
  5443. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5444. }
  5445. } );
  5446. }
  5447. /**
  5448. * Set the sorting classes on table's body, Note: it is safe to call this function
  5449. * when bSort and bSortClasses are false
  5450. * @param {object} oSettings dataTables settings object
  5451. * @memberof DataTable#oApi
  5452. */
  5453. function _fnSortingClasses( settings )
  5454. {
  5455. var oldSort = settings.aLastSort;
  5456. var sortClass = settings.oClasses.sSortColumn;
  5457. var sort = _fnSortFlatten( settings );
  5458. var features = settings.oFeatures;
  5459. var i, ien, colIdx;
  5460. if ( features.bSort && features.bSortClasses ) {
  5461. // Remove old sorting classes
  5462. for ( i=0, ien=oldSort.length ; i<ien ; i++ ) {
  5463. colIdx = oldSort[i].src;
  5464. // Remove column sorting
  5465. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5466. .removeClass( sortClass + (i<2 ? i+1 : 3) );
  5467. }
  5468. // Add new column sorting
  5469. for ( i=0, ien=sort.length ; i<ien ; i++ ) {
  5470. colIdx = sort[i].src;
  5471. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5472. .addClass( sortClass + (i<2 ? i+1 : 3) );
  5473. }
  5474. }
  5475. settings.aLastSort = sort;
  5476. }
  5477. // Get the data to sort a column, be it from cache, fresh (populating the
  5478. // cache), or from a sort formatter
  5479. function _fnSortData( settings, idx )
  5480. {
  5481. // Custom sorting function - provided by the sort data type
  5482. var column = settings.aoColumns[ idx ];
  5483. var customSort = DataTable.ext.order[ column.sSortDataType ];
  5484. var customData;
  5485. if ( customSort ) {
  5486. customData = customSort.call( settings.oInstance, settings, idx,
  5487. _fnColumnIndexToVisible( settings, idx )
  5488. );
  5489. }
  5490. // Use / populate cache
  5491. var row, cellData;
  5492. var formatter = DataTable.ext.type.order[ column.sType+"-pre" ];
  5493. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5494. row = settings.aoData[i];
  5495. if ( ! row._aSortData ) {
  5496. row._aSortData = [];
  5497. }
  5498. if ( ! row._aSortData[idx] || customSort ) {
  5499. cellData = customSort ?
  5500. customData[i] : // If there was a custom sort function, use data from there
  5501. _fnGetCellData( settings, i, idx, 'sort' );
  5502. row._aSortData[ idx ] = formatter ?
  5503. formatter( cellData ) :
  5504. cellData;
  5505. }
  5506. }
  5507. }
  5508. /**
  5509. * Save the state of a table
  5510. * @param {object} oSettings dataTables settings object
  5511. * @memberof DataTable#oApi
  5512. */
  5513. function _fnSaveState ( settings )
  5514. {
  5515. if (settings._bLoadingState) {
  5516. return;
  5517. }
  5518. /* Store the interesting variables */
  5519. var state = {
  5520. time: +new Date(),
  5521. start: settings._iDisplayStart,
  5522. length: settings._iDisplayLength,
  5523. order: $.extend( true, [], settings.aaSorting ),
  5524. search: _fnSearchToCamel( settings.oPreviousSearch ),
  5525. columns: $.map( settings.aoColumns, function ( col, i ) {
  5526. return {
  5527. visible: col.bVisible,
  5528. search: _fnSearchToCamel( settings.aoPreSearchCols[i] )
  5529. };
  5530. } )
  5531. };
  5532. settings.oSavedState = state;
  5533. _fnCallbackFire( settings, "aoStateSaveParams", 'stateSaveParams', [settings, state] );
  5534. if ( settings.oFeatures.bStateSave && !settings.bDestroying )
  5535. {
  5536. settings.fnStateSaveCallback.call( settings.oInstance, settings, state );
  5537. }
  5538. }
  5539. /**
  5540. * Attempt to load a saved table state
  5541. * @param {object} oSettings dataTables settings object
  5542. * @param {object} oInit DataTables init object so we can override settings
  5543. * @param {function} callback Callback to execute when the state has been loaded
  5544. * @memberof DataTable#oApi
  5545. */
  5546. function _fnLoadState ( settings, oInit, callback )
  5547. {
  5548. if ( ! settings.oFeatures.bStateSave ) {
  5549. callback();
  5550. return;
  5551. }
  5552. var loaded = function(state) {
  5553. _fnImplementState(settings, state, callback);
  5554. }
  5555. var state = settings.fnStateLoadCallback.call( settings.oInstance, settings, loaded );
  5556. if ( state !== undefined ) {
  5557. _fnImplementState( settings, state, callback );
  5558. }
  5559. // otherwise, wait for the loaded callback to be executed
  5560. return true;
  5561. }
  5562. function _fnImplementState ( settings, s, callback) {
  5563. var i, ien;
  5564. var columns = settings.aoColumns;
  5565. settings._bLoadingState = true;
  5566. // When StateRestore was introduced the state could now be implemented at any time
  5567. // Not just initialisation. To do this an api instance is required in some places
  5568. var api = settings._bInitComplete ? new DataTable.Api(settings) : null;
  5569. if ( ! s || ! s.time ) {
  5570. settings._bLoadingState = false;
  5571. callback();
  5572. return;
  5573. }
  5574. // Allow custom and plug-in manipulation functions to alter the saved data set and
  5575. // cancelling of loading by returning false
  5576. var abStateLoad = _fnCallbackFire( settings, 'aoStateLoadParams', 'stateLoadParams', [settings, s] );
  5577. if ( $.inArray( false, abStateLoad ) !== -1 ) {
  5578. settings._bLoadingState = false;
  5579. callback();
  5580. return;
  5581. }
  5582. // Reject old data
  5583. var duration = settings.iStateDuration;
  5584. if ( duration > 0 && s.time < +new Date() - (duration*1000) ) {
  5585. settings._bLoadingState = false;
  5586. callback();
  5587. return;
  5588. }
  5589. // Number of columns have changed - all bets are off, no restore of settings
  5590. if ( s.columns && columns.length !== s.columns.length ) {
  5591. settings._bLoadingState = false;
  5592. callback();
  5593. return;
  5594. }
  5595. // Store the saved state so it might be accessed at any time
  5596. settings.oLoadedState = $.extend( true, {}, s );
  5597. // Page Length
  5598. if ( s.length !== undefined ) {
  5599. // If already initialised just set the value directly so that the select element is also updated
  5600. if (api) {
  5601. api.page.len(s.length)
  5602. }
  5603. else {
  5604. settings._iDisplayLength = s.length;
  5605. }
  5606. }
  5607. // Restore key features - todo - for 1.11 this needs to be done by
  5608. // subscribed events
  5609. if ( s.start !== undefined ) {
  5610. if(api === null) {
  5611. settings._iDisplayStart = s.start;
  5612. settings.iInitDisplayStart = s.start;
  5613. }
  5614. else {
  5615. _fnPageChange(settings, s.start/settings._iDisplayLength);
  5616. }
  5617. }
  5618. // Order
  5619. if ( s.order !== undefined ) {
  5620. settings.aaSorting = [];
  5621. $.each( s.order, function ( i, col ) {
  5622. settings.aaSorting.push( col[0] >= columns.length ?
  5623. [ 0, col[1] ] :
  5624. col
  5625. );
  5626. } );
  5627. }
  5628. // Search
  5629. if ( s.search !== undefined ) {
  5630. $.extend( settings.oPreviousSearch, _fnSearchToHung( s.search ) );
  5631. }
  5632. // Columns
  5633. if ( s.columns ) {
  5634. for ( i=0, ien=s.columns.length ; i<ien ; i++ ) {
  5635. var col = s.columns[i];
  5636. // Visibility
  5637. if ( col.visible !== undefined ) {
  5638. // If the api is defined, the table has been initialised so we need to use it rather than internal settings
  5639. if (api) {
  5640. // Don't redraw the columns on every iteration of this loop, we will do this at the end instead
  5641. api.column(i).visible(col.visible, false);
  5642. }
  5643. else {
  5644. columns[i].bVisible = col.visible;
  5645. }
  5646. }
  5647. // Search
  5648. if ( col.search !== undefined ) {
  5649. $.extend( settings.aoPreSearchCols[i], _fnSearchToHung( col.search ) );
  5650. }
  5651. }
  5652. // If the api is defined then we need to adjust the columns once the visibility has been changed
  5653. if (api) {
  5654. api.columns.adjust();
  5655. }
  5656. }
  5657. settings._bLoadingState = false;
  5658. _fnCallbackFire( settings, 'aoStateLoaded', 'stateLoaded', [settings, s] );
  5659. callback();
  5660. };
  5661. /**
  5662. * Return the settings object for a particular table
  5663. * @param {node} table table we are using as a dataTable
  5664. * @returns {object} Settings object - or null if not found
  5665. * @memberof DataTable#oApi
  5666. */
  5667. function _fnSettingsFromNode ( table )
  5668. {
  5669. var settings = DataTable.settings;
  5670. var idx = $.inArray( table, _pluck( settings, 'nTable' ) );
  5671. return idx !== -1 ?
  5672. settings[ idx ] :
  5673. null;
  5674. }
  5675. /**
  5676. * Log an error message
  5677. * @param {object} settings dataTables settings object
  5678. * @param {int} level log error messages, or display them to the user
  5679. * @param {string} msg error message
  5680. * @param {int} tn Technical note id to get more information about the error.
  5681. * @memberof DataTable#oApi
  5682. */
  5683. function _fnLog( settings, level, msg, tn )
  5684. {
  5685. msg = 'DataTables warning: '+
  5686. (settings ? 'table id='+settings.sTableId+' - ' : '')+msg;
  5687. if ( tn ) {
  5688. msg += '. For more information about this error, please see '+
  5689. 'http://datatables.net/tn/'+tn;
  5690. }
  5691. if ( ! level ) {
  5692. // Backwards compatibility pre 1.10
  5693. var ext = DataTable.ext;
  5694. var type = ext.sErrMode || ext.errMode;
  5695. if ( settings ) {
  5696. _fnCallbackFire( settings, null, 'error', [ settings, tn, msg ] );
  5697. }
  5698. if ( type == 'alert' ) {
  5699. alert( msg );
  5700. }
  5701. else if ( type == 'throw' ) {
  5702. throw new Error(msg);
  5703. }
  5704. else if ( typeof type == 'function' ) {
  5705. type( settings, tn, msg );
  5706. }
  5707. }
  5708. else if ( window.console && console.log ) {
  5709. console.log( msg );
  5710. }
  5711. }
  5712. /**
  5713. * See if a property is defined on one object, if so assign it to the other object
  5714. * @param {object} ret target object
  5715. * @param {object} src source object
  5716. * @param {string} name property
  5717. * @param {string} [mappedName] name to map too - optional, name used if not given
  5718. * @memberof DataTable#oApi
  5719. */
  5720. function _fnMap( ret, src, name, mappedName )
  5721. {
  5722. if ( Array.isArray( name ) ) {
  5723. $.each( name, function (i, val) {
  5724. if ( Array.isArray( val ) ) {
  5725. _fnMap( ret, src, val[0], val[1] );
  5726. }
  5727. else {
  5728. _fnMap( ret, src, val );
  5729. }
  5730. } );
  5731. return;
  5732. }
  5733. if ( mappedName === undefined ) {
  5734. mappedName = name;
  5735. }
  5736. if ( src[name] !== undefined ) {
  5737. ret[mappedName] = src[name];
  5738. }
  5739. }
  5740. /**
  5741. * Extend objects - very similar to jQuery.extend, but deep copy objects, and
  5742. * shallow copy arrays. The reason we need to do this, is that we don't want to
  5743. * deep copy array init values (such as aaSorting) since the dev wouldn't be
  5744. * able to override them, but we do want to deep copy arrays.
  5745. * @param {object} out Object to extend
  5746. * @param {object} extender Object from which the properties will be applied to
  5747. * out
  5748. * @param {boolean} breakRefs If true, then arrays will be sliced to take an
  5749. * independent copy with the exception of the `data` or `aaData` parameters
  5750. * if they are present. This is so you can pass in a collection to
  5751. * DataTables and have that used as your data source without breaking the
  5752. * references
  5753. * @returns {object} out Reference, just for convenience - out === the return.
  5754. * @memberof DataTable#oApi
  5755. * @todo This doesn't take account of arrays inside the deep copied objects.
  5756. */
  5757. function _fnExtend( out, extender, breakRefs )
  5758. {
  5759. var val;
  5760. for ( var prop in extender ) {
  5761. if ( extender.hasOwnProperty(prop) ) {
  5762. val = extender[prop];
  5763. if ( $.isPlainObject( val ) ) {
  5764. if ( ! $.isPlainObject( out[prop] ) ) {
  5765. out[prop] = {};
  5766. }
  5767. $.extend( true, out[prop], val );
  5768. }
  5769. else if ( breakRefs && prop !== 'data' && prop !== 'aaData' && Array.isArray(val) ) {
  5770. out[prop] = val.slice();
  5771. }
  5772. else {
  5773. out[prop] = val;
  5774. }
  5775. }
  5776. }
  5777. return out;
  5778. }
  5779. /**
  5780. * Bind an event handers to allow a click or return key to activate the callback.
  5781. * This is good for accessibility since a return on the keyboard will have the
  5782. * same effect as a click, if the element has focus.
  5783. * @param {element} n Element to bind the action to
  5784. * @param {object} oData Data object to pass to the triggered function
  5785. * @param {function} fn Callback function for when the event is triggered
  5786. * @memberof DataTable#oApi
  5787. */
  5788. function _fnBindAction( n, oData, fn )
  5789. {
  5790. $(n)
  5791. .on( 'click.DT', oData, function (e) {
  5792. $(n).trigger('blur'); // Remove focus outline for mouse users
  5793. fn(e);
  5794. } )
  5795. .on( 'keypress.DT', oData, function (e){
  5796. if ( e.which === 13 ) {
  5797. e.preventDefault();
  5798. fn(e);
  5799. }
  5800. } )
  5801. .on( 'selectstart.DT', function () {
  5802. /* Take the brutal approach to cancelling text selection */
  5803. return false;
  5804. } );
  5805. }
  5806. /**
  5807. * Register a callback function. Easily allows a callback function to be added to
  5808. * an array store of callback functions that can then all be called together.
  5809. * @param {object} oSettings dataTables settings object
  5810. * @param {string} sStore Name of the array storage for the callbacks in oSettings
  5811. * @param {function} fn Function to be called back
  5812. * @param {string} sName Identifying name for the callback (i.e. a label)
  5813. * @memberof DataTable#oApi
  5814. */
  5815. function _fnCallbackReg( oSettings, sStore, fn, sName )
  5816. {
  5817. if ( fn )
  5818. {
  5819. oSettings[sStore].push( {
  5820. "fn": fn,
  5821. "sName": sName
  5822. } );
  5823. }
  5824. }
  5825. /**
  5826. * Fire callback functions and trigger events. Note that the loop over the
  5827. * callback array store is done backwards! Further note that you do not want to
  5828. * fire off triggers in time sensitive applications (for example cell creation)
  5829. * as its slow.
  5830. * @param {object} settings dataTables settings object
  5831. * @param {string} callbackArr Name of the array storage for the callbacks in
  5832. * oSettings
  5833. * @param {string} eventName Name of the jQuery custom event to trigger. If
  5834. * null no trigger is fired
  5835. * @param {array} args Array of arguments to pass to the callback function /
  5836. * trigger
  5837. * @memberof DataTable#oApi
  5838. */
  5839. function _fnCallbackFire( settings, callbackArr, eventName, args )
  5840. {
  5841. var ret = [];
  5842. if ( callbackArr ) {
  5843. ret = $.map( settings[callbackArr].slice().reverse(), function (val, i) {
  5844. return val.fn.apply( settings.oInstance, args );
  5845. } );
  5846. }
  5847. if ( eventName !== null ) {
  5848. var e = $.Event( eventName+'.dt' );
  5849. var table = $(settings.nTable);
  5850. table.trigger( e, args );
  5851. // If not yet attached to the document, trigger the event
  5852. // on the body directly to sort of simulate the bubble
  5853. if (table.parents('body').length === 0) {
  5854. $('body').trigger( e, args );
  5855. }
  5856. ret.push( e.result );
  5857. }
  5858. return ret;
  5859. }
  5860. function _fnLengthOverflow ( settings )
  5861. {
  5862. var
  5863. start = settings._iDisplayStart,
  5864. end = settings.fnDisplayEnd(),
  5865. len = settings._iDisplayLength;
  5866. /* If we have space to show extra rows (backing up from the end point - then do so */
  5867. if ( start >= end )
  5868. {
  5869. start = end - len;
  5870. }
  5871. // Keep the start record on the current page
  5872. start -= (start % len);
  5873. if ( len === -1 || start < 0 )
  5874. {
  5875. start = 0;
  5876. }
  5877. settings._iDisplayStart = start;
  5878. }
  5879. function _fnRenderer( settings, type )
  5880. {
  5881. var renderer = settings.renderer;
  5882. var host = DataTable.ext.renderer[type];
  5883. if ( $.isPlainObject( renderer ) && renderer[type] ) {
  5884. // Specific renderer for this type. If available use it, otherwise use
  5885. // the default.
  5886. return host[renderer[type]] || host._;
  5887. }
  5888. else if ( typeof renderer === 'string' ) {
  5889. // Common renderer - if there is one available for this type use it,
  5890. // otherwise use the default
  5891. return host[renderer] || host._;
  5892. }
  5893. // Use the default
  5894. return host._;
  5895. }
  5896. /**
  5897. * Detect the data source being used for the table. Used to simplify the code
  5898. * a little (ajax) and to make it compress a little smaller.
  5899. *
  5900. * @param {object} settings dataTables settings object
  5901. * @returns {string} Data source
  5902. * @memberof DataTable#oApi
  5903. */
  5904. function _fnDataSource ( settings )
  5905. {
  5906. if ( settings.oFeatures.bServerSide ) {
  5907. return 'ssp';
  5908. }
  5909. else if ( settings.ajax || settings.sAjaxSource ) {
  5910. return 'ajax';
  5911. }
  5912. return 'dom';
  5913. }
  5914. /**
  5915. * Computed structure of the DataTables API, defined by the options passed to
  5916. * `DataTable.Api.register()` when building the API.
  5917. *
  5918. * The structure is built in order to speed creation and extension of the Api
  5919. * objects since the extensions are effectively pre-parsed.
  5920. *
  5921. * The array is an array of objects with the following structure, where this
  5922. * base array represents the Api prototype base:
  5923. *
  5924. * [
  5925. * {
  5926. * name: 'data' -- string - Property name
  5927. * val: function () {}, -- function - Api method (or undefined if just an object
  5928. * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  5929. * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  5930. * },
  5931. * {
  5932. * name: 'row'
  5933. * val: {},
  5934. * methodExt: [ ... ],
  5935. * propExt: [
  5936. * {
  5937. * name: 'data'
  5938. * val: function () {},
  5939. * methodExt: [ ... ],
  5940. * propExt: [ ... ]
  5941. * },
  5942. * ...
  5943. * ]
  5944. * }
  5945. * ]
  5946. *
  5947. * @type {Array}
  5948. * @ignore
  5949. */
  5950. var __apiStruct = [];
  5951. /**
  5952. * `Array.prototype` reference.
  5953. *
  5954. * @type object
  5955. * @ignore
  5956. */
  5957. var __arrayProto = Array.prototype;
  5958. /**
  5959. * Abstraction for `context` parameter of the `Api` constructor to allow it to
  5960. * take several different forms for ease of use.
  5961. *
  5962. * Each of the input parameter types will be converted to a DataTables settings
  5963. * object where possible.
  5964. *
  5965. * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
  5966. * of:
  5967. *
  5968. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5969. * with be found and used.
  5970. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5971. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5972. * * `object` - DataTables settings object
  5973. * * `DataTables.Api` - API instance
  5974. * @return {array|null} Matching DataTables settings objects. `null` or
  5975. * `undefined` is returned if no matching DataTable is found.
  5976. * @ignore
  5977. */
  5978. var _toSettings = function ( mixed )
  5979. {
  5980. var idx, jq;
  5981. var settings = DataTable.settings;
  5982. var tables = $.map( settings, function (el, i) {
  5983. return el.nTable;
  5984. } );
  5985. if ( ! mixed ) {
  5986. return [];
  5987. }
  5988. else if ( mixed.nTable && mixed.oApi ) {
  5989. // DataTables settings object
  5990. return [ mixed ];
  5991. }
  5992. else if ( mixed.nodeName && mixed.nodeName.toLowerCase() === 'table' ) {
  5993. // Table node
  5994. idx = $.inArray( mixed, tables );
  5995. return idx !== -1 ? [ settings[idx] ] : null;
  5996. }
  5997. else if ( mixed && typeof mixed.settings === 'function' ) {
  5998. return mixed.settings().toArray();
  5999. }
  6000. else if ( typeof mixed === 'string' ) {
  6001. // jQuery selector
  6002. jq = $(mixed);
  6003. }
  6004. else if ( mixed instanceof $ ) {
  6005. // jQuery object (also DataTables instance)
  6006. jq = mixed;
  6007. }
  6008. if ( jq ) {
  6009. return jq.map( function(i) {
  6010. idx = $.inArray( this, tables );
  6011. return idx !== -1 ? settings[idx] : null;
  6012. } ).toArray();
  6013. }
  6014. };
  6015. /**
  6016. * DataTables API class - used to control and interface with one or more
  6017. * DataTables enhanced tables.
  6018. *
  6019. * The API class is heavily based on jQuery, presenting a chainable interface
  6020. * that you can use to interact with tables. Each instance of the API class has
  6021. * a "context" - i.e. the tables that it will operate on. This could be a single
  6022. * table, all tables on a page or a sub-set thereof.
  6023. *
  6024. * Additionally the API is designed to allow you to easily work with the data in
  6025. * the tables, retrieving and manipulating it as required. This is done by
  6026. * presenting the API class as an array like interface. The contents of the
  6027. * array depend upon the actions requested by each method (for example
  6028. * `rows().nodes()` will return an array of nodes, while `rows().data()` will
  6029. * return an array of objects or arrays depending upon your table's
  6030. * configuration). The API object has a number of array like methods (`push`,
  6031. * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
  6032. * `unique` etc) to assist your working with the data held in a table.
  6033. *
  6034. * Most methods (those which return an Api instance) are chainable, which means
  6035. * the return from a method call also has all of the methods available that the
  6036. * top level object had. For example, these two calls are equivalent:
  6037. *
  6038. * // Not chained
  6039. * api.row.add( {...} );
  6040. * api.draw();
  6041. *
  6042. * // Chained
  6043. * api.row.add( {...} ).draw();
  6044. *
  6045. * @class DataTable.Api
  6046. * @param {array|object|string|jQuery} context DataTable identifier. This is
  6047. * used to define which DataTables enhanced tables this API will operate on.
  6048. * Can be one of:
  6049. *
  6050. * * `string` - jQuery selector. Any DataTables' matching the given selector
  6051. * with be found and used.
  6052. * * `node` - `TABLE` node which has already been formed into a DataTable.
  6053. * * `jQuery` - A jQuery object of `TABLE` nodes.
  6054. * * `object` - DataTables settings object
  6055. * @param {array} [data] Data to initialise the Api instance with.
  6056. *
  6057. * @example
  6058. * // Direct initialisation during DataTables construction
  6059. * var api = $('#example').DataTable();
  6060. *
  6061. * @example
  6062. * // Initialisation using a DataTables jQuery object
  6063. * var api = $('#example').dataTable().api();
  6064. *
  6065. * @example
  6066. * // Initialisation as a constructor
  6067. * var api = new $.fn.DataTable.Api( 'table.dataTable' );
  6068. */
  6069. _Api = function ( context, data )
  6070. {
  6071. if ( ! (this instanceof _Api) ) {
  6072. return new _Api( context, data );
  6073. }
  6074. var settings = [];
  6075. var ctxSettings = function ( o ) {
  6076. var a = _toSettings( o );
  6077. if ( a ) {
  6078. settings.push.apply( settings, a );
  6079. }
  6080. };
  6081. if ( Array.isArray( context ) ) {
  6082. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  6083. ctxSettings( context[i] );
  6084. }
  6085. }
  6086. else {
  6087. ctxSettings( context );
  6088. }
  6089. // Remove duplicates
  6090. this.context = _unique( settings );
  6091. // Initial data
  6092. if ( data ) {
  6093. $.merge( this, data );
  6094. }
  6095. // selector
  6096. this.selector = {
  6097. rows: null,
  6098. cols: null,
  6099. opts: null
  6100. };
  6101. _Api.extend( this, this, __apiStruct );
  6102. };
  6103. DataTable.Api = _Api;
  6104. // Don't destroy the existing prototype, just extend it. Required for jQuery 2's
  6105. // isPlainObject.
  6106. $.extend( _Api.prototype, {
  6107. any: function ()
  6108. {
  6109. return this.count() !== 0;
  6110. },
  6111. concat: __arrayProto.concat,
  6112. context: [], // array of table settings objects
  6113. count: function ()
  6114. {
  6115. return this.flatten().length;
  6116. },
  6117. each: function ( fn )
  6118. {
  6119. for ( var i=0, ien=this.length ; i<ien; i++ ) {
  6120. fn.call( this, this[i], i, this );
  6121. }
  6122. return this;
  6123. },
  6124. eq: function ( idx )
  6125. {
  6126. var ctx = this.context;
  6127. return ctx.length > idx ?
  6128. new _Api( ctx[idx], this[idx] ) :
  6129. null;
  6130. },
  6131. filter: function ( fn )
  6132. {
  6133. var a = [];
  6134. if ( __arrayProto.filter ) {
  6135. a = __arrayProto.filter.call( this, fn, this );
  6136. }
  6137. else {
  6138. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6139. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  6140. if ( fn.call( this, this[i], i, this ) ) {
  6141. a.push( this[i] );
  6142. }
  6143. }
  6144. }
  6145. return new _Api( this.context, a );
  6146. },
  6147. flatten: function ()
  6148. {
  6149. var a = [];
  6150. return new _Api( this.context, a.concat.apply( a, this.toArray() ) );
  6151. },
  6152. join: __arrayProto.join,
  6153. indexOf: __arrayProto.indexOf || function (obj, start)
  6154. {
  6155. for ( var i=(start || 0), ien=this.length ; i<ien ; i++ ) {
  6156. if ( this[i] === obj ) {
  6157. return i;
  6158. }
  6159. }
  6160. return -1;
  6161. },
  6162. iterator: function ( flatten, type, fn, alwaysNew ) {
  6163. var
  6164. a = [], ret,
  6165. i, ien, j, jen,
  6166. context = this.context,
  6167. rows, items, item,
  6168. selector = this.selector;
  6169. // Argument shifting
  6170. if ( typeof flatten === 'string' ) {
  6171. alwaysNew = fn;
  6172. fn = type;
  6173. type = flatten;
  6174. flatten = false;
  6175. }
  6176. for ( i=0, ien=context.length ; i<ien ; i++ ) {
  6177. var apiInst = new _Api( context[i] );
  6178. if ( type === 'table' ) {
  6179. ret = fn.call( apiInst, context[i], i );
  6180. if ( ret !== undefined ) {
  6181. a.push( ret );
  6182. }
  6183. }
  6184. else if ( type === 'columns' || type === 'rows' ) {
  6185. // this has same length as context - one entry for each table
  6186. ret = fn.call( apiInst, context[i], this[i], i );
  6187. if ( ret !== undefined ) {
  6188. a.push( ret );
  6189. }
  6190. }
  6191. else if ( type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell' ) {
  6192. // columns and rows share the same structure.
  6193. // 'this' is an array of column indexes for each context
  6194. items = this[i];
  6195. if ( type === 'column-rows' ) {
  6196. rows = _selector_row_indexes( context[i], selector.opts );
  6197. }
  6198. for ( j=0, jen=items.length ; j<jen ; j++ ) {
  6199. item = items[j];
  6200. if ( type === 'cell' ) {
  6201. ret = fn.call( apiInst, context[i], item.row, item.column, i, j );
  6202. }
  6203. else {
  6204. ret = fn.call( apiInst, context[i], item, i, j, rows );
  6205. }
  6206. if ( ret !== undefined ) {
  6207. a.push( ret );
  6208. }
  6209. }
  6210. }
  6211. }
  6212. if ( a.length || alwaysNew ) {
  6213. var api = new _Api( context, flatten ? a.concat.apply( [], a ) : a );
  6214. var apiSelector = api.selector;
  6215. apiSelector.rows = selector.rows;
  6216. apiSelector.cols = selector.cols;
  6217. apiSelector.opts = selector.opts;
  6218. return api;
  6219. }
  6220. return this;
  6221. },
  6222. lastIndexOf: __arrayProto.lastIndexOf || function (obj, start)
  6223. {
  6224. // Bit cheeky...
  6225. return this.indexOf.apply( this.toArray.reverse(), arguments );
  6226. },
  6227. length: 0,
  6228. map: function ( fn )
  6229. {
  6230. var a = [];
  6231. if ( __arrayProto.map ) {
  6232. a = __arrayProto.map.call( this, fn, this );
  6233. }
  6234. else {
  6235. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6236. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  6237. a.push( fn.call( this, this[i], i ) );
  6238. }
  6239. }
  6240. return new _Api( this.context, a );
  6241. },
  6242. pluck: function ( prop )
  6243. {
  6244. var fn = DataTable.util.get(prop);
  6245. return this.map( function ( el ) {
  6246. return fn(el);
  6247. } );
  6248. },
  6249. pop: __arrayProto.pop,
  6250. push: __arrayProto.push,
  6251. // Does not return an API instance
  6252. reduce: __arrayProto.reduce || function ( fn, init )
  6253. {
  6254. return _fnReduce( this, fn, init, 0, this.length, 1 );
  6255. },
  6256. reduceRight: __arrayProto.reduceRight || function ( fn, init )
  6257. {
  6258. return _fnReduce( this, fn, init, this.length-1, -1, -1 );
  6259. },
  6260. reverse: __arrayProto.reverse,
  6261. // Object with rows, columns and opts
  6262. selector: null,
  6263. shift: __arrayProto.shift,
  6264. slice: function () {
  6265. return new _Api( this.context, this );
  6266. },
  6267. sort: __arrayProto.sort, // ? name - order?
  6268. splice: __arrayProto.splice,
  6269. toArray: function ()
  6270. {
  6271. return __arrayProto.slice.call( this );
  6272. },
  6273. to$: function ()
  6274. {
  6275. return $( this );
  6276. },
  6277. toJQuery: function ()
  6278. {
  6279. return $( this );
  6280. },
  6281. unique: function ()
  6282. {
  6283. return new _Api( this.context, _unique(this) );
  6284. },
  6285. unshift: __arrayProto.unshift
  6286. } );
  6287. _Api.extend = function ( scope, obj, ext )
  6288. {
  6289. // Only extend API instances and static properties of the API
  6290. if ( ! ext.length || ! obj || ( ! (obj instanceof _Api) && ! obj.__dt_wrapper ) ) {
  6291. return;
  6292. }
  6293. var
  6294. i, ien,
  6295. struct,
  6296. methodScoping = function ( scope, fn, struc ) {
  6297. return function () {
  6298. var ret = fn.apply( scope, arguments );
  6299. // Method extension
  6300. _Api.extend( ret, ret, struc.methodExt );
  6301. return ret;
  6302. };
  6303. };
  6304. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6305. struct = ext[i];
  6306. // Value
  6307. obj[ struct.name ] = struct.type === 'function' ?
  6308. methodScoping( scope, struct.val, struct ) :
  6309. struct.type === 'object' ?
  6310. {} :
  6311. struct.val;
  6312. obj[ struct.name ].__dt_wrapper = true;
  6313. // Property extension
  6314. _Api.extend( scope, obj[ struct.name ], struct.propExt );
  6315. }
  6316. };
  6317. // @todo - Is there need for an augment function?
  6318. // _Api.augment = function ( inst, name )
  6319. // {
  6320. // // Find src object in the structure from the name
  6321. // var parts = name.split('.');
  6322. // _Api.extend( inst, obj );
  6323. // };
  6324. // [
  6325. // {
  6326. // name: 'data' -- string - Property name
  6327. // val: function () {}, -- function - Api method (or undefined if just an object
  6328. // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  6329. // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  6330. // },
  6331. // {
  6332. // name: 'row'
  6333. // val: {},
  6334. // methodExt: [ ... ],
  6335. // propExt: [
  6336. // {
  6337. // name: 'data'
  6338. // val: function () {},
  6339. // methodExt: [ ... ],
  6340. // propExt: [ ... ]
  6341. // },
  6342. // ...
  6343. // ]
  6344. // }
  6345. // ]
  6346. _Api.register = _api_register = function ( name, val )
  6347. {
  6348. if ( Array.isArray( name ) ) {
  6349. for ( var j=0, jen=name.length ; j<jen ; j++ ) {
  6350. _Api.register( name[j], val );
  6351. }
  6352. return;
  6353. }
  6354. var
  6355. i, ien,
  6356. heir = name.split('.'),
  6357. struct = __apiStruct,
  6358. key, method;
  6359. var find = function ( src, name ) {
  6360. for ( var i=0, ien=src.length ; i<ien ; i++ ) {
  6361. if ( src[i].name === name ) {
  6362. return src[i];
  6363. }
  6364. }
  6365. return null;
  6366. };
  6367. for ( i=0, ien=heir.length ; i<ien ; i++ ) {
  6368. method = heir[i].indexOf('()') !== -1;
  6369. key = method ?
  6370. heir[i].replace('()', '') :
  6371. heir[i];
  6372. var src = find( struct, key );
  6373. if ( ! src ) {
  6374. src = {
  6375. name: key,
  6376. val: {},
  6377. methodExt: [],
  6378. propExt: [],
  6379. type: 'object'
  6380. };
  6381. struct.push( src );
  6382. }
  6383. if ( i === ien-1 ) {
  6384. src.val = val;
  6385. src.type = typeof val === 'function' ?
  6386. 'function' :
  6387. $.isPlainObject( val ) ?
  6388. 'object' :
  6389. 'other';
  6390. }
  6391. else {
  6392. struct = method ?
  6393. src.methodExt :
  6394. src.propExt;
  6395. }
  6396. }
  6397. };
  6398. _Api.registerPlural = _api_registerPlural = function ( pluralName, singularName, val ) {
  6399. _Api.register( pluralName, val );
  6400. _Api.register( singularName, function () {
  6401. var ret = val.apply( this, arguments );
  6402. if ( ret === this ) {
  6403. // Returned item is the API instance that was passed in, return it
  6404. return this;
  6405. }
  6406. else if ( ret instanceof _Api ) {
  6407. // New API instance returned, want the value from the first item
  6408. // in the returned array for the singular result.
  6409. return ret.length ?
  6410. Array.isArray( ret[0] ) ?
  6411. new _Api( ret.context, ret[0] ) : // Array results are 'enhanced'
  6412. ret[0] :
  6413. undefined;
  6414. }
  6415. // Non-API return - just fire it back
  6416. return ret;
  6417. } );
  6418. };
  6419. /**
  6420. * Selector for HTML tables. Apply the given selector to the give array of
  6421. * DataTables settings objects.
  6422. *
  6423. * @param {string|integer} [selector] jQuery selector string or integer
  6424. * @param {array} Array of DataTables settings objects to be filtered
  6425. * @return {array}
  6426. * @ignore
  6427. */
  6428. var __table_selector = function ( selector, a )
  6429. {
  6430. if ( Array.isArray(selector) ) {
  6431. return $.map( selector, function (item) {
  6432. return __table_selector(item, a);
  6433. } );
  6434. }
  6435. // Integer is used to pick out a table by index
  6436. if ( typeof selector === 'number' ) {
  6437. return [ a[ selector ] ];
  6438. }
  6439. // Perform a jQuery selector on the table nodes
  6440. var nodes = $.map( a, function (el, i) {
  6441. return el.nTable;
  6442. } );
  6443. return $(nodes)
  6444. .filter( selector )
  6445. .map( function (i) {
  6446. // Need to translate back from the table node to the settings
  6447. var idx = $.inArray( this, nodes );
  6448. return a[ idx ];
  6449. } )
  6450. .toArray();
  6451. };
  6452. /**
  6453. * Context selector for the API's context (i.e. the tables the API instance
  6454. * refers to.
  6455. *
  6456. * @name DataTable.Api#tables
  6457. * @param {string|integer} [selector] Selector to pick which tables the iterator
  6458. * should operate on. If not given, all tables in the current context are
  6459. * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
  6460. * select multiple tables or as an integer to select a single table.
  6461. * @returns {DataTable.Api} Returns a new API instance if a selector is given.
  6462. */
  6463. _api_register( 'tables()', function ( selector ) {
  6464. // A new instance is created if there was a selector specified
  6465. return selector !== undefined && selector !== null ?
  6466. new _Api( __table_selector( selector, this.context ) ) :
  6467. this;
  6468. } );
  6469. _api_register( 'table()', function ( selector ) {
  6470. var tables = this.tables( selector );
  6471. var ctx = tables.context;
  6472. // Truncate to the first matched table
  6473. return ctx.length ?
  6474. new _Api( ctx[0] ) :
  6475. tables;
  6476. } );
  6477. _api_registerPlural( 'tables().nodes()', 'table().node()' , function () {
  6478. return this.iterator( 'table', function ( ctx ) {
  6479. return ctx.nTable;
  6480. }, 1 );
  6481. } );
  6482. _api_registerPlural( 'tables().body()', 'table().body()' , function () {
  6483. return this.iterator( 'table', function ( ctx ) {
  6484. return ctx.nTBody;
  6485. }, 1 );
  6486. } );
  6487. _api_registerPlural( 'tables().header()', 'table().header()' , function () {
  6488. return this.iterator( 'table', function ( ctx ) {
  6489. return ctx.nTHead;
  6490. }, 1 );
  6491. } );
  6492. _api_registerPlural( 'tables().footer()', 'table().footer()' , function () {
  6493. return this.iterator( 'table', function ( ctx ) {
  6494. return ctx.nTFoot;
  6495. }, 1 );
  6496. } );
  6497. _api_registerPlural( 'tables().containers()', 'table().container()' , function () {
  6498. return this.iterator( 'table', function ( ctx ) {
  6499. return ctx.nTableWrapper;
  6500. }, 1 );
  6501. } );
  6502. /**
  6503. * Redraw the tables in the current context.
  6504. */
  6505. _api_register( 'draw()', function ( paging ) {
  6506. return this.iterator( 'table', function ( settings ) {
  6507. if ( paging === 'page' ) {
  6508. _fnDraw( settings );
  6509. }
  6510. else {
  6511. if ( typeof paging === 'string' ) {
  6512. paging = paging === 'full-hold' ?
  6513. false :
  6514. true;
  6515. }
  6516. _fnReDraw( settings, paging===false );
  6517. }
  6518. } );
  6519. } );
  6520. /**
  6521. * Get the current page index.
  6522. *
  6523. * @return {integer} Current page index (zero based)
  6524. *//**
  6525. * Set the current page.
  6526. *
  6527. * Note that if you attempt to show a page which does not exist, DataTables will
  6528. * not throw an error, but rather reset the paging.
  6529. *
  6530. * @param {integer|string} action The paging action to take. This can be one of:
  6531. * * `integer` - The page index to jump to
  6532. * * `string` - An action to take:
  6533. * * `first` - Jump to first page.
  6534. * * `next` - Jump to the next page
  6535. * * `previous` - Jump to previous page
  6536. * * `last` - Jump to the last page.
  6537. * @returns {DataTables.Api} this
  6538. */
  6539. _api_register( 'page()', function ( action ) {
  6540. if ( action === undefined ) {
  6541. return this.page.info().page; // not an expensive call
  6542. }
  6543. // else, have an action to take on all tables
  6544. return this.iterator( 'table', function ( settings ) {
  6545. _fnPageChange( settings, action );
  6546. } );
  6547. } );
  6548. /**
  6549. * Paging information for the first table in the current context.
  6550. *
  6551. * If you require paging information for another table, use the `table()` method
  6552. * with a suitable selector.
  6553. *
  6554. * @return {object} Object with the following properties set:
  6555. * * `page` - Current page index (zero based - i.e. the first page is `0`)
  6556. * * `pages` - Total number of pages
  6557. * * `start` - Display index for the first record shown on the current page
  6558. * * `end` - Display index for the last record shown on the current page
  6559. * * `length` - Display length (number of records). Note that generally `start
  6560. * + length = end`, but this is not always true, for example if there are
  6561. * only 2 records to show on the final page, with a length of 10.
  6562. * * `recordsTotal` - Full data set length
  6563. * * `recordsDisplay` - Data set length once the current filtering criterion
  6564. * are applied.
  6565. */
  6566. _api_register( 'page.info()', function ( action ) {
  6567. if ( this.context.length === 0 ) {
  6568. return undefined;
  6569. }
  6570. var
  6571. settings = this.context[0],
  6572. start = settings._iDisplayStart,
  6573. len = settings.oFeatures.bPaginate ? settings._iDisplayLength : -1,
  6574. visRecords = settings.fnRecordsDisplay(),
  6575. all = len === -1;
  6576. return {
  6577. "page": all ? 0 : Math.floor( start / len ),
  6578. "pages": all ? 1 : Math.ceil( visRecords / len ),
  6579. "start": start,
  6580. "end": settings.fnDisplayEnd(),
  6581. "length": len,
  6582. "recordsTotal": settings.fnRecordsTotal(),
  6583. "recordsDisplay": visRecords,
  6584. "serverSide": _fnDataSource( settings ) === 'ssp'
  6585. };
  6586. } );
  6587. /**
  6588. * Get the current page length.
  6589. *
  6590. * @return {integer} Current page length. Note `-1` indicates that all records
  6591. * are to be shown.
  6592. *//**
  6593. * Set the current page length.
  6594. *
  6595. * @param {integer} Page length to set. Use `-1` to show all records.
  6596. * @returns {DataTables.Api} this
  6597. */
  6598. _api_register( 'page.len()', function ( len ) {
  6599. // Note that we can't call this function 'length()' because `length`
  6600. // is a Javascript property of functions which defines how many arguments
  6601. // the function expects.
  6602. if ( len === undefined ) {
  6603. return this.context.length !== 0 ?
  6604. this.context[0]._iDisplayLength :
  6605. undefined;
  6606. }
  6607. // else, set the page length
  6608. return this.iterator( 'table', function ( settings ) {
  6609. _fnLengthChange( settings, len );
  6610. } );
  6611. } );
  6612. var __reload = function ( settings, holdPosition, callback ) {
  6613. // Use the draw event to trigger a callback
  6614. if ( callback ) {
  6615. var api = new _Api( settings );
  6616. api.one( 'draw', function () {
  6617. callback( api.ajax.json() );
  6618. } );
  6619. }
  6620. if ( _fnDataSource( settings ) == 'ssp' ) {
  6621. _fnReDraw( settings, holdPosition );
  6622. }
  6623. else {
  6624. _fnProcessingDisplay( settings, true );
  6625. // Cancel an existing request
  6626. var xhr = settings.jqXHR;
  6627. if ( xhr && xhr.readyState !== 4 ) {
  6628. xhr.abort();
  6629. }
  6630. // Trigger xhr
  6631. _fnBuildAjax( settings, [], function( json ) {
  6632. _fnClearTable( settings );
  6633. var data = _fnAjaxDataSrc( settings, json );
  6634. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  6635. _fnAddData( settings, data[i] );
  6636. }
  6637. _fnReDraw( settings, holdPosition );
  6638. _fnProcessingDisplay( settings, false );
  6639. } );
  6640. }
  6641. };
  6642. /**
  6643. * Get the JSON response from the last Ajax request that DataTables made to the
  6644. * server. Note that this returns the JSON from the first table in the current
  6645. * context.
  6646. *
  6647. * @return {object} JSON received from the server.
  6648. */
  6649. _api_register( 'ajax.json()', function () {
  6650. var ctx = this.context;
  6651. if ( ctx.length > 0 ) {
  6652. return ctx[0].json;
  6653. }
  6654. // else return undefined;
  6655. } );
  6656. /**
  6657. * Get the data submitted in the last Ajax request
  6658. */
  6659. _api_register( 'ajax.params()', function () {
  6660. var ctx = this.context;
  6661. if ( ctx.length > 0 ) {
  6662. return ctx[0].oAjaxData;
  6663. }
  6664. // else return undefined;
  6665. } );
  6666. /**
  6667. * Reload tables from the Ajax data source. Note that this function will
  6668. * automatically re-draw the table when the remote data has been loaded.
  6669. *
  6670. * @param {boolean} [reset=true] Reset (default) or hold the current paging
  6671. * position. A full re-sort and re-filter is performed when this method is
  6672. * called, which is why the pagination reset is the default action.
  6673. * @returns {DataTables.Api} this
  6674. */
  6675. _api_register( 'ajax.reload()', function ( callback, resetPaging ) {
  6676. return this.iterator( 'table', function (settings) {
  6677. __reload( settings, resetPaging===false, callback );
  6678. } );
  6679. } );
  6680. /**
  6681. * Get the current Ajax URL. Note that this returns the URL from the first
  6682. * table in the current context.
  6683. *
  6684. * @return {string} Current Ajax source URL
  6685. *//**
  6686. * Set the Ajax URL. Note that this will set the URL for all tables in the
  6687. * current context.
  6688. *
  6689. * @param {string} url URL to set.
  6690. * @returns {DataTables.Api} this
  6691. */
  6692. _api_register( 'ajax.url()', function ( url ) {
  6693. var ctx = this.context;
  6694. if ( url === undefined ) {
  6695. // get
  6696. if ( ctx.length === 0 ) {
  6697. return undefined;
  6698. }
  6699. ctx = ctx[0];
  6700. return ctx.ajax ?
  6701. $.isPlainObject( ctx.ajax ) ?
  6702. ctx.ajax.url :
  6703. ctx.ajax :
  6704. ctx.sAjaxSource;
  6705. }
  6706. // set
  6707. return this.iterator( 'table', function ( settings ) {
  6708. if ( $.isPlainObject( settings.ajax ) ) {
  6709. settings.ajax.url = url;
  6710. }
  6711. else {
  6712. settings.ajax = url;
  6713. }
  6714. // No need to consider sAjaxSource here since DataTables gives priority
  6715. // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
  6716. // value of `sAjaxSource` redundant.
  6717. } );
  6718. } );
  6719. /**
  6720. * Load data from the newly set Ajax URL. Note that this method is only
  6721. * available when `ajax.url()` is used to set a URL. Additionally, this method
  6722. * has the same effect as calling `ajax.reload()` but is provided for
  6723. * convenience when setting a new URL. Like `ajax.reload()` it will
  6724. * automatically redraw the table once the remote data has been loaded.
  6725. *
  6726. * @returns {DataTables.Api} this
  6727. */
  6728. _api_register( 'ajax.url().load()', function ( callback, resetPaging ) {
  6729. // Same as a reload, but makes sense to present it for easy access after a
  6730. // url change
  6731. return this.iterator( 'table', function ( ctx ) {
  6732. __reload( ctx, resetPaging===false, callback );
  6733. } );
  6734. } );
  6735. var _selector_run = function ( type, selector, selectFn, settings, opts )
  6736. {
  6737. var
  6738. out = [], res,
  6739. a, i, ien, j, jen,
  6740. selectorType = typeof selector;
  6741. // Can't just check for isArray here, as an API or jQuery instance might be
  6742. // given with their array like look
  6743. if ( ! selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined ) {
  6744. selector = [ selector ];
  6745. }
  6746. for ( i=0, ien=selector.length ; i<ien ; i++ ) {
  6747. // Only split on simple strings - complex expressions will be jQuery selectors
  6748. a = selector[i] && selector[i].split && ! selector[i].match(/[\[\(:]/) ?
  6749. selector[i].split(',') :
  6750. [ selector[i] ];
  6751. for ( j=0, jen=a.length ; j<jen ; j++ ) {
  6752. res = selectFn( typeof a[j] === 'string' ? (a[j]).trim() : a[j] );
  6753. if ( res && res.length ) {
  6754. out = out.concat( res );
  6755. }
  6756. }
  6757. }
  6758. // selector extensions
  6759. var ext = _ext.selector[ type ];
  6760. if ( ext.length ) {
  6761. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6762. out = ext[i]( settings, opts, out );
  6763. }
  6764. }
  6765. return _unique( out );
  6766. };
  6767. var _selector_opts = function ( opts )
  6768. {
  6769. if ( ! opts ) {
  6770. opts = {};
  6771. }
  6772. // Backwards compatibility for 1.9- which used the terminology filter rather
  6773. // than search
  6774. if ( opts.filter && opts.search === undefined ) {
  6775. opts.search = opts.filter;
  6776. }
  6777. return $.extend( {
  6778. search: 'none',
  6779. order: 'current',
  6780. page: 'all'
  6781. }, opts );
  6782. };
  6783. var _selector_first = function ( inst )
  6784. {
  6785. // Reduce the API instance to the first item found
  6786. for ( var i=0, ien=inst.length ; i<ien ; i++ ) {
  6787. if ( inst[i].length > 0 ) {
  6788. // Assign the first element to the first item in the instance
  6789. // and truncate the instance and context
  6790. inst[0] = inst[i];
  6791. inst[0].length = 1;
  6792. inst.length = 1;
  6793. inst.context = [ inst.context[i] ];
  6794. return inst;
  6795. }
  6796. }
  6797. // Not found - return an empty instance
  6798. inst.length = 0;
  6799. return inst;
  6800. };
  6801. var _selector_row_indexes = function ( settings, opts )
  6802. {
  6803. var
  6804. i, ien, tmp, a=[],
  6805. displayFiltered = settings.aiDisplay,
  6806. displayMaster = settings.aiDisplayMaster;
  6807. var
  6808. search = opts.search, // none, applied, removed
  6809. order = opts.order, // applied, current, index (original - compatibility with 1.9)
  6810. page = opts.page; // all, current
  6811. if ( _fnDataSource( settings ) == 'ssp' ) {
  6812. // In server-side processing mode, most options are irrelevant since
  6813. // rows not shown don't exist and the index order is the applied order
  6814. // Removed is a special case - for consistency just return an empty
  6815. // array
  6816. return search === 'removed' ?
  6817. [] :
  6818. _range( 0, displayMaster.length );
  6819. }
  6820. else if ( page == 'current' ) {
  6821. // Current page implies that order=current and filter=applied, since it is
  6822. // fairly senseless otherwise, regardless of what order and search actually
  6823. // are
  6824. for ( i=settings._iDisplayStart, ien=settings.fnDisplayEnd() ; i<ien ; i++ ) {
  6825. a.push( displayFiltered[i] );
  6826. }
  6827. }
  6828. else if ( order == 'current' || order == 'applied' ) {
  6829. if ( search == 'none') {
  6830. a = displayMaster.slice();
  6831. }
  6832. else if ( search == 'applied' ) {
  6833. a = displayFiltered.slice();
  6834. }
  6835. else if ( search == 'removed' ) {
  6836. // O(n+m) solution by creating a hash map
  6837. var displayFilteredMap = {};
  6838. for ( var i=0, ien=displayFiltered.length ; i<ien ; i++ ) {
  6839. displayFilteredMap[displayFiltered[i]] = null;
  6840. }
  6841. a = $.map( displayMaster, function (el) {
  6842. return ! displayFilteredMap.hasOwnProperty(el) ?
  6843. el :
  6844. null;
  6845. } );
  6846. }
  6847. }
  6848. else if ( order == 'index' || order == 'original' ) {
  6849. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  6850. if ( search == 'none' ) {
  6851. a.push( i );
  6852. }
  6853. else { // applied | removed
  6854. tmp = $.inArray( i, displayFiltered );
  6855. if ((tmp === -1 && search == 'removed') ||
  6856. (tmp >= 0 && search == 'applied') )
  6857. {
  6858. a.push( i );
  6859. }
  6860. }
  6861. }
  6862. }
  6863. return a;
  6864. };
  6865. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  6866. * Rows
  6867. *
  6868. * {} - no selector - use all available rows
  6869. * {integer} - row aoData index
  6870. * {node} - TR node
  6871. * {string} - jQuery selector to apply to the TR elements
  6872. * {array} - jQuery array of nodes, or simply an array of TR nodes
  6873. *
  6874. */
  6875. var __row_selector = function ( settings, selector, opts )
  6876. {
  6877. var rows;
  6878. var run = function ( sel ) {
  6879. var selInt = _intVal( sel );
  6880. var i, ien;
  6881. var aoData = settings.aoData;
  6882. // Short cut - selector is a number and no options provided (default is
  6883. // all records, so no need to check if the index is in there, since it
  6884. // must be - dev error if the index doesn't exist).
  6885. if ( selInt !== null && ! opts ) {
  6886. return [ selInt ];
  6887. }
  6888. if ( ! rows ) {
  6889. rows = _selector_row_indexes( settings, opts );
  6890. }
  6891. if ( selInt !== null && $.inArray( selInt, rows ) !== -1 ) {
  6892. // Selector - integer
  6893. return [ selInt ];
  6894. }
  6895. else if ( sel === null || sel === undefined || sel === '' ) {
  6896. // Selector - none
  6897. return rows;
  6898. }
  6899. // Selector - function
  6900. if ( typeof sel === 'function' ) {
  6901. return $.map( rows, function (idx) {
  6902. var row = aoData[ idx ];
  6903. return sel( idx, row._aData, row.nTr ) ? idx : null;
  6904. } );
  6905. }
  6906. // Selector - node
  6907. if ( sel.nodeName ) {
  6908. var rowIdx = sel._DT_RowIndex; // Property added by DT for fast lookup
  6909. var cellIdx = sel._DT_CellIndex;
  6910. if ( rowIdx !== undefined ) {
  6911. // Make sure that the row is actually still present in the table
  6912. return aoData[ rowIdx ] && aoData[ rowIdx ].nTr === sel ?
  6913. [ rowIdx ] :
  6914. [];
  6915. }
  6916. else if ( cellIdx ) {
  6917. return aoData[ cellIdx.row ] && aoData[ cellIdx.row ].nTr === sel.parentNode ?
  6918. [ cellIdx.row ] :
  6919. [];
  6920. }
  6921. else {
  6922. var host = $(sel).closest('*[data-dt-row]');
  6923. return host.length ?
  6924. [ host.data('dt-row') ] :
  6925. [];
  6926. }
  6927. }
  6928. // ID selector. Want to always be able to select rows by id, regardless
  6929. // of if the tr element has been created or not, so can't rely upon
  6930. // jQuery here - hence a custom implementation. This does not match
  6931. // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
  6932. // but to select it using a CSS selector engine (like Sizzle or
  6933. // querySelect) it would need to need to be escaped for some characters.
  6934. // DataTables simplifies this for row selectors since you can select
  6935. // only a row. A # indicates an id any anything that follows is the id -
  6936. // unescaped.
  6937. if ( typeof sel === 'string' && sel.charAt(0) === '#' ) {
  6938. // get row index from id
  6939. var rowObj = settings.aIds[ sel.replace( /^#/, '' ) ];
  6940. if ( rowObj !== undefined ) {
  6941. return [ rowObj.idx ];
  6942. }
  6943. // need to fall through to jQuery in case there is DOM id that
  6944. // matches
  6945. }
  6946. // Get nodes in the order from the `rows` array with null values removed
  6947. var nodes = _removeEmpty(
  6948. _pluck_order( settings.aoData, rows, 'nTr' )
  6949. );
  6950. // Selector - jQuery selector string, array of nodes or jQuery object/
  6951. // As jQuery's .filter() allows jQuery objects to be passed in filter,
  6952. // it also allows arrays, so this will cope with all three options
  6953. return $(nodes)
  6954. .filter( sel )
  6955. .map( function () {
  6956. return this._DT_RowIndex;
  6957. } )
  6958. .toArray();
  6959. };
  6960. return _selector_run( 'row', selector, run, settings, opts );
  6961. };
  6962. _api_register( 'rows()', function ( selector, opts ) {
  6963. // argument shifting
  6964. if ( selector === undefined ) {
  6965. selector = '';
  6966. }
  6967. else if ( $.isPlainObject( selector ) ) {
  6968. opts = selector;
  6969. selector = '';
  6970. }
  6971. opts = _selector_opts( opts );
  6972. var inst = this.iterator( 'table', function ( settings ) {
  6973. return __row_selector( settings, selector, opts );
  6974. }, 1 );
  6975. // Want argument shifting here and in __row_selector?
  6976. inst.selector.rows = selector;
  6977. inst.selector.opts = opts;
  6978. return inst;
  6979. } );
  6980. _api_register( 'rows().nodes()', function () {
  6981. return this.iterator( 'row', function ( settings, row ) {
  6982. return settings.aoData[ row ].nTr || undefined;
  6983. }, 1 );
  6984. } );
  6985. _api_register( 'rows().data()', function () {
  6986. return this.iterator( true, 'rows', function ( settings, rows ) {
  6987. return _pluck_order( settings.aoData, rows, '_aData' );
  6988. }, 1 );
  6989. } );
  6990. _api_registerPlural( 'rows().cache()', 'row().cache()', function ( type ) {
  6991. return this.iterator( 'row', function ( settings, row ) {
  6992. var r = settings.aoData[ row ];
  6993. return type === 'search' ? r._aFilterData : r._aSortData;
  6994. }, 1 );
  6995. } );
  6996. _api_registerPlural( 'rows().invalidate()', 'row().invalidate()', function ( src ) {
  6997. return this.iterator( 'row', function ( settings, row ) {
  6998. _fnInvalidate( settings, row, src );
  6999. } );
  7000. } );
  7001. _api_registerPlural( 'rows().indexes()', 'row().index()', function () {
  7002. return this.iterator( 'row', function ( settings, row ) {
  7003. return row;
  7004. }, 1 );
  7005. } );
  7006. _api_registerPlural( 'rows().ids()', 'row().id()', function ( hash ) {
  7007. var a = [];
  7008. var context = this.context;
  7009. // `iterator` will drop undefined values, but in this case we want them
  7010. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  7011. for ( var j=0, jen=this[i].length ; j<jen ; j++ ) {
  7012. var id = context[i].rowIdFn( context[i].aoData[ this[i][j] ]._aData );
  7013. a.push( (hash === true ? '#' : '' )+ id );
  7014. }
  7015. }
  7016. return new _Api( context, a );
  7017. } );
  7018. _api_registerPlural( 'rows().remove()', 'row().remove()', function () {
  7019. var that = this;
  7020. this.iterator( 'row', function ( settings, row, thatIdx ) {
  7021. var data = settings.aoData;
  7022. var rowData = data[ row ];
  7023. var i, ien, j, jen;
  7024. var loopRow, loopCells;
  7025. data.splice( row, 1 );
  7026. // Update the cached indexes
  7027. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  7028. loopRow = data[i];
  7029. loopCells = loopRow.anCells;
  7030. // Rows
  7031. if ( loopRow.nTr !== null ) {
  7032. loopRow.nTr._DT_RowIndex = i;
  7033. }
  7034. // Cells
  7035. if ( loopCells !== null ) {
  7036. for ( j=0, jen=loopCells.length ; j<jen ; j++ ) {
  7037. loopCells[j]._DT_CellIndex.row = i;
  7038. }
  7039. }
  7040. }
  7041. // Delete from the display arrays
  7042. _fnDeleteIndex( settings.aiDisplayMaster, row );
  7043. _fnDeleteIndex( settings.aiDisplay, row );
  7044. _fnDeleteIndex( that[ thatIdx ], row, false ); // maintain local indexes
  7045. // For server-side processing tables - subtract the deleted row from the count
  7046. if ( settings._iRecordsDisplay > 0 ) {
  7047. settings._iRecordsDisplay--;
  7048. }
  7049. // Check for an 'overflow' they case for displaying the table
  7050. _fnLengthOverflow( settings );
  7051. // Remove the row's ID reference if there is one
  7052. var id = settings.rowIdFn( rowData._aData );
  7053. if ( id !== undefined ) {
  7054. delete settings.aIds[ id ];
  7055. }
  7056. } );
  7057. this.iterator( 'table', function ( settings ) {
  7058. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  7059. settings.aoData[i].idx = i;
  7060. }
  7061. } );
  7062. return this;
  7063. } );
  7064. _api_register( 'rows.add()', function ( rows ) {
  7065. var newRows = this.iterator( 'table', function ( settings ) {
  7066. var row, i, ien;
  7067. var out = [];
  7068. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  7069. row = rows[i];
  7070. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  7071. out.push( _fnAddTr( settings, row )[0] );
  7072. }
  7073. else {
  7074. out.push( _fnAddData( settings, row ) );
  7075. }
  7076. }
  7077. return out;
  7078. }, 1 );
  7079. // Return an Api.rows() extended instance, so rows().nodes() etc can be used
  7080. var modRows = this.rows( -1 );
  7081. modRows.pop();
  7082. $.merge( modRows, newRows );
  7083. return modRows;
  7084. } );
  7085. /**
  7086. *
  7087. */
  7088. _api_register( 'row()', function ( selector, opts ) {
  7089. return _selector_first( this.rows( selector, opts ) );
  7090. } );
  7091. _api_register( 'row().data()', function ( data ) {
  7092. var ctx = this.context;
  7093. if ( data === undefined ) {
  7094. // Get
  7095. return ctx.length && this.length ?
  7096. ctx[0].aoData[ this[0] ]._aData :
  7097. undefined;
  7098. }
  7099. // Set
  7100. var row = ctx[0].aoData[ this[0] ];
  7101. row._aData = data;
  7102. // If the DOM has an id, and the data source is an array
  7103. if ( Array.isArray( data ) && row.nTr && row.nTr.id ) {
  7104. _fnSetObjectDataFn( ctx[0].rowId )( data, row.nTr.id );
  7105. }
  7106. // Automatically invalidate
  7107. _fnInvalidate( ctx[0], this[0], 'data' );
  7108. return this;
  7109. } );
  7110. _api_register( 'row().node()', function () {
  7111. var ctx = this.context;
  7112. return ctx.length && this.length ?
  7113. ctx[0].aoData[ this[0] ].nTr || null :
  7114. null;
  7115. } );
  7116. _api_register( 'row.add()', function ( row ) {
  7117. // Allow a jQuery object to be passed in - only a single row is added from
  7118. // it though - the first element in the set
  7119. if ( row instanceof $ && row.length ) {
  7120. row = row[0];
  7121. }
  7122. var rows = this.iterator( 'table', function ( settings ) {
  7123. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  7124. return _fnAddTr( settings, row )[0];
  7125. }
  7126. return _fnAddData( settings, row );
  7127. } );
  7128. // Return an Api.rows() extended instance, with the newly added row selected
  7129. return this.row( rows[0] );
  7130. } );
  7131. $(document).on('plugin-init.dt', function (e, context) {
  7132. var api = new _Api( context );
  7133. var namespace = 'on-plugin-init';
  7134. var stateSaveParamsEvent = 'stateSaveParams.' + namespace;
  7135. var destroyEvent = 'destroy. ' + namespace;
  7136. api.on( stateSaveParamsEvent, function ( e, settings, d ) {
  7137. // This could be more compact with the API, but it is a lot faster as a simple
  7138. // internal loop
  7139. var idFn = settings.rowIdFn;
  7140. var data = settings.aoData;
  7141. var ids = [];
  7142. for (var i=0 ; i<data.length ; i++) {
  7143. if (data[i]._detailsShow) {
  7144. ids.push( '#' + idFn(data[i]._aData) );
  7145. }
  7146. }
  7147. d.childRows = ids;
  7148. });
  7149. api.on( destroyEvent, function () {
  7150. api.off(stateSaveParamsEvent + ' ' + destroyEvent);
  7151. });
  7152. var loaded = api.state.loaded();
  7153. if ( loaded && loaded.childRows ) {
  7154. api
  7155. .rows( $.map(loaded.childRows, function (id){
  7156. return id.replace(/:/g, '\\:')
  7157. }) )
  7158. .every( function () {
  7159. _fnCallbackFire( context, null, 'requestChild', [ this ] )
  7160. });
  7161. }
  7162. });
  7163. var __details_add = function ( ctx, row, data, klass )
  7164. {
  7165. // Convert to array of TR elements
  7166. var rows = [];
  7167. var addRow = function ( r, k ) {
  7168. // Recursion to allow for arrays of jQuery objects
  7169. if ( Array.isArray( r ) || r instanceof $ ) {
  7170. for ( var i=0, ien=r.length ; i<ien ; i++ ) {
  7171. addRow( r[i], k );
  7172. }
  7173. return;
  7174. }
  7175. // If we get a TR element, then just add it directly - up to the dev
  7176. // to add the correct number of columns etc
  7177. if ( r.nodeName && r.nodeName.toLowerCase() === 'tr' ) {
  7178. rows.push( r );
  7179. }
  7180. else {
  7181. // Otherwise create a row with a wrapper
  7182. var created = $('<tr><td></td></tr>').addClass( k );
  7183. $('td', created)
  7184. .addClass( k )
  7185. .html( r )
  7186. [0].colSpan = _fnVisbleColumns( ctx );
  7187. rows.push( created[0] );
  7188. }
  7189. };
  7190. addRow( data, klass );
  7191. if ( row._details ) {
  7192. row._details.detach();
  7193. }
  7194. row._details = $(rows);
  7195. // If the children were already shown, that state should be retained
  7196. if ( row._detailsShow ) {
  7197. row._details.insertAfter( row.nTr );
  7198. }
  7199. };
  7200. // Make state saving of child row details async to allow them to be batch processed
  7201. var __details_state = DataTable.util.throttle(
  7202. function (ctx) {
  7203. _fnSaveState( ctx[0] )
  7204. },
  7205. 500
  7206. );
  7207. var __details_remove = function ( api, idx )
  7208. {
  7209. var ctx = api.context;
  7210. if ( ctx.length ) {
  7211. var row = ctx[0].aoData[ idx !== undefined ? idx : api[0] ];
  7212. if ( row && row._details ) {
  7213. row._details.remove();
  7214. row._detailsShow = undefined;
  7215. row._details = undefined;
  7216. $( row.nTr ).removeClass( 'dt-hasChild' );
  7217. __details_state( ctx );
  7218. }
  7219. }
  7220. };
  7221. var __details_display = function ( api, show ) {
  7222. var ctx = api.context;
  7223. if ( ctx.length && api.length ) {
  7224. var row = ctx[0].aoData[ api[0] ];
  7225. if ( row._details ) {
  7226. row._detailsShow = show;
  7227. if ( show ) {
  7228. row._details.insertAfter( row.nTr );
  7229. $( row.nTr ).addClass( 'dt-hasChild' );
  7230. }
  7231. else {
  7232. row._details.detach();
  7233. $( row.nTr ).removeClass( 'dt-hasChild' );
  7234. }
  7235. _fnCallbackFire( ctx[0], null, 'childRow', [ show, api.row( api[0] ) ] )
  7236. __details_events( ctx[0] );
  7237. __details_state( ctx );
  7238. }
  7239. }
  7240. };
  7241. var __details_events = function ( settings )
  7242. {
  7243. var api = new _Api( settings );
  7244. var namespace = '.dt.DT_details';
  7245. var drawEvent = 'draw'+namespace;
  7246. var colvisEvent = 'column-sizing'+namespace;
  7247. var destroyEvent = 'destroy'+namespace;
  7248. var data = settings.aoData;
  7249. api.off( drawEvent +' '+ colvisEvent +' '+ destroyEvent );
  7250. if ( _pluck( data, '_details' ).length > 0 ) {
  7251. // On each draw, insert the required elements into the document
  7252. api.on( drawEvent, function ( e, ctx ) {
  7253. if ( settings !== ctx ) {
  7254. return;
  7255. }
  7256. api.rows( {page:'current'} ).eq(0).each( function (idx) {
  7257. // Internal data grab
  7258. var row = data[ idx ];
  7259. if ( row._detailsShow ) {
  7260. row._details.insertAfter( row.nTr );
  7261. }
  7262. } );
  7263. } );
  7264. // Column visibility change - update the colspan
  7265. api.on( colvisEvent, function ( e, ctx, idx, vis ) {
  7266. if ( settings !== ctx ) {
  7267. return;
  7268. }
  7269. // Update the colspan for the details rows (note, only if it already has
  7270. // a colspan)
  7271. var row, visible = _fnVisbleColumns( ctx );
  7272. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7273. row = data[i];
  7274. if ( row._details ) {
  7275. row._details.children('td[colspan]').attr('colspan', visible );
  7276. }
  7277. }
  7278. } );
  7279. // Table destroyed - nuke any child rows
  7280. api.on( destroyEvent, function ( e, ctx ) {
  7281. if ( settings !== ctx ) {
  7282. return;
  7283. }
  7284. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7285. if ( data[i]._details ) {
  7286. __details_remove( api, i );
  7287. }
  7288. }
  7289. } );
  7290. }
  7291. };
  7292. // Strings for the method names to help minification
  7293. var _emp = '';
  7294. var _child_obj = _emp+'row().child';
  7295. var _child_mth = _child_obj+'()';
  7296. // data can be:
  7297. // tr
  7298. // string
  7299. // jQuery or array of any of the above
  7300. _api_register( _child_mth, function ( data, klass ) {
  7301. var ctx = this.context;
  7302. if ( data === undefined ) {
  7303. // get
  7304. return ctx.length && this.length ?
  7305. ctx[0].aoData[ this[0] ]._details :
  7306. undefined;
  7307. }
  7308. else if ( data === true ) {
  7309. // show
  7310. this.child.show();
  7311. }
  7312. else if ( data === false ) {
  7313. // remove
  7314. __details_remove( this );
  7315. }
  7316. else if ( ctx.length && this.length ) {
  7317. // set
  7318. __details_add( ctx[0], ctx[0].aoData[ this[0] ], data, klass );
  7319. }
  7320. return this;
  7321. } );
  7322. _api_register( [
  7323. _child_obj+'.show()',
  7324. _child_mth+'.show()' // only when `child()` was called with parameters (without
  7325. ], function ( show ) { // it returns an object and this method is not executed)
  7326. __details_display( this, true );
  7327. return this;
  7328. } );
  7329. _api_register( [
  7330. _child_obj+'.hide()',
  7331. _child_mth+'.hide()' // only when `child()` was called with parameters (without
  7332. ], function () { // it returns an object and this method is not executed)
  7333. __details_display( this, false );
  7334. return this;
  7335. } );
  7336. _api_register( [
  7337. _child_obj+'.remove()',
  7338. _child_mth+'.remove()' // only when `child()` was called with parameters (without
  7339. ], function () { // it returns an object and this method is not executed)
  7340. __details_remove( this );
  7341. return this;
  7342. } );
  7343. _api_register( _child_obj+'.isShown()', function () {
  7344. var ctx = this.context;
  7345. if ( ctx.length && this.length ) {
  7346. // _detailsShown as false or undefined will fall through to return false
  7347. return ctx[0].aoData[ this[0] ]._detailsShow || false;
  7348. }
  7349. return false;
  7350. } );
  7351. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7352. * Columns
  7353. *
  7354. * {integer} - column index (>=0 count from left, <0 count from right)
  7355. * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
  7356. * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
  7357. * "{string}:name" - column name
  7358. * "{string}" - jQuery selector on column header nodes
  7359. *
  7360. */
  7361. // can be an array of these items, comma separated list, or an array of comma
  7362. // separated lists
  7363. var __re_column_selector = /^([^:]+):(name|visIdx|visible)$/;
  7364. // r1 and r2 are redundant - but it means that the parameters match for the
  7365. // iterator callback in columns().data()
  7366. var __columnData = function ( settings, column, r1, r2, rows ) {
  7367. var a = [];
  7368. for ( var row=0, ien=rows.length ; row<ien ; row++ ) {
  7369. a.push( _fnGetCellData( settings, rows[row], column ) );
  7370. }
  7371. return a;
  7372. };
  7373. var __column_selector = function ( settings, selector, opts )
  7374. {
  7375. var
  7376. columns = settings.aoColumns,
  7377. names = _pluck( columns, 'sName' ),
  7378. nodes = _pluck( columns, 'nTh' );
  7379. var run = function ( s ) {
  7380. var selInt = _intVal( s );
  7381. // Selector - all
  7382. if ( s === '' ) {
  7383. return _range( columns.length );
  7384. }
  7385. // Selector - index
  7386. if ( selInt !== null ) {
  7387. return [ selInt >= 0 ?
  7388. selInt : // Count from left
  7389. columns.length + selInt // Count from right (+ because its a negative value)
  7390. ];
  7391. }
  7392. // Selector = function
  7393. if ( typeof s === 'function' ) {
  7394. var rows = _selector_row_indexes( settings, opts );
  7395. return $.map( columns, function (col, idx) {
  7396. return s(
  7397. idx,
  7398. __columnData( settings, idx, 0, 0, rows ),
  7399. nodes[ idx ]
  7400. ) ? idx : null;
  7401. } );
  7402. }
  7403. // jQuery or string selector
  7404. var match = typeof s === 'string' ?
  7405. s.match( __re_column_selector ) :
  7406. '';
  7407. if ( match ) {
  7408. switch( match[2] ) {
  7409. case 'visIdx':
  7410. case 'visible':
  7411. var idx = parseInt( match[1], 10 );
  7412. // Visible index given, convert to column index
  7413. if ( idx < 0 ) {
  7414. // Counting from the right
  7415. var visColumns = $.map( columns, function (col,i) {
  7416. return col.bVisible ? i : null;
  7417. } );
  7418. return [ visColumns[ visColumns.length + idx ] ];
  7419. }
  7420. // Counting from the left
  7421. return [ _fnVisibleToColumnIndex( settings, idx ) ];
  7422. case 'name':
  7423. // match by name. `names` is column index complete and in order
  7424. return $.map( names, function (name, i) {
  7425. return name === match[1] ? i : null;
  7426. } );
  7427. default:
  7428. return [];
  7429. }
  7430. }
  7431. // Cell in the table body
  7432. if ( s.nodeName && s._DT_CellIndex ) {
  7433. return [ s._DT_CellIndex.column ];
  7434. }
  7435. // jQuery selector on the TH elements for the columns
  7436. var jqResult = $( nodes )
  7437. .filter( s )
  7438. .map( function () {
  7439. return $.inArray( this, nodes ); // `nodes` is column index complete and in order
  7440. } )
  7441. .toArray();
  7442. if ( jqResult.length || ! s.nodeName ) {
  7443. return jqResult;
  7444. }
  7445. // Otherwise a node which might have a `dt-column` data attribute, or be
  7446. // a child or such an element
  7447. var host = $(s).closest('*[data-dt-column]');
  7448. return host.length ?
  7449. [ host.data('dt-column') ] :
  7450. [];
  7451. };
  7452. return _selector_run( 'column', selector, run, settings, opts );
  7453. };
  7454. var __setColumnVis = function ( settings, column, vis ) {
  7455. var
  7456. cols = settings.aoColumns,
  7457. col = cols[ column ],
  7458. data = settings.aoData,
  7459. row, cells, i, ien, tr;
  7460. // Get
  7461. if ( vis === undefined ) {
  7462. return col.bVisible;
  7463. }
  7464. // Set
  7465. // No change
  7466. if ( col.bVisible === vis ) {
  7467. return;
  7468. }
  7469. if ( vis ) {
  7470. // Insert column
  7471. // Need to decide if we should use appendChild or insertBefore
  7472. var insertBefore = $.inArray( true, _pluck(cols, 'bVisible'), column+1 );
  7473. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  7474. tr = data[i].nTr;
  7475. cells = data[i].anCells;
  7476. if ( tr ) {
  7477. // insertBefore can act like appendChild if 2nd arg is null
  7478. tr.insertBefore( cells[ column ], cells[ insertBefore ] || null );
  7479. }
  7480. }
  7481. }
  7482. else {
  7483. // Remove column
  7484. $( _pluck( settings.aoData, 'anCells', column ) ).detach();
  7485. }
  7486. // Common actions
  7487. col.bVisible = vis;
  7488. };
  7489. _api_register( 'columns()', function ( selector, opts ) {
  7490. // argument shifting
  7491. if ( selector === undefined ) {
  7492. selector = '';
  7493. }
  7494. else if ( $.isPlainObject( selector ) ) {
  7495. opts = selector;
  7496. selector = '';
  7497. }
  7498. opts = _selector_opts( opts );
  7499. var inst = this.iterator( 'table', function ( settings ) {
  7500. return __column_selector( settings, selector, opts );
  7501. }, 1 );
  7502. // Want argument shifting here and in _row_selector?
  7503. inst.selector.cols = selector;
  7504. inst.selector.opts = opts;
  7505. return inst;
  7506. } );
  7507. _api_registerPlural( 'columns().header()', 'column().header()', function ( selector, opts ) {
  7508. return this.iterator( 'column', function ( settings, column ) {
  7509. return settings.aoColumns[column].nTh;
  7510. }, 1 );
  7511. } );
  7512. _api_registerPlural( 'columns().footer()', 'column().footer()', function ( selector, opts ) {
  7513. return this.iterator( 'column', function ( settings, column ) {
  7514. return settings.aoColumns[column].nTf;
  7515. }, 1 );
  7516. } );
  7517. _api_registerPlural( 'columns().data()', 'column().data()', function () {
  7518. return this.iterator( 'column-rows', __columnData, 1 );
  7519. } );
  7520. _api_registerPlural( 'columns().dataSrc()', 'column().dataSrc()', function () {
  7521. return this.iterator( 'column', function ( settings, column ) {
  7522. return settings.aoColumns[column].mData;
  7523. }, 1 );
  7524. } );
  7525. _api_registerPlural( 'columns().cache()', 'column().cache()', function ( type ) {
  7526. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7527. return _pluck_order( settings.aoData, rows,
  7528. type === 'search' ? '_aFilterData' : '_aSortData', column
  7529. );
  7530. }, 1 );
  7531. } );
  7532. _api_registerPlural( 'columns().nodes()', 'column().nodes()', function () {
  7533. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7534. return _pluck_order( settings.aoData, rows, 'anCells', column ) ;
  7535. }, 1 );
  7536. } );
  7537. _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis, calc ) {
  7538. var that = this;
  7539. var ret = this.iterator( 'column', function ( settings, column ) {
  7540. if ( vis === undefined ) {
  7541. return settings.aoColumns[ column ].bVisible;
  7542. } // else
  7543. __setColumnVis( settings, column, vis );
  7544. } );
  7545. // Group the column visibility changes
  7546. if ( vis !== undefined ) {
  7547. this.iterator( 'table', function ( settings ) {
  7548. // Redraw the header after changes
  7549. _fnDrawHead( settings, settings.aoHeader );
  7550. _fnDrawHead( settings, settings.aoFooter );
  7551. // Update colspan for no records display. Child rows and extensions will use their own
  7552. // listeners to do this - only need to update the empty table item here
  7553. if ( ! settings.aiDisplay.length ) {
  7554. $(settings.nTBody).find('td[colspan]').attr('colspan', _fnVisbleColumns(settings));
  7555. }
  7556. _fnSaveState( settings );
  7557. // Second loop once the first is done for events
  7558. that.iterator( 'column', function ( settings, column ) {
  7559. _fnCallbackFire( settings, null, 'column-visibility', [settings, column, vis, calc] );
  7560. } );
  7561. if ( calc === undefined || calc ) {
  7562. that.columns.adjust();
  7563. }
  7564. });
  7565. }
  7566. return ret;
  7567. } );
  7568. _api_registerPlural( 'columns().indexes()', 'column().index()', function ( type ) {
  7569. return this.iterator( 'column', function ( settings, column ) {
  7570. return type === 'visible' ?
  7571. _fnColumnIndexToVisible( settings, column ) :
  7572. column;
  7573. }, 1 );
  7574. } );
  7575. _api_register( 'columns.adjust()', function () {
  7576. return this.iterator( 'table', function ( settings ) {
  7577. _fnAdjustColumnSizing( settings );
  7578. }, 1 );
  7579. } );
  7580. _api_register( 'column.index()', function ( type, idx ) {
  7581. if ( this.context.length !== 0 ) {
  7582. var ctx = this.context[0];
  7583. if ( type === 'fromVisible' || type === 'toData' ) {
  7584. return _fnVisibleToColumnIndex( ctx, idx );
  7585. }
  7586. else if ( type === 'fromData' || type === 'toVisible' ) {
  7587. return _fnColumnIndexToVisible( ctx, idx );
  7588. }
  7589. }
  7590. } );
  7591. _api_register( 'column()', function ( selector, opts ) {
  7592. return _selector_first( this.columns( selector, opts ) );
  7593. } );
  7594. var __cell_selector = function ( settings, selector, opts )
  7595. {
  7596. var data = settings.aoData;
  7597. var rows = _selector_row_indexes( settings, opts );
  7598. var cells = _removeEmpty( _pluck_order( data, rows, 'anCells' ) );
  7599. var allCells = $(_flatten( [], cells ));
  7600. var row;
  7601. var columns = settings.aoColumns.length;
  7602. var a, i, ien, j, o, host;
  7603. var run = function ( s ) {
  7604. var fnSelector = typeof s === 'function';
  7605. if ( s === null || s === undefined || fnSelector ) {
  7606. // All cells and function selectors
  7607. a = [];
  7608. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  7609. row = rows[i];
  7610. for ( j=0 ; j<columns ; j++ ) {
  7611. o = {
  7612. row: row,
  7613. column: j
  7614. };
  7615. if ( fnSelector ) {
  7616. // Selector - function
  7617. host = data[ row ];
  7618. if ( s( o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null ) ) {
  7619. a.push( o );
  7620. }
  7621. }
  7622. else {
  7623. // Selector - all
  7624. a.push( o );
  7625. }
  7626. }
  7627. }
  7628. return a;
  7629. }
  7630. // Selector - index
  7631. if ( $.isPlainObject( s ) ) {
  7632. // Valid cell index and its in the array of selectable rows
  7633. return s.column !== undefined && s.row !== undefined && $.inArray( s.row, rows ) !== -1 ?
  7634. [s] :
  7635. [];
  7636. }
  7637. // Selector - jQuery filtered cells
  7638. var jqResult = allCells
  7639. .filter( s )
  7640. .map( function (i, el) {
  7641. return { // use a new object, in case someone changes the values
  7642. row: el._DT_CellIndex.row,
  7643. column: el._DT_CellIndex.column
  7644. };
  7645. } )
  7646. .toArray();
  7647. if ( jqResult.length || ! s.nodeName ) {
  7648. return jqResult;
  7649. }
  7650. // Otherwise the selector is a node, and there is one last option - the
  7651. // element might be a child of an element which has dt-row and dt-column
  7652. // data attributes
  7653. host = $(s).closest('*[data-dt-row]');
  7654. return host.length ?
  7655. [ {
  7656. row: host.data('dt-row'),
  7657. column: host.data('dt-column')
  7658. } ] :
  7659. [];
  7660. };
  7661. return _selector_run( 'cell', selector, run, settings, opts );
  7662. };
  7663. _api_register( 'cells()', function ( rowSelector, columnSelector, opts ) {
  7664. // Argument shifting
  7665. if ( $.isPlainObject( rowSelector ) ) {
  7666. // Indexes
  7667. if ( rowSelector.row === undefined ) {
  7668. // Selector options in first parameter
  7669. opts = rowSelector;
  7670. rowSelector = null;
  7671. }
  7672. else {
  7673. // Cell index objects in first parameter
  7674. opts = columnSelector;
  7675. columnSelector = null;
  7676. }
  7677. }
  7678. if ( $.isPlainObject( columnSelector ) ) {
  7679. opts = columnSelector;
  7680. columnSelector = null;
  7681. }
  7682. // Cell selector
  7683. if ( columnSelector === null || columnSelector === undefined ) {
  7684. return this.iterator( 'table', function ( settings ) {
  7685. return __cell_selector( settings, rowSelector, _selector_opts( opts ) );
  7686. } );
  7687. }
  7688. // The default built in options need to apply to row and columns
  7689. var internalOpts = opts ? {
  7690. page: opts.page,
  7691. order: opts.order,
  7692. search: opts.search
  7693. } : {};
  7694. // Row + column selector
  7695. var columns = this.columns( columnSelector, internalOpts );
  7696. var rows = this.rows( rowSelector, internalOpts );
  7697. var i, ien, j, jen;
  7698. var cellsNoOpts = this.iterator( 'table', function ( settings, idx ) {
  7699. var a = [];
  7700. for ( i=0, ien=rows[idx].length ; i<ien ; i++ ) {
  7701. for ( j=0, jen=columns[idx].length ; j<jen ; j++ ) {
  7702. a.push( {
  7703. row: rows[idx][i],
  7704. column: columns[idx][j]
  7705. } );
  7706. }
  7707. }
  7708. return a;
  7709. }, 1 );
  7710. // There is currently only one extension which uses a cell selector extension
  7711. // It is a _major_ performance drag to run this if it isn't needed, so this is
  7712. // an extension specific check at the moment
  7713. var cells = opts && opts.selected ?
  7714. this.cells( cellsNoOpts, opts ) :
  7715. cellsNoOpts;
  7716. $.extend( cells.selector, {
  7717. cols: columnSelector,
  7718. rows: rowSelector,
  7719. opts: opts
  7720. } );
  7721. return cells;
  7722. } );
  7723. _api_registerPlural( 'cells().nodes()', 'cell().node()', function () {
  7724. return this.iterator( 'cell', function ( settings, row, column ) {
  7725. var data = settings.aoData[ row ];
  7726. return data && data.anCells ?
  7727. data.anCells[ column ] :
  7728. undefined;
  7729. }, 1 );
  7730. } );
  7731. _api_register( 'cells().data()', function () {
  7732. return this.iterator( 'cell', function ( settings, row, column ) {
  7733. return _fnGetCellData( settings, row, column );
  7734. }, 1 );
  7735. } );
  7736. _api_registerPlural( 'cells().cache()', 'cell().cache()', function ( type ) {
  7737. type = type === 'search' ? '_aFilterData' : '_aSortData';
  7738. return this.iterator( 'cell', function ( settings, row, column ) {
  7739. return settings.aoData[ row ][ type ][ column ];
  7740. }, 1 );
  7741. } );
  7742. _api_registerPlural( 'cells().render()', 'cell().render()', function ( type ) {
  7743. return this.iterator( 'cell', function ( settings, row, column ) {
  7744. return _fnGetCellData( settings, row, column, type );
  7745. }, 1 );
  7746. } );
  7747. _api_registerPlural( 'cells().indexes()', 'cell().index()', function () {
  7748. return this.iterator( 'cell', function ( settings, row, column ) {
  7749. return {
  7750. row: row,
  7751. column: column,
  7752. columnVisible: _fnColumnIndexToVisible( settings, column )
  7753. };
  7754. }, 1 );
  7755. } );
  7756. _api_registerPlural( 'cells().invalidate()', 'cell().invalidate()', function ( src ) {
  7757. return this.iterator( 'cell', function ( settings, row, column ) {
  7758. _fnInvalidate( settings, row, src, column );
  7759. } );
  7760. } );
  7761. _api_register( 'cell()', function ( rowSelector, columnSelector, opts ) {
  7762. return _selector_first( this.cells( rowSelector, columnSelector, opts ) );
  7763. } );
  7764. _api_register( 'cell().data()', function ( data ) {
  7765. var ctx = this.context;
  7766. var cell = this[0];
  7767. if ( data === undefined ) {
  7768. // Get
  7769. return ctx.length && cell.length ?
  7770. _fnGetCellData( ctx[0], cell[0].row, cell[0].column ) :
  7771. undefined;
  7772. }
  7773. // Set
  7774. _fnSetCellData( ctx[0], cell[0].row, cell[0].column, data );
  7775. _fnInvalidate( ctx[0], cell[0].row, 'data', cell[0].column );
  7776. return this;
  7777. } );
  7778. /**
  7779. * Get current ordering (sorting) that has been applied to the table.
  7780. *
  7781. * @returns {array} 2D array containing the sorting information for the first
  7782. * table in the current context. Each element in the parent array represents
  7783. * a column being sorted upon (i.e. multi-sorting with two columns would have
  7784. * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
  7785. * the column index that the sorting condition applies to, the second is the
  7786. * direction of the sort (`desc` or `asc`) and, optionally, the third is the
  7787. * index of the sorting order from the `column.sorting` initialisation array.
  7788. *//**
  7789. * Set the ordering for the table.
  7790. *
  7791. * @param {integer} order Column index to sort upon.
  7792. * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
  7793. * @returns {DataTables.Api} this
  7794. *//**
  7795. * Set the ordering for the table.
  7796. *
  7797. * @param {array} order 1D array of sorting information to be applied.
  7798. * @param {array} [...] Optional additional sorting conditions
  7799. * @returns {DataTables.Api} this
  7800. *//**
  7801. * Set the ordering for the table.
  7802. *
  7803. * @param {array} order 2D array of sorting information to be applied.
  7804. * @returns {DataTables.Api} this
  7805. */
  7806. _api_register( 'order()', function ( order, dir ) {
  7807. var ctx = this.context;
  7808. if ( order === undefined ) {
  7809. // get
  7810. return ctx.length !== 0 ?
  7811. ctx[0].aaSorting :
  7812. undefined;
  7813. }
  7814. // set
  7815. if ( typeof order === 'number' ) {
  7816. // Simple column / direction passed in
  7817. order = [ [ order, dir ] ];
  7818. }
  7819. else if ( order.length && ! Array.isArray( order[0] ) ) {
  7820. // Arguments passed in (list of 1D arrays)
  7821. order = Array.prototype.slice.call( arguments );
  7822. }
  7823. // otherwise a 2D array was passed in
  7824. return this.iterator( 'table', function ( settings ) {
  7825. settings.aaSorting = order.slice();
  7826. } );
  7827. } );
  7828. /**
  7829. * Attach a sort listener to an element for a given column
  7830. *
  7831. * @param {node|jQuery|string} node Identifier for the element(s) to attach the
  7832. * listener to. This can take the form of a single DOM node, a jQuery
  7833. * collection of nodes or a jQuery selector which will identify the node(s).
  7834. * @param {integer} column the column that a click on this node will sort on
  7835. * @param {function} [callback] callback function when sort is run
  7836. * @returns {DataTables.Api} this
  7837. */
  7838. _api_register( 'order.listener()', function ( node, column, callback ) {
  7839. return this.iterator( 'table', function ( settings ) {
  7840. _fnSortAttachListener( settings, node, column, callback );
  7841. } );
  7842. } );
  7843. _api_register( 'order.fixed()', function ( set ) {
  7844. if ( ! set ) {
  7845. var ctx = this.context;
  7846. var fixed = ctx.length ?
  7847. ctx[0].aaSortingFixed :
  7848. undefined;
  7849. return Array.isArray( fixed ) ?
  7850. { pre: fixed } :
  7851. fixed;
  7852. }
  7853. return this.iterator( 'table', function ( settings ) {
  7854. settings.aaSortingFixed = $.extend( true, {}, set );
  7855. } );
  7856. } );
  7857. // Order by the selected column(s)
  7858. _api_register( [
  7859. 'columns().order()',
  7860. 'column().order()'
  7861. ], function ( dir ) {
  7862. var that = this;
  7863. return this.iterator( 'table', function ( settings, i ) {
  7864. var sort = [];
  7865. $.each( that[i], function (j, col) {
  7866. sort.push( [ col, dir ] );
  7867. } );
  7868. settings.aaSorting = sort;
  7869. } );
  7870. } );
  7871. _api_register( 'search()', function ( input, regex, smart, caseInsen ) {
  7872. var ctx = this.context;
  7873. if ( input === undefined ) {
  7874. // get
  7875. return ctx.length !== 0 ?
  7876. ctx[0].oPreviousSearch.sSearch :
  7877. undefined;
  7878. }
  7879. // set
  7880. return this.iterator( 'table', function ( settings ) {
  7881. if ( ! settings.oFeatures.bFilter ) {
  7882. return;
  7883. }
  7884. _fnFilterComplete( settings, $.extend( {}, settings.oPreviousSearch, {
  7885. "sSearch": input+"",
  7886. "bRegex": regex === null ? false : regex,
  7887. "bSmart": smart === null ? true : smart,
  7888. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7889. } ), 1 );
  7890. } );
  7891. } );
  7892. _api_registerPlural(
  7893. 'columns().search()',
  7894. 'column().search()',
  7895. function ( input, regex, smart, caseInsen ) {
  7896. return this.iterator( 'column', function ( settings, column ) {
  7897. var preSearch = settings.aoPreSearchCols;
  7898. if ( input === undefined ) {
  7899. // get
  7900. return preSearch[ column ].sSearch;
  7901. }
  7902. // set
  7903. if ( ! settings.oFeatures.bFilter ) {
  7904. return;
  7905. }
  7906. $.extend( preSearch[ column ], {
  7907. "sSearch": input+"",
  7908. "bRegex": regex === null ? false : regex,
  7909. "bSmart": smart === null ? true : smart,
  7910. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7911. } );
  7912. _fnFilterComplete( settings, settings.oPreviousSearch, 1 );
  7913. } );
  7914. }
  7915. );
  7916. /*
  7917. * State API methods
  7918. */
  7919. _api_register( 'state()', function () {
  7920. return this.context.length ?
  7921. this.context[0].oSavedState :
  7922. null;
  7923. } );
  7924. _api_register( 'state.clear()', function () {
  7925. return this.iterator( 'table', function ( settings ) {
  7926. // Save an empty object
  7927. settings.fnStateSaveCallback.call( settings.oInstance, settings, {} );
  7928. } );
  7929. } );
  7930. _api_register( 'state.loaded()', function () {
  7931. return this.context.length ?
  7932. this.context[0].oLoadedState :
  7933. null;
  7934. } );
  7935. _api_register( 'state.save()', function () {
  7936. return this.iterator( 'table', function ( settings ) {
  7937. _fnSaveState( settings );
  7938. } );
  7939. } );
  7940. /**
  7941. * Set the jQuery or window object to be used by DataTables
  7942. *
  7943. * @param {*} module Library / container object
  7944. * @param {string} [type] Library or container type `lib`, `win` or `datetime`.
  7945. * If not provided, automatic detection is attempted.
  7946. */
  7947. DataTable.use = function (module, type) {
  7948. if (type === 'lib' || module.fn) {
  7949. $ = module;
  7950. }
  7951. else if (type == 'win' || module.document) {
  7952. window = module;
  7953. document = module.document;
  7954. }
  7955. else if (type === 'datetime' || module.type === 'DateTime') {
  7956. DataTable.DateTime = module;
  7957. }
  7958. }
  7959. /**
  7960. * CommonJS factory function pass through. This will check if the arguments
  7961. * given are a window object or a jQuery object. If so they are set
  7962. * accordingly.
  7963. * @param {*} root Window
  7964. * @param {*} jq jQUery
  7965. * @returns {boolean} Indicator
  7966. */
  7967. DataTable.factory = function (root, jq) {
  7968. var is = false;
  7969. // Test if the first parameter is a window object
  7970. if (root && root.document) {
  7971. window = root;
  7972. document = root.document;
  7973. }
  7974. // Test if the second parameter is a jQuery object
  7975. if (jq && jq.fn && jq.fn.jquery) {
  7976. $ = jq;
  7977. is = true;
  7978. }
  7979. return is;
  7980. }
  7981. /**
  7982. * Provide a common method for plug-ins to check the version of DataTables being
  7983. * used, in order to ensure compatibility.
  7984. *
  7985. * @param {string} version Version string to check for, in the format "X.Y.Z".
  7986. * Note that the formats "X" and "X.Y" are also acceptable.
  7987. * @returns {boolean} true if this version of DataTables is greater or equal to
  7988. * the required version, or false if this version of DataTales is not
  7989. * suitable
  7990. * @static
  7991. * @dtopt API-Static
  7992. *
  7993. * @example
  7994. * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
  7995. */
  7996. DataTable.versionCheck = DataTable.fnVersionCheck = function( version )
  7997. {
  7998. var aThis = DataTable.version.split('.');
  7999. var aThat = version.split('.');
  8000. var iThis, iThat;
  8001. for ( var i=0, iLen=aThat.length ; i<iLen ; i++ ) {
  8002. iThis = parseInt( aThis[i], 10 ) || 0;
  8003. iThat = parseInt( aThat[i], 10 ) || 0;
  8004. // Parts are the same, keep comparing
  8005. if (iThis === iThat) {
  8006. continue;
  8007. }
  8008. // Parts are different, return immediately
  8009. return iThis > iThat;
  8010. }
  8011. return true;
  8012. };
  8013. /**
  8014. * Check if a `<table>` node is a DataTable table already or not.
  8015. *
  8016. * @param {node|jquery|string} table Table node, jQuery object or jQuery
  8017. * selector for the table to test. Note that if more than more than one
  8018. * table is passed on, only the first will be checked
  8019. * @returns {boolean} true the table given is a DataTable, or false otherwise
  8020. * @static
  8021. * @dtopt API-Static
  8022. *
  8023. * @example
  8024. * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
  8025. * $('#example').dataTable();
  8026. * }
  8027. */
  8028. DataTable.isDataTable = DataTable.fnIsDataTable = function ( table )
  8029. {
  8030. var t = $(table).get(0);
  8031. var is = false;
  8032. if ( table instanceof DataTable.Api ) {
  8033. return true;
  8034. }
  8035. $.each( DataTable.settings, function (i, o) {
  8036. var head = o.nScrollHead ? $('table', o.nScrollHead)[0] : null;
  8037. var foot = o.nScrollFoot ? $('table', o.nScrollFoot)[0] : null;
  8038. if ( o.nTable === t || head === t || foot === t ) {
  8039. is = true;
  8040. }
  8041. } );
  8042. return is;
  8043. };
  8044. /**
  8045. * Get all DataTable tables that have been initialised - optionally you can
  8046. * select to get only currently visible tables.
  8047. *
  8048. * @param {boolean} [visible=false] Flag to indicate if you want all (default)
  8049. * or visible tables only.
  8050. * @returns {array} Array of `table` nodes (not DataTable instances) which are
  8051. * DataTables
  8052. * @static
  8053. * @dtopt API-Static
  8054. *
  8055. * @example
  8056. * $.each( $.fn.dataTable.tables(true), function () {
  8057. * $(table).DataTable().columns.adjust();
  8058. * } );
  8059. */
  8060. DataTable.tables = DataTable.fnTables = function ( visible )
  8061. {
  8062. var api = false;
  8063. if ( $.isPlainObject( visible ) ) {
  8064. api = visible.api;
  8065. visible = visible.visible;
  8066. }
  8067. var a = $.map( DataTable.settings, function (o) {
  8068. if ( !visible || (visible && $(o.nTable).is(':visible')) ) {
  8069. return o.nTable;
  8070. }
  8071. } );
  8072. return api ?
  8073. new _Api( a ) :
  8074. a;
  8075. };
  8076. /**
  8077. * Convert from camel case parameters to Hungarian notation. This is made public
  8078. * for the extensions to provide the same ability as DataTables core to accept
  8079. * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
  8080. * parameters.
  8081. *
  8082. * @param {object} src The model object which holds all parameters that can be
  8083. * mapped.
  8084. * @param {object} user The object to convert from camel case to Hungarian.
  8085. * @param {boolean} force When set to `true`, properties which already have a
  8086. * Hungarian value in the `user` object will be overwritten. Otherwise they
  8087. * won't be.
  8088. */
  8089. DataTable.camelToHungarian = _fnCamelToHungarian;
  8090. /**
  8091. *
  8092. */
  8093. _api_register( '$()', function ( selector, opts ) {
  8094. var
  8095. rows = this.rows( opts ).nodes(), // Get all rows
  8096. jqRows = $(rows);
  8097. return $( [].concat(
  8098. jqRows.filter( selector ).toArray(),
  8099. jqRows.find( selector ).toArray()
  8100. ) );
  8101. } );
  8102. // jQuery functions to operate on the tables
  8103. $.each( [ 'on', 'one', 'off' ], function (i, key) {
  8104. _api_register( key+'()', function ( /* event, handler */ ) {
  8105. var args = Array.prototype.slice.call(arguments);
  8106. // Add the `dt` namespace automatically if it isn't already present
  8107. args[0] = $.map( args[0].split( /\s/ ), function ( e ) {
  8108. return ! e.match(/\.dt\b/) ?
  8109. e+'.dt' :
  8110. e;
  8111. } ).join( ' ' );
  8112. var inst = $( this.tables().nodes() );
  8113. inst[key].apply( inst, args );
  8114. return this;
  8115. } );
  8116. } );
  8117. _api_register( 'clear()', function () {
  8118. return this.iterator( 'table', function ( settings ) {
  8119. _fnClearTable( settings );
  8120. } );
  8121. } );
  8122. _api_register( 'settings()', function () {
  8123. return new _Api( this.context, this.context );
  8124. } );
  8125. _api_register( 'init()', function () {
  8126. var ctx = this.context;
  8127. return ctx.length ? ctx[0].oInit : null;
  8128. } );
  8129. _api_register( 'data()', function () {
  8130. return this.iterator( 'table', function ( settings ) {
  8131. return _pluck( settings.aoData, '_aData' );
  8132. } ).flatten();
  8133. } );
  8134. _api_register( 'destroy()', function ( remove ) {
  8135. remove = remove || false;
  8136. return this.iterator( 'table', function ( settings ) {
  8137. var classes = settings.oClasses;
  8138. var table = settings.nTable;
  8139. var tbody = settings.nTBody;
  8140. var thead = settings.nTHead;
  8141. var tfoot = settings.nTFoot;
  8142. var jqTable = $(table);
  8143. var jqTbody = $(tbody);
  8144. var jqWrapper = $(settings.nTableWrapper);
  8145. var rows = $.map( settings.aoData, function (r) { return r.nTr; } );
  8146. var i, ien;
  8147. // Flag to note that the table is currently being destroyed - no action
  8148. // should be taken
  8149. settings.bDestroying = true;
  8150. // Fire off the destroy callbacks for plug-ins etc
  8151. _fnCallbackFire( settings, "aoDestroyCallback", "destroy", [settings] );
  8152. // If not being removed from the document, make all columns visible
  8153. if ( ! remove ) {
  8154. new _Api( settings ).columns().visible( true );
  8155. }
  8156. // Blitz all `DT` namespaced events (these are internal events, the
  8157. // lowercase, `dt` events are user subscribed and they are responsible
  8158. // for removing them
  8159. jqWrapper.off('.DT').find(':not(tbody *)').off('.DT');
  8160. $(window).off('.DT-'+settings.sInstance);
  8161. // When scrolling we had to break the table up - restore it
  8162. if ( table != thead.parentNode ) {
  8163. jqTable.children('thead').detach();
  8164. jqTable.append( thead );
  8165. }
  8166. if ( tfoot && table != tfoot.parentNode ) {
  8167. jqTable.children('tfoot').detach();
  8168. jqTable.append( tfoot );
  8169. }
  8170. settings.aaSorting = [];
  8171. settings.aaSortingFixed = [];
  8172. _fnSortingClasses( settings );
  8173. $( rows ).removeClass( settings.asStripeClasses.join(' ') );
  8174. $('th, td', thead).removeClass( classes.sSortable+' '+
  8175. classes.sSortableAsc+' '+classes.sSortableDesc+' '+classes.sSortableNone
  8176. );
  8177. // Add the TR elements back into the table in their original order
  8178. jqTbody.children().detach();
  8179. jqTbody.append( rows );
  8180. var orig = settings.nTableWrapper.parentNode;
  8181. // Remove the DataTables generated nodes, events and classes
  8182. var removedMethod = remove ? 'remove' : 'detach';
  8183. jqTable[ removedMethod ]();
  8184. jqWrapper[ removedMethod ]();
  8185. // If we need to reattach the table to the document
  8186. if ( ! remove && orig ) {
  8187. // insertBefore acts like appendChild if !arg[1]
  8188. orig.insertBefore( table, settings.nTableReinsertBefore );
  8189. // Restore the width of the original table - was read from the style property,
  8190. // so we can restore directly to that
  8191. jqTable
  8192. .css( 'width', settings.sDestroyWidth )
  8193. .removeClass( classes.sTable );
  8194. // If the were originally stripe classes - then we add them back here.
  8195. // Note this is not fool proof (for example if not all rows had stripe
  8196. // classes - but it's a good effort without getting carried away
  8197. ien = settings.asDestroyStripes.length;
  8198. if ( ien ) {
  8199. jqTbody.children().each( function (i) {
  8200. $(this).addClass( settings.asDestroyStripes[i % ien] );
  8201. } );
  8202. }
  8203. }
  8204. /* Remove the settings object from the settings array */
  8205. var idx = $.inArray( settings, DataTable.settings );
  8206. if ( idx !== -1 ) {
  8207. DataTable.settings.splice( idx, 1 );
  8208. }
  8209. } );
  8210. } );
  8211. // Add the `every()` method for rows, columns and cells in a compact form
  8212. $.each( [ 'column', 'row', 'cell' ], function ( i, type ) {
  8213. _api_register( type+'s().every()', function ( fn ) {
  8214. var opts = this.selector.opts;
  8215. var api = this;
  8216. return this.iterator( type, function ( settings, arg1, arg2, arg3, arg4 ) {
  8217. // Rows and columns:
  8218. // arg1 - index
  8219. // arg2 - table counter
  8220. // arg3 - loop counter
  8221. // arg4 - undefined
  8222. // Cells:
  8223. // arg1 - row index
  8224. // arg2 - column index
  8225. // arg3 - table counter
  8226. // arg4 - loop counter
  8227. fn.call(
  8228. api[ type ](
  8229. arg1,
  8230. type==='cell' ? arg2 : opts,
  8231. type==='cell' ? opts : undefined
  8232. ),
  8233. arg1, arg2, arg3, arg4
  8234. );
  8235. } );
  8236. } );
  8237. } );
  8238. // i18n method for extensions to be able to use the language object from the
  8239. // DataTable
  8240. _api_register( 'i18n()', function ( token, def, plural ) {
  8241. var ctx = this.context[0];
  8242. var resolved = _fnGetObjectDataFn( token )( ctx.oLanguage );
  8243. if ( resolved === undefined ) {
  8244. resolved = def;
  8245. }
  8246. if ( plural !== undefined && $.isPlainObject( resolved ) ) {
  8247. resolved = resolved[ plural ] !== undefined ?
  8248. resolved[ plural ] :
  8249. resolved._;
  8250. }
  8251. return typeof resolved === 'string'
  8252. ? resolved.replace( '%d', plural ) // nb: plural might be undefined,
  8253. : resolved;
  8254. } );
  8255. /**
  8256. * Version string for plug-ins to check compatibility. Allowed format is
  8257. * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
  8258. * only for non-release builds. See http://semver.org/ for more information.
  8259. * @member
  8260. * @type string
  8261. * @default Version number
  8262. */
  8263. DataTable.version = "1.13.5";
  8264. /**
  8265. * Private data store, containing all of the settings objects that are
  8266. * created for the tables on a given page.
  8267. *
  8268. * Note that the `DataTable.settings` object is aliased to
  8269. * `jQuery.fn.dataTableExt` through which it may be accessed and
  8270. * manipulated, or `jQuery.fn.dataTable.settings`.
  8271. * @member
  8272. * @type array
  8273. * @default []
  8274. * @private
  8275. */
  8276. DataTable.settings = [];
  8277. /**
  8278. * Object models container, for the various models that DataTables has
  8279. * available to it. These models define the objects that are used to hold
  8280. * the active state and configuration of the table.
  8281. * @namespace
  8282. */
  8283. DataTable.models = {};
  8284. /**
  8285. * Template object for the way in which DataTables holds information about
  8286. * search information for the global filter and individual column filters.
  8287. * @namespace
  8288. */
  8289. DataTable.models.oSearch = {
  8290. /**
  8291. * Flag to indicate if the filtering should be case insensitive or not
  8292. * @type boolean
  8293. * @default true
  8294. */
  8295. "bCaseInsensitive": true,
  8296. /**
  8297. * Applied search term
  8298. * @type string
  8299. * @default <i>Empty string</i>
  8300. */
  8301. "sSearch": "",
  8302. /**
  8303. * Flag to indicate if the search term should be interpreted as a
  8304. * regular expression (true) or not (false) and therefore and special
  8305. * regex characters escaped.
  8306. * @type boolean
  8307. * @default false
  8308. */
  8309. "bRegex": false,
  8310. /**
  8311. * Flag to indicate if DataTables is to use its smart filtering or not.
  8312. * @type boolean
  8313. * @default true
  8314. */
  8315. "bSmart": true,
  8316. /**
  8317. * Flag to indicate if DataTables should only trigger a search when
  8318. * the return key is pressed.
  8319. * @type boolean
  8320. * @default false
  8321. */
  8322. "return": false
  8323. };
  8324. /**
  8325. * Template object for the way in which DataTables holds information about
  8326. * each individual row. This is the object format used for the settings
  8327. * aoData array.
  8328. * @namespace
  8329. */
  8330. DataTable.models.oRow = {
  8331. /**
  8332. * TR element for the row
  8333. * @type node
  8334. * @default null
  8335. */
  8336. "nTr": null,
  8337. /**
  8338. * Array of TD elements for each row. This is null until the row has been
  8339. * created.
  8340. * @type array nodes
  8341. * @default []
  8342. */
  8343. "anCells": null,
  8344. /**
  8345. * Data object from the original data source for the row. This is either
  8346. * an array if using the traditional form of DataTables, or an object if
  8347. * using mData options. The exact type will depend on the passed in
  8348. * data from the data source, or will be an array if using DOM a data
  8349. * source.
  8350. * @type array|object
  8351. * @default []
  8352. */
  8353. "_aData": [],
  8354. /**
  8355. * Sorting data cache - this array is ostensibly the same length as the
  8356. * number of columns (although each index is generated only as it is
  8357. * needed), and holds the data that is used for sorting each column in the
  8358. * row. We do this cache generation at the start of the sort in order that
  8359. * the formatting of the sort data need be done only once for each cell
  8360. * per sort. This array should not be read from or written to by anything
  8361. * other than the master sorting methods.
  8362. * @type array
  8363. * @default null
  8364. * @private
  8365. */
  8366. "_aSortData": null,
  8367. /**
  8368. * Per cell filtering data cache. As per the sort data cache, used to
  8369. * increase the performance of the filtering in DataTables
  8370. * @type array
  8371. * @default null
  8372. * @private
  8373. */
  8374. "_aFilterData": null,
  8375. /**
  8376. * Filtering data cache. This is the same as the cell filtering cache, but
  8377. * in this case a string rather than an array. This is easily computed with
  8378. * a join on `_aFilterData`, but is provided as a cache so the join isn't
  8379. * needed on every search (memory traded for performance)
  8380. * @type array
  8381. * @default null
  8382. * @private
  8383. */
  8384. "_sFilterRow": null,
  8385. /**
  8386. * Cache of the class name that DataTables has applied to the row, so we
  8387. * can quickly look at this variable rather than needing to do a DOM check
  8388. * on className for the nTr property.
  8389. * @type string
  8390. * @default <i>Empty string</i>
  8391. * @private
  8392. */
  8393. "_sRowStripe": "",
  8394. /**
  8395. * Denote if the original data source was from the DOM, or the data source
  8396. * object. This is used for invalidating data, so DataTables can
  8397. * automatically read data from the original source, unless uninstructed
  8398. * otherwise.
  8399. * @type string
  8400. * @default null
  8401. * @private
  8402. */
  8403. "src": null,
  8404. /**
  8405. * Index in the aoData array. This saves an indexOf lookup when we have the
  8406. * object, but want to know the index
  8407. * @type integer
  8408. * @default -1
  8409. * @private
  8410. */
  8411. "idx": -1
  8412. };
  8413. /**
  8414. * Template object for the column information object in DataTables. This object
  8415. * is held in the settings aoColumns array and contains all the information that
  8416. * DataTables needs about each individual column.
  8417. *
  8418. * Note that this object is related to {@link DataTable.defaults.column}
  8419. * but this one is the internal data store for DataTables's cache of columns.
  8420. * It should NOT be manipulated outside of DataTables. Any configuration should
  8421. * be done through the initialisation options.
  8422. * @namespace
  8423. */
  8424. DataTable.models.oColumn = {
  8425. /**
  8426. * Column index. This could be worked out on-the-fly with $.inArray, but it
  8427. * is faster to just hold it as a variable
  8428. * @type integer
  8429. * @default null
  8430. */
  8431. "idx": null,
  8432. /**
  8433. * A list of the columns that sorting should occur on when this column
  8434. * is sorted. That this property is an array allows multi-column sorting
  8435. * to be defined for a column (for example first name / last name columns
  8436. * would benefit from this). The values are integers pointing to the
  8437. * columns to be sorted on (typically it will be a single integer pointing
  8438. * at itself, but that doesn't need to be the case).
  8439. * @type array
  8440. */
  8441. "aDataSort": null,
  8442. /**
  8443. * Define the sorting directions that are applied to the column, in sequence
  8444. * as the column is repeatedly sorted upon - i.e. the first value is used
  8445. * as the sorting direction when the column if first sorted (clicked on).
  8446. * Sort it again (click again) and it will move on to the next index.
  8447. * Repeat until loop.
  8448. * @type array
  8449. */
  8450. "asSorting": null,
  8451. /**
  8452. * Flag to indicate if the column is searchable, and thus should be included
  8453. * in the filtering or not.
  8454. * @type boolean
  8455. */
  8456. "bSearchable": null,
  8457. /**
  8458. * Flag to indicate if the column is sortable or not.
  8459. * @type boolean
  8460. */
  8461. "bSortable": null,
  8462. /**
  8463. * Flag to indicate if the column is currently visible in the table or not
  8464. * @type boolean
  8465. */
  8466. "bVisible": null,
  8467. /**
  8468. * Store for manual type assignment using the `column.type` option. This
  8469. * is held in store so we can manipulate the column's `sType` property.
  8470. * @type string
  8471. * @default null
  8472. * @private
  8473. */
  8474. "_sManualType": null,
  8475. /**
  8476. * Flag to indicate if HTML5 data attributes should be used as the data
  8477. * source for filtering or sorting. True is either are.
  8478. * @type boolean
  8479. * @default false
  8480. * @private
  8481. */
  8482. "_bAttrSrc": false,
  8483. /**
  8484. * Developer definable function that is called whenever a cell is created (Ajax source,
  8485. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  8486. * allowing you to modify the DOM element (add background colour for example) when the
  8487. * element is available.
  8488. * @type function
  8489. * @param {element} nTd The TD node that has been created
  8490. * @param {*} sData The Data for the cell
  8491. * @param {array|object} oData The data for the whole row
  8492. * @param {int} iRow The row index for the aoData data store
  8493. * @default null
  8494. */
  8495. "fnCreatedCell": null,
  8496. /**
  8497. * Function to get data from a cell in a column. You should <b>never</b>
  8498. * access data directly through _aData internally in DataTables - always use
  8499. * the method attached to this property. It allows mData to function as
  8500. * required. This function is automatically assigned by the column
  8501. * initialisation method
  8502. * @type function
  8503. * @param {array|object} oData The data array/object for the array
  8504. * (i.e. aoData[]._aData)
  8505. * @param {string} sSpecific The specific data type you want to get -
  8506. * 'display', 'type' 'filter' 'sort'
  8507. * @returns {*} The data for the cell from the given row's data
  8508. * @default null
  8509. */
  8510. "fnGetData": null,
  8511. /**
  8512. * Function to set data for a cell in the column. You should <b>never</b>
  8513. * set the data directly to _aData internally in DataTables - always use
  8514. * this method. It allows mData to function as required. This function
  8515. * is automatically assigned by the column initialisation method
  8516. * @type function
  8517. * @param {array|object} oData The data array/object for the array
  8518. * (i.e. aoData[]._aData)
  8519. * @param {*} sValue Value to set
  8520. * @default null
  8521. */
  8522. "fnSetData": null,
  8523. /**
  8524. * Property to read the value for the cells in the column from the data
  8525. * source array / object. If null, then the default content is used, if a
  8526. * function is given then the return from the function is used.
  8527. * @type function|int|string|null
  8528. * @default null
  8529. */
  8530. "mData": null,
  8531. /**
  8532. * Partner property to mData which is used (only when defined) to get
  8533. * the data - i.e. it is basically the same as mData, but without the
  8534. * 'set' option, and also the data fed to it is the result from mData.
  8535. * This is the rendering method to match the data method of mData.
  8536. * @type function|int|string|null
  8537. * @default null
  8538. */
  8539. "mRender": null,
  8540. /**
  8541. * Unique header TH/TD element for this column - this is what the sorting
  8542. * listener is attached to (if sorting is enabled.)
  8543. * @type node
  8544. * @default null
  8545. */
  8546. "nTh": null,
  8547. /**
  8548. * Unique footer TH/TD element for this column (if there is one). Not used
  8549. * in DataTables as such, but can be used for plug-ins to reference the
  8550. * footer for each column.
  8551. * @type node
  8552. * @default null
  8553. */
  8554. "nTf": null,
  8555. /**
  8556. * The class to apply to all TD elements in the table's TBODY for the column
  8557. * @type string
  8558. * @default null
  8559. */
  8560. "sClass": null,
  8561. /**
  8562. * When DataTables calculates the column widths to assign to each column,
  8563. * it finds the longest string in each column and then constructs a
  8564. * temporary table and reads the widths from that. The problem with this
  8565. * is that "mmm" is much wider then "iiii", but the latter is a longer
  8566. * string - thus the calculation can go wrong (doing it properly and putting
  8567. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  8568. * a "work around" we provide this option. It will append its value to the
  8569. * text that is found to be the longest string for the column - i.e. padding.
  8570. * @type string
  8571. */
  8572. "sContentPadding": null,
  8573. /**
  8574. * Allows a default value to be given for a column's data, and will be used
  8575. * whenever a null data source is encountered (this can be because mData
  8576. * is set to null, or because the data source itself is null).
  8577. * @type string
  8578. * @default null
  8579. */
  8580. "sDefaultContent": null,
  8581. /**
  8582. * Name for the column, allowing reference to the column by name as well as
  8583. * by index (needs a lookup to work by name).
  8584. * @type string
  8585. */
  8586. "sName": null,
  8587. /**
  8588. * Custom sorting data type - defines which of the available plug-ins in
  8589. * afnSortData the custom sorting will use - if any is defined.
  8590. * @type string
  8591. * @default std
  8592. */
  8593. "sSortDataType": 'std',
  8594. /**
  8595. * Class to be applied to the header element when sorting on this column
  8596. * @type string
  8597. * @default null
  8598. */
  8599. "sSortingClass": null,
  8600. /**
  8601. * Class to be applied to the header element when sorting on this column -
  8602. * when jQuery UI theming is used.
  8603. * @type string
  8604. * @default null
  8605. */
  8606. "sSortingClassJUI": null,
  8607. /**
  8608. * Title of the column - what is seen in the TH element (nTh).
  8609. * @type string
  8610. */
  8611. "sTitle": null,
  8612. /**
  8613. * Column sorting and filtering type
  8614. * @type string
  8615. * @default null
  8616. */
  8617. "sType": null,
  8618. /**
  8619. * Width of the column
  8620. * @type string
  8621. * @default null
  8622. */
  8623. "sWidth": null,
  8624. /**
  8625. * Width of the column when it was first "encountered"
  8626. * @type string
  8627. * @default null
  8628. */
  8629. "sWidthOrig": null
  8630. };
  8631. /*
  8632. * Developer note: The properties of the object below are given in Hungarian
  8633. * notation, that was used as the interface for DataTables prior to v1.10, however
  8634. * from v1.10 onwards the primary interface is camel case. In order to avoid
  8635. * breaking backwards compatibility utterly with this change, the Hungarian
  8636. * version is still, internally the primary interface, but is is not documented
  8637. * - hence the @name tags in each doc comment. This allows a Javascript function
  8638. * to create a map from Hungarian notation to camel case (going the other direction
  8639. * would require each property to be listed, which would add around 3K to the size
  8640. * of DataTables, while this method is about a 0.5K hit).
  8641. *
  8642. * Ultimately this does pave the way for Hungarian notation to be dropped
  8643. * completely, but that is a massive amount of work and will break current
  8644. * installs (therefore is on-hold until v2).
  8645. */
  8646. /**
  8647. * Initialisation options that can be given to DataTables at initialisation
  8648. * time.
  8649. * @namespace
  8650. */
  8651. DataTable.defaults = {
  8652. /**
  8653. * An array of data to use for the table, passed in at initialisation which
  8654. * will be used in preference to any data which is already in the DOM. This is
  8655. * particularly useful for constructing tables purely in Javascript, for
  8656. * example with a custom Ajax call.
  8657. * @type array
  8658. * @default null
  8659. *
  8660. * @dtopt Option
  8661. * @name DataTable.defaults.data
  8662. *
  8663. * @example
  8664. * // Using a 2D array data source
  8665. * $(document).ready( function () {
  8666. * $('#example').dataTable( {
  8667. * "data": [
  8668. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  8669. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  8670. * ],
  8671. * "columns": [
  8672. * { "title": "Engine" },
  8673. * { "title": "Browser" },
  8674. * { "title": "Platform" },
  8675. * { "title": "Version" },
  8676. * { "title": "Grade" }
  8677. * ]
  8678. * } );
  8679. * } );
  8680. *
  8681. * @example
  8682. * // Using an array of objects as a data source (`data`)
  8683. * $(document).ready( function () {
  8684. * $('#example').dataTable( {
  8685. * "data": [
  8686. * {
  8687. * "engine": "Trident",
  8688. * "browser": "Internet Explorer 4.0",
  8689. * "platform": "Win 95+",
  8690. * "version": 4,
  8691. * "grade": "X"
  8692. * },
  8693. * {
  8694. * "engine": "Trident",
  8695. * "browser": "Internet Explorer 5.0",
  8696. * "platform": "Win 95+",
  8697. * "version": 5,
  8698. * "grade": "C"
  8699. * }
  8700. * ],
  8701. * "columns": [
  8702. * { "title": "Engine", "data": "engine" },
  8703. * { "title": "Browser", "data": "browser" },
  8704. * { "title": "Platform", "data": "platform" },
  8705. * { "title": "Version", "data": "version" },
  8706. * { "title": "Grade", "data": "grade" }
  8707. * ]
  8708. * } );
  8709. * } );
  8710. */
  8711. "aaData": null,
  8712. /**
  8713. * If ordering is enabled, then DataTables will perform a first pass sort on
  8714. * initialisation. You can define which column(s) the sort is performed
  8715. * upon, and the sorting direction, with this variable. The `sorting` array
  8716. * should contain an array for each column to be sorted initially containing
  8717. * the column's index and a direction string ('asc' or 'desc').
  8718. * @type array
  8719. * @default [[0,'asc']]
  8720. *
  8721. * @dtopt Option
  8722. * @name DataTable.defaults.order
  8723. *
  8724. * @example
  8725. * // Sort by 3rd column first, and then 4th column
  8726. * $(document).ready( function() {
  8727. * $('#example').dataTable( {
  8728. * "order": [[2,'asc'], [3,'desc']]
  8729. * } );
  8730. * } );
  8731. *
  8732. * // No initial sorting
  8733. * $(document).ready( function() {
  8734. * $('#example').dataTable( {
  8735. * "order": []
  8736. * } );
  8737. * } );
  8738. */
  8739. "aaSorting": [[0,'asc']],
  8740. /**
  8741. * This parameter is basically identical to the `sorting` parameter, but
  8742. * cannot be overridden by user interaction with the table. What this means
  8743. * is that you could have a column (visible or hidden) which the sorting
  8744. * will always be forced on first - any sorting after that (from the user)
  8745. * will then be performed as required. This can be useful for grouping rows
  8746. * together.
  8747. * @type array
  8748. * @default null
  8749. *
  8750. * @dtopt Option
  8751. * @name DataTable.defaults.orderFixed
  8752. *
  8753. * @example
  8754. * $(document).ready( function() {
  8755. * $('#example').dataTable( {
  8756. * "orderFixed": [[0,'asc']]
  8757. * } );
  8758. * } )
  8759. */
  8760. "aaSortingFixed": [],
  8761. /**
  8762. * DataTables can be instructed to load data to display in the table from a
  8763. * Ajax source. This option defines how that Ajax call is made and where to.
  8764. *
  8765. * The `ajax` property has three different modes of operation, depending on
  8766. * how it is defined. These are:
  8767. *
  8768. * * `string` - Set the URL from where the data should be loaded from.
  8769. * * `object` - Define properties for `jQuery.ajax`.
  8770. * * `function` - Custom data get function
  8771. *
  8772. * `string`
  8773. * --------
  8774. *
  8775. * As a string, the `ajax` property simply defines the URL from which
  8776. * DataTables will load data.
  8777. *
  8778. * `object`
  8779. * --------
  8780. *
  8781. * As an object, the parameters in the object are passed to
  8782. * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
  8783. * of the Ajax request. DataTables has a number of default parameters which
  8784. * you can override using this option. Please refer to the jQuery
  8785. * documentation for a full description of the options available, although
  8786. * the following parameters provide additional options in DataTables or
  8787. * require special consideration:
  8788. *
  8789. * * `data` - As with jQuery, `data` can be provided as an object, but it
  8790. * can also be used as a function to manipulate the data DataTables sends
  8791. * to the server. The function takes a single parameter, an object of
  8792. * parameters with the values that DataTables has readied for sending. An
  8793. * object may be returned which will be merged into the DataTables
  8794. * defaults, or you can add the items to the object that was passed in and
  8795. * not return anything from the function. This supersedes `fnServerParams`
  8796. * from DataTables 1.9-.
  8797. *
  8798. * * `dataSrc` - By default DataTables will look for the property `data` (or
  8799. * `aaData` for compatibility with DataTables 1.9-) when obtaining data
  8800. * from an Ajax source or for server-side processing - this parameter
  8801. * allows that property to be changed. You can use Javascript dotted
  8802. * object notation to get a data source for multiple levels of nesting, or
  8803. * it my be used as a function. As a function it takes a single parameter,
  8804. * the JSON returned from the server, which can be manipulated as
  8805. * required, with the returned value being that used by DataTables as the
  8806. * data source for the table. This supersedes `sAjaxDataProp` from
  8807. * DataTables 1.9-.
  8808. *
  8809. * * `success` - Should not be overridden it is used internally in
  8810. * DataTables. To manipulate / transform the data returned by the server
  8811. * use `ajax.dataSrc`, or use `ajax` as a function (see below).
  8812. *
  8813. * `function`
  8814. * ----------
  8815. *
  8816. * As a function, making the Ajax call is left up to yourself allowing
  8817. * complete control of the Ajax request. Indeed, if desired, a method other
  8818. * than Ajax could be used to obtain the required data, such as Web storage
  8819. * or an AIR database.
  8820. *
  8821. * The function is given four parameters and no return is required. The
  8822. * parameters are:
  8823. *
  8824. * 1. _object_ - Data to send to the server
  8825. * 2. _function_ - Callback function that must be executed when the required
  8826. * data has been obtained. That data should be passed into the callback
  8827. * as the only parameter
  8828. * 3. _object_ - DataTables settings object for the table
  8829. *
  8830. * Note that this supersedes `fnServerData` from DataTables 1.9-.
  8831. *
  8832. * @type string|object|function
  8833. * @default null
  8834. *
  8835. * @dtopt Option
  8836. * @name DataTable.defaults.ajax
  8837. * @since 1.10.0
  8838. *
  8839. * @example
  8840. * // Get JSON data from a file via Ajax.
  8841. * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
  8842. * $('#example').dataTable( {
  8843. * "ajax": "data.json"
  8844. * } );
  8845. *
  8846. * @example
  8847. * // Get JSON data from a file via Ajax, using `dataSrc` to change
  8848. * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
  8849. * $('#example').dataTable( {
  8850. * "ajax": {
  8851. * "url": "data.json",
  8852. * "dataSrc": "tableData"
  8853. * }
  8854. * } );
  8855. *
  8856. * @example
  8857. * // Get JSON data from a file via Ajax, using `dataSrc` to read data
  8858. * // from a plain array rather than an array in an object
  8859. * $('#example').dataTable( {
  8860. * "ajax": {
  8861. * "url": "data.json",
  8862. * "dataSrc": ""
  8863. * }
  8864. * } );
  8865. *
  8866. * @example
  8867. * // Manipulate the data returned from the server - add a link to data
  8868. * // (note this can, should, be done using `render` for the column - this
  8869. * // is just a simple example of how the data can be manipulated).
  8870. * $('#example').dataTable( {
  8871. * "ajax": {
  8872. * "url": "data.json",
  8873. * "dataSrc": function ( json ) {
  8874. * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
  8875. * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
  8876. * }
  8877. * return json;
  8878. * }
  8879. * }
  8880. * } );
  8881. *
  8882. * @example
  8883. * // Add data to the request
  8884. * $('#example').dataTable( {
  8885. * "ajax": {
  8886. * "url": "data.json",
  8887. * "data": function ( d ) {
  8888. * return {
  8889. * "extra_search": $('#extra').val()
  8890. * };
  8891. * }
  8892. * }
  8893. * } );
  8894. *
  8895. * @example
  8896. * // Send request as POST
  8897. * $('#example').dataTable( {
  8898. * "ajax": {
  8899. * "url": "data.json",
  8900. * "type": "POST"
  8901. * }
  8902. * } );
  8903. *
  8904. * @example
  8905. * // Get the data from localStorage (could interface with a form for
  8906. * // adding, editing and removing rows).
  8907. * $('#example').dataTable( {
  8908. * "ajax": function (data, callback, settings) {
  8909. * callback(
  8910. * JSON.parse( localStorage.getItem('dataTablesData') )
  8911. * );
  8912. * }
  8913. * } );
  8914. */
  8915. "ajax": null,
  8916. /**
  8917. * This parameter allows you to readily specify the entries in the length drop
  8918. * down menu that DataTables shows when pagination is enabled. It can be
  8919. * either a 1D array of options which will be used for both the displayed
  8920. * option and the value, or a 2D array which will use the array in the first
  8921. * position as the value, and the array in the second position as the
  8922. * displayed options (useful for language strings such as 'All').
  8923. *
  8924. * Note that the `pageLength` property will be automatically set to the
  8925. * first value given in this array, unless `pageLength` is also provided.
  8926. * @type array
  8927. * @default [ 10, 25, 50, 100 ]
  8928. *
  8929. * @dtopt Option
  8930. * @name DataTable.defaults.lengthMenu
  8931. *
  8932. * @example
  8933. * $(document).ready( function() {
  8934. * $('#example').dataTable( {
  8935. * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  8936. * } );
  8937. * } );
  8938. */
  8939. "aLengthMenu": [ 10, 25, 50, 100 ],
  8940. /**
  8941. * The `columns` option in the initialisation parameter allows you to define
  8942. * details about the way individual columns behave. For a full list of
  8943. * column options that can be set, please see
  8944. * {@link DataTable.defaults.column}. Note that if you use `columns` to
  8945. * define your columns, you must have an entry in the array for every single
  8946. * column that you have in your table (these can be null if you don't which
  8947. * to specify any options).
  8948. * @member
  8949. *
  8950. * @name DataTable.defaults.column
  8951. */
  8952. "aoColumns": null,
  8953. /**
  8954. * Very similar to `columns`, `columnDefs` allows you to target a specific
  8955. * column, multiple columns, or all columns, using the `targets` property of
  8956. * each object in the array. This allows great flexibility when creating
  8957. * tables, as the `columnDefs` arrays can be of any length, targeting the
  8958. * columns you specifically want. `columnDefs` may use any of the column
  8959. * options available: {@link DataTable.defaults.column}, but it _must_
  8960. * have `targets` defined in each object in the array. Values in the `targets`
  8961. * array may be:
  8962. * <ul>
  8963. * <li>a string - class name will be matched on the TH for the column</li>
  8964. * <li>0 or a positive integer - column index counting from the left</li>
  8965. * <li>a negative integer - column index counting from the right</li>
  8966. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  8967. * </ul>
  8968. * @member
  8969. *
  8970. * @name DataTable.defaults.columnDefs
  8971. */
  8972. "aoColumnDefs": null,
  8973. /**
  8974. * Basically the same as `search`, this parameter defines the individual column
  8975. * filtering state at initialisation time. The array must be of the same size
  8976. * as the number of columns, and each element be an object with the parameters
  8977. * `search` and `escapeRegex` (the latter is optional). 'null' is also
  8978. * accepted and the default will be used.
  8979. * @type array
  8980. * @default []
  8981. *
  8982. * @dtopt Option
  8983. * @name DataTable.defaults.searchCols
  8984. *
  8985. * @example
  8986. * $(document).ready( function() {
  8987. * $('#example').dataTable( {
  8988. * "searchCols": [
  8989. * null,
  8990. * { "search": "My filter" },
  8991. * null,
  8992. * { "search": "^[0-9]", "escapeRegex": false }
  8993. * ]
  8994. * } );
  8995. * } )
  8996. */
  8997. "aoSearchCols": [],
  8998. /**
  8999. * An array of CSS classes that should be applied to displayed rows. This
  9000. * array may be of any length, and DataTables will apply each class
  9001. * sequentially, looping when required.
  9002. * @type array
  9003. * @default null <i>Will take the values determined by the `oClasses.stripe*`
  9004. * options</i>
  9005. *
  9006. * @dtopt Option
  9007. * @name DataTable.defaults.stripeClasses
  9008. *
  9009. * @example
  9010. * $(document).ready( function() {
  9011. * $('#example').dataTable( {
  9012. * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  9013. * } );
  9014. * } )
  9015. */
  9016. "asStripeClasses": null,
  9017. /**
  9018. * Enable or disable automatic column width calculation. This can be disabled
  9019. * as an optimisation (it takes some time to calculate the widths) if the
  9020. * tables widths are passed in using `columns`.
  9021. * @type boolean
  9022. * @default true
  9023. *
  9024. * @dtopt Features
  9025. * @name DataTable.defaults.autoWidth
  9026. *
  9027. * @example
  9028. * $(document).ready( function () {
  9029. * $('#example').dataTable( {
  9030. * "autoWidth": false
  9031. * } );
  9032. * } );
  9033. */
  9034. "bAutoWidth": true,
  9035. /**
  9036. * Deferred rendering can provide DataTables with a huge speed boost when you
  9037. * are using an Ajax or JS data source for the table. This option, when set to
  9038. * true, will cause DataTables to defer the creation of the table elements for
  9039. * each row until they are needed for a draw - saving a significant amount of
  9040. * time.
  9041. * @type boolean
  9042. * @default false
  9043. *
  9044. * @dtopt Features
  9045. * @name DataTable.defaults.deferRender
  9046. *
  9047. * @example
  9048. * $(document).ready( function() {
  9049. * $('#example').dataTable( {
  9050. * "ajax": "sources/arrays.txt",
  9051. * "deferRender": true
  9052. * } );
  9053. * } );
  9054. */
  9055. "bDeferRender": false,
  9056. /**
  9057. * Replace a DataTable which matches the given selector and replace it with
  9058. * one which has the properties of the new initialisation object passed. If no
  9059. * table matches the selector, then the new DataTable will be constructed as
  9060. * per normal.
  9061. * @type boolean
  9062. * @default false
  9063. *
  9064. * @dtopt Options
  9065. * @name DataTable.defaults.destroy
  9066. *
  9067. * @example
  9068. * $(document).ready( function() {
  9069. * $('#example').dataTable( {
  9070. * "srollY": "200px",
  9071. * "paginate": false
  9072. * } );
  9073. *
  9074. * // Some time later....
  9075. * $('#example').dataTable( {
  9076. * "filter": false,
  9077. * "destroy": true
  9078. * } );
  9079. * } );
  9080. */
  9081. "bDestroy": false,
  9082. /**
  9083. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  9084. * that it allows the end user to input multiple words (space separated) and
  9085. * will match a row containing those words, even if not in the order that was
  9086. * specified (this allow matching across multiple columns). Note that if you
  9087. * wish to use filtering in DataTables this must remain 'true' - to remove the
  9088. * default filtering input box and retain filtering abilities, please use
  9089. * {@link DataTable.defaults.dom}.
  9090. * @type boolean
  9091. * @default true
  9092. *
  9093. * @dtopt Features
  9094. * @name DataTable.defaults.searching
  9095. *
  9096. * @example
  9097. * $(document).ready( function () {
  9098. * $('#example').dataTable( {
  9099. * "searching": false
  9100. * } );
  9101. * } );
  9102. */
  9103. "bFilter": true,
  9104. /**
  9105. * Enable or disable the table information display. This shows information
  9106. * about the data that is currently visible on the page, including information
  9107. * about filtered data if that action is being performed.
  9108. * @type boolean
  9109. * @default true
  9110. *
  9111. * @dtopt Features
  9112. * @name DataTable.defaults.info
  9113. *
  9114. * @example
  9115. * $(document).ready( function () {
  9116. * $('#example').dataTable( {
  9117. * "info": false
  9118. * } );
  9119. * } );
  9120. */
  9121. "bInfo": true,
  9122. /**
  9123. * Allows the end user to select the size of a formatted page from a select
  9124. * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
  9125. * @type boolean
  9126. * @default true
  9127. *
  9128. * @dtopt Features
  9129. * @name DataTable.defaults.lengthChange
  9130. *
  9131. * @example
  9132. * $(document).ready( function () {
  9133. * $('#example').dataTable( {
  9134. * "lengthChange": false
  9135. * } );
  9136. * } );
  9137. */
  9138. "bLengthChange": true,
  9139. /**
  9140. * Enable or disable pagination.
  9141. * @type boolean
  9142. * @default true
  9143. *
  9144. * @dtopt Features
  9145. * @name DataTable.defaults.paging
  9146. *
  9147. * @example
  9148. * $(document).ready( function () {
  9149. * $('#example').dataTable( {
  9150. * "paging": false
  9151. * } );
  9152. * } );
  9153. */
  9154. "bPaginate": true,
  9155. /**
  9156. * Enable or disable the display of a 'processing' indicator when the table is
  9157. * being processed (e.g. a sort). This is particularly useful for tables with
  9158. * large amounts of data where it can take a noticeable amount of time to sort
  9159. * the entries.
  9160. * @type boolean
  9161. * @default false
  9162. *
  9163. * @dtopt Features
  9164. * @name DataTable.defaults.processing
  9165. *
  9166. * @example
  9167. * $(document).ready( function () {
  9168. * $('#example').dataTable( {
  9169. * "processing": true
  9170. * } );
  9171. * } );
  9172. */
  9173. "bProcessing": false,
  9174. /**
  9175. * Retrieve the DataTables object for the given selector. Note that if the
  9176. * table has already been initialised, this parameter will cause DataTables
  9177. * to simply return the object that has already been set up - it will not take
  9178. * account of any changes you might have made to the initialisation object
  9179. * passed to DataTables (setting this parameter to true is an acknowledgement
  9180. * that you understand this). `destroy` can be used to reinitialise a table if
  9181. * you need.
  9182. * @type boolean
  9183. * @default false
  9184. *
  9185. * @dtopt Options
  9186. * @name DataTable.defaults.retrieve
  9187. *
  9188. * @example
  9189. * $(document).ready( function() {
  9190. * initTable();
  9191. * tableActions();
  9192. * } );
  9193. *
  9194. * function initTable ()
  9195. * {
  9196. * return $('#example').dataTable( {
  9197. * "scrollY": "200px",
  9198. * "paginate": false,
  9199. * "retrieve": true
  9200. * } );
  9201. * }
  9202. *
  9203. * function tableActions ()
  9204. * {
  9205. * var table = initTable();
  9206. * // perform API operations with oTable
  9207. * }
  9208. */
  9209. "bRetrieve": false,
  9210. /**
  9211. * When vertical (y) scrolling is enabled, DataTables will force the height of
  9212. * the table's viewport to the given height at all times (useful for layout).
  9213. * However, this can look odd when filtering data down to a small data set,
  9214. * and the footer is left "floating" further down. This parameter (when
  9215. * enabled) will cause DataTables to collapse the table's viewport down when
  9216. * the result set will fit within the given Y height.
  9217. * @type boolean
  9218. * @default false
  9219. *
  9220. * @dtopt Options
  9221. * @name DataTable.defaults.scrollCollapse
  9222. *
  9223. * @example
  9224. * $(document).ready( function() {
  9225. * $('#example').dataTable( {
  9226. * "scrollY": "200",
  9227. * "scrollCollapse": true
  9228. * } );
  9229. * } );
  9230. */
  9231. "bScrollCollapse": false,
  9232. /**
  9233. * Configure DataTables to use server-side processing. Note that the
  9234. * `ajax` parameter must also be given in order to give DataTables a
  9235. * source to obtain the required data for each draw.
  9236. * @type boolean
  9237. * @default false
  9238. *
  9239. * @dtopt Features
  9240. * @dtopt Server-side
  9241. * @name DataTable.defaults.serverSide
  9242. *
  9243. * @example
  9244. * $(document).ready( function () {
  9245. * $('#example').dataTable( {
  9246. * "serverSide": true,
  9247. * "ajax": "xhr.php"
  9248. * } );
  9249. * } );
  9250. */
  9251. "bServerSide": false,
  9252. /**
  9253. * Enable or disable sorting of columns. Sorting of individual columns can be
  9254. * disabled by the `sortable` option for each column.
  9255. * @type boolean
  9256. * @default true
  9257. *
  9258. * @dtopt Features
  9259. * @name DataTable.defaults.ordering
  9260. *
  9261. * @example
  9262. * $(document).ready( function () {
  9263. * $('#example').dataTable( {
  9264. * "ordering": false
  9265. * } );
  9266. * } );
  9267. */
  9268. "bSort": true,
  9269. /**
  9270. * Enable or display DataTables' ability to sort multiple columns at the
  9271. * same time (activated by shift-click by the user).
  9272. * @type boolean
  9273. * @default true
  9274. *
  9275. * @dtopt Options
  9276. * @name DataTable.defaults.orderMulti
  9277. *
  9278. * @example
  9279. * // Disable multiple column sorting ability
  9280. * $(document).ready( function () {
  9281. * $('#example').dataTable( {
  9282. * "orderMulti": false
  9283. * } );
  9284. * } );
  9285. */
  9286. "bSortMulti": true,
  9287. /**
  9288. * Allows control over whether DataTables should use the top (true) unique
  9289. * cell that is found for a single column, or the bottom (false - default).
  9290. * This is useful when using complex headers.
  9291. * @type boolean
  9292. * @default false
  9293. *
  9294. * @dtopt Options
  9295. * @name DataTable.defaults.orderCellsTop
  9296. *
  9297. * @example
  9298. * $(document).ready( function() {
  9299. * $('#example').dataTable( {
  9300. * "orderCellsTop": true
  9301. * } );
  9302. * } );
  9303. */
  9304. "bSortCellsTop": false,
  9305. /**
  9306. * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
  9307. * `sorting\_3` to the columns which are currently being sorted on. This is
  9308. * presented as a feature switch as it can increase processing time (while
  9309. * classes are removed and added) so for large data sets you might want to
  9310. * turn this off.
  9311. * @type boolean
  9312. * @default true
  9313. *
  9314. * @dtopt Features
  9315. * @name DataTable.defaults.orderClasses
  9316. *
  9317. * @example
  9318. * $(document).ready( function () {
  9319. * $('#example').dataTable( {
  9320. * "orderClasses": false
  9321. * } );
  9322. * } );
  9323. */
  9324. "bSortClasses": true,
  9325. /**
  9326. * Enable or disable state saving. When enabled HTML5 `localStorage` will be
  9327. * used to save table display information such as pagination information,
  9328. * display length, filtering and sorting. As such when the end user reloads
  9329. * the page the display display will match what thy had previously set up.
  9330. *
  9331. * Due to the use of `localStorage` the default state saving is not supported
  9332. * in IE6 or 7. If state saving is required in those browsers, use
  9333. * `stateSaveCallback` to provide a storage solution such as cookies.
  9334. * @type boolean
  9335. * @default false
  9336. *
  9337. * @dtopt Features
  9338. * @name DataTable.defaults.stateSave
  9339. *
  9340. * @example
  9341. * $(document).ready( function () {
  9342. * $('#example').dataTable( {
  9343. * "stateSave": true
  9344. * } );
  9345. * } );
  9346. */
  9347. "bStateSave": false,
  9348. /**
  9349. * This function is called when a TR element is created (and all TD child
  9350. * elements have been inserted), or registered if using a DOM source, allowing
  9351. * manipulation of the TR element (adding classes etc).
  9352. * @type function
  9353. * @param {node} row "TR" element for the current row
  9354. * @param {array} data Raw data array for this row
  9355. * @param {int} dataIndex The index of this row in the internal aoData array
  9356. *
  9357. * @dtopt Callbacks
  9358. * @name DataTable.defaults.createdRow
  9359. *
  9360. * @example
  9361. * $(document).ready( function() {
  9362. * $('#example').dataTable( {
  9363. * "createdRow": function( row, data, dataIndex ) {
  9364. * // Bold the grade for all 'A' grade browsers
  9365. * if ( data[4] == "A" )
  9366. * {
  9367. * $('td:eq(4)', row).html( '<b>A</b>' );
  9368. * }
  9369. * }
  9370. * } );
  9371. * } );
  9372. */
  9373. "fnCreatedRow": null,
  9374. /**
  9375. * This function is called on every 'draw' event, and allows you to
  9376. * dynamically modify any aspect you want about the created DOM.
  9377. * @type function
  9378. * @param {object} settings DataTables settings object
  9379. *
  9380. * @dtopt Callbacks
  9381. * @name DataTable.defaults.drawCallback
  9382. *
  9383. * @example
  9384. * $(document).ready( function() {
  9385. * $('#example').dataTable( {
  9386. * "drawCallback": function( settings ) {
  9387. * alert( 'DataTables has redrawn the table' );
  9388. * }
  9389. * } );
  9390. * } );
  9391. */
  9392. "fnDrawCallback": null,
  9393. /**
  9394. * Identical to fnHeaderCallback() but for the table footer this function
  9395. * allows you to modify the table footer on every 'draw' event.
  9396. * @type function
  9397. * @param {node} foot "TR" element for the footer
  9398. * @param {array} data Full table data (as derived from the original HTML)
  9399. * @param {int} start Index for the current display starting point in the
  9400. * display array
  9401. * @param {int} end Index for the current display ending point in the
  9402. * display array
  9403. * @param {array int} display Index array to translate the visual position
  9404. * to the full data array
  9405. *
  9406. * @dtopt Callbacks
  9407. * @name DataTable.defaults.footerCallback
  9408. *
  9409. * @example
  9410. * $(document).ready( function() {
  9411. * $('#example').dataTable( {
  9412. * "footerCallback": function( tfoot, data, start, end, display ) {
  9413. * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
  9414. * }
  9415. * } );
  9416. * } )
  9417. */
  9418. "fnFooterCallback": null,
  9419. /**
  9420. * When rendering large numbers in the information element for the table
  9421. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  9422. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  9423. * rendered as "1,000,000") to help readability for the end user. This
  9424. * function will override the default method DataTables uses.
  9425. * @type function
  9426. * @member
  9427. * @param {int} toFormat number to be formatted
  9428. * @returns {string} formatted string for DataTables to show the number
  9429. *
  9430. * @dtopt Callbacks
  9431. * @name DataTable.defaults.formatNumber
  9432. *
  9433. * @example
  9434. * // Format a number using a single quote for the separator (note that
  9435. * // this can also be done with the language.thousands option)
  9436. * $(document).ready( function() {
  9437. * $('#example').dataTable( {
  9438. * "formatNumber": function ( toFormat ) {
  9439. * return toFormat.toString().replace(
  9440. * /\B(?=(\d{3})+(?!\d))/g, "'"
  9441. * );
  9442. * };
  9443. * } );
  9444. * } );
  9445. */
  9446. "fnFormatNumber": function ( toFormat ) {
  9447. return toFormat.toString().replace(
  9448. /\B(?=(\d{3})+(?!\d))/g,
  9449. this.oLanguage.sThousands
  9450. );
  9451. },
  9452. /**
  9453. * This function is called on every 'draw' event, and allows you to
  9454. * dynamically modify the header row. This can be used to calculate and
  9455. * display useful information about the table.
  9456. * @type function
  9457. * @param {node} head "TR" element for the header
  9458. * @param {array} data Full table data (as derived from the original HTML)
  9459. * @param {int} start Index for the current display starting point in the
  9460. * display array
  9461. * @param {int} end Index for the current display ending point in the
  9462. * display array
  9463. * @param {array int} display Index array to translate the visual position
  9464. * to the full data array
  9465. *
  9466. * @dtopt Callbacks
  9467. * @name DataTable.defaults.headerCallback
  9468. *
  9469. * @example
  9470. * $(document).ready( function() {
  9471. * $('#example').dataTable( {
  9472. * "fheaderCallback": function( head, data, start, end, display ) {
  9473. * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
  9474. * }
  9475. * } );
  9476. * } )
  9477. */
  9478. "fnHeaderCallback": null,
  9479. /**
  9480. * The information element can be used to convey information about the current
  9481. * state of the table. Although the internationalisation options presented by
  9482. * DataTables are quite capable of dealing with most customisations, there may
  9483. * be times where you wish to customise the string further. This callback
  9484. * allows you to do exactly that.
  9485. * @type function
  9486. * @param {object} oSettings DataTables settings object
  9487. * @param {int} start Starting position in data for the draw
  9488. * @param {int} end End position in data for the draw
  9489. * @param {int} max Total number of rows in the table (regardless of
  9490. * filtering)
  9491. * @param {int} total Total number of rows in the data set, after filtering
  9492. * @param {string} pre The string that DataTables has formatted using it's
  9493. * own rules
  9494. * @returns {string} The string to be displayed in the information element.
  9495. *
  9496. * @dtopt Callbacks
  9497. * @name DataTable.defaults.infoCallback
  9498. *
  9499. * @example
  9500. * $('#example').dataTable( {
  9501. * "infoCallback": function( settings, start, end, max, total, pre ) {
  9502. * return start +" to "+ end;
  9503. * }
  9504. * } );
  9505. */
  9506. "fnInfoCallback": null,
  9507. /**
  9508. * Called when the table has been initialised. Normally DataTables will
  9509. * initialise sequentially and there will be no need for this function,
  9510. * however, this does not hold true when using external language information
  9511. * since that is obtained using an async XHR call.
  9512. * @type function
  9513. * @param {object} settings DataTables settings object
  9514. * @param {object} json The JSON object request from the server - only
  9515. * present if client-side Ajax sourced data is used
  9516. *
  9517. * @dtopt Callbacks
  9518. * @name DataTable.defaults.initComplete
  9519. *
  9520. * @example
  9521. * $(document).ready( function() {
  9522. * $('#example').dataTable( {
  9523. * "initComplete": function(settings, json) {
  9524. * alert( 'DataTables has finished its initialisation.' );
  9525. * }
  9526. * } );
  9527. * } )
  9528. */
  9529. "fnInitComplete": null,
  9530. /**
  9531. * Called at the very start of each table draw and can be used to cancel the
  9532. * draw by returning false, any other return (including undefined) results in
  9533. * the full draw occurring).
  9534. * @type function
  9535. * @param {object} settings DataTables settings object
  9536. * @returns {boolean} False will cancel the draw, anything else (including no
  9537. * return) will allow it to complete.
  9538. *
  9539. * @dtopt Callbacks
  9540. * @name DataTable.defaults.preDrawCallback
  9541. *
  9542. * @example
  9543. * $(document).ready( function() {
  9544. * $('#example').dataTable( {
  9545. * "preDrawCallback": function( settings ) {
  9546. * if ( $('#test').val() == 1 ) {
  9547. * return false;
  9548. * }
  9549. * }
  9550. * } );
  9551. * } );
  9552. */
  9553. "fnPreDrawCallback": null,
  9554. /**
  9555. * This function allows you to 'post process' each row after it have been
  9556. * generated for each table draw, but before it is rendered on screen. This
  9557. * function might be used for setting the row class name etc.
  9558. * @type function
  9559. * @param {node} row "TR" element for the current row
  9560. * @param {array} data Raw data array for this row
  9561. * @param {int} displayIndex The display index for the current table draw
  9562. * @param {int} displayIndexFull The index of the data in the full list of
  9563. * rows (after filtering)
  9564. *
  9565. * @dtopt Callbacks
  9566. * @name DataTable.defaults.rowCallback
  9567. *
  9568. * @example
  9569. * $(document).ready( function() {
  9570. * $('#example').dataTable( {
  9571. * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
  9572. * // Bold the grade for all 'A' grade browsers
  9573. * if ( data[4] == "A" ) {
  9574. * $('td:eq(4)', row).html( '<b>A</b>' );
  9575. * }
  9576. * }
  9577. * } );
  9578. * } );
  9579. */
  9580. "fnRowCallback": null,
  9581. /**
  9582. * __Deprecated__ The functionality provided by this parameter has now been
  9583. * superseded by that provided through `ajax`, which should be used instead.
  9584. *
  9585. * This parameter allows you to override the default function which obtains
  9586. * the data from the server so something more suitable for your application.
  9587. * For example you could use POST data, or pull information from a Gears or
  9588. * AIR database.
  9589. * @type function
  9590. * @member
  9591. * @param {string} source HTTP source to obtain the data from (`ajax`)
  9592. * @param {array} data A key/value pair object containing the data to send
  9593. * to the server
  9594. * @param {function} callback to be called on completion of the data get
  9595. * process that will draw the data on the page.
  9596. * @param {object} settings DataTables settings object
  9597. *
  9598. * @dtopt Callbacks
  9599. * @dtopt Server-side
  9600. * @name DataTable.defaults.serverData
  9601. *
  9602. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9603. */
  9604. "fnServerData": null,
  9605. /**
  9606. * __Deprecated__ The functionality provided by this parameter has now been
  9607. * superseded by that provided through `ajax`, which should be used instead.
  9608. *
  9609. * It is often useful to send extra data to the server when making an Ajax
  9610. * request - for example custom filtering information, and this callback
  9611. * function makes it trivial to send extra information to the server. The
  9612. * passed in parameter is the data set that has been constructed by
  9613. * DataTables, and you can add to this or modify it as you require.
  9614. * @type function
  9615. * @param {array} data Data array (array of objects which are name/value
  9616. * pairs) that has been constructed by DataTables and will be sent to the
  9617. * server. In the case of Ajax sourced data with server-side processing
  9618. * this will be an empty array, for server-side processing there will be a
  9619. * significant number of parameters!
  9620. * @returns {undefined} Ensure that you modify the data array passed in,
  9621. * as this is passed by reference.
  9622. *
  9623. * @dtopt Callbacks
  9624. * @dtopt Server-side
  9625. * @name DataTable.defaults.serverParams
  9626. *
  9627. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9628. */
  9629. "fnServerParams": null,
  9630. /**
  9631. * Load the table state. With this function you can define from where, and how, the
  9632. * state of a table is loaded. By default DataTables will load from `localStorage`
  9633. * but you might wish to use a server-side database or cookies.
  9634. * @type function
  9635. * @member
  9636. * @param {object} settings DataTables settings object
  9637. * @param {object} callback Callback that can be executed when done. It
  9638. * should be passed the loaded state object.
  9639. * @return {object} The DataTables state object to be loaded
  9640. *
  9641. * @dtopt Callbacks
  9642. * @name DataTable.defaults.stateLoadCallback
  9643. *
  9644. * @example
  9645. * $(document).ready( function() {
  9646. * $('#example').dataTable( {
  9647. * "stateSave": true,
  9648. * "stateLoadCallback": function (settings, callback) {
  9649. * $.ajax( {
  9650. * "url": "/state_load",
  9651. * "dataType": "json",
  9652. * "success": function (json) {
  9653. * callback( json );
  9654. * }
  9655. * } );
  9656. * }
  9657. * } );
  9658. * } );
  9659. */
  9660. "fnStateLoadCallback": function ( settings ) {
  9661. try {
  9662. return JSON.parse(
  9663. (settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
  9664. 'DataTables_'+settings.sInstance+'_'+location.pathname
  9665. )
  9666. );
  9667. } catch (e) {
  9668. return {};
  9669. }
  9670. },
  9671. /**
  9672. * Callback which allows modification of the saved state prior to loading that state.
  9673. * This callback is called when the table is loading state from the stored data, but
  9674. * prior to the settings object being modified by the saved state. Note that for
  9675. * plug-in authors, you should use the `stateLoadParams` event to load parameters for
  9676. * a plug-in.
  9677. * @type function
  9678. * @param {object} settings DataTables settings object
  9679. * @param {object} data The state object that is to be loaded
  9680. *
  9681. * @dtopt Callbacks
  9682. * @name DataTable.defaults.stateLoadParams
  9683. *
  9684. * @example
  9685. * // Remove a saved filter, so filtering is never loaded
  9686. * $(document).ready( function() {
  9687. * $('#example').dataTable( {
  9688. * "stateSave": true,
  9689. * "stateLoadParams": function (settings, data) {
  9690. * data.oSearch.sSearch = "";
  9691. * }
  9692. * } );
  9693. * } );
  9694. *
  9695. * @example
  9696. * // Disallow state loading by returning false
  9697. * $(document).ready( function() {
  9698. * $('#example').dataTable( {
  9699. * "stateSave": true,
  9700. * "stateLoadParams": function (settings, data) {
  9701. * return false;
  9702. * }
  9703. * } );
  9704. * } );
  9705. */
  9706. "fnStateLoadParams": null,
  9707. /**
  9708. * Callback that is called when the state has been loaded from the state saving method
  9709. * and the DataTables settings object has been modified as a result of the loaded state.
  9710. * @type function
  9711. * @param {object} settings DataTables settings object
  9712. * @param {object} data The state object that was loaded
  9713. *
  9714. * @dtopt Callbacks
  9715. * @name DataTable.defaults.stateLoaded
  9716. *
  9717. * @example
  9718. * // Show an alert with the filtering value that was saved
  9719. * $(document).ready( function() {
  9720. * $('#example').dataTable( {
  9721. * "stateSave": true,
  9722. * "stateLoaded": function (settings, data) {
  9723. * alert( 'Saved filter was: '+data.oSearch.sSearch );
  9724. * }
  9725. * } );
  9726. * } );
  9727. */
  9728. "fnStateLoaded": null,
  9729. /**
  9730. * Save the table state. This function allows you to define where and how the state
  9731. * information for the table is stored By default DataTables will use `localStorage`
  9732. * but you might wish to use a server-side database or cookies.
  9733. * @type function
  9734. * @member
  9735. * @param {object} settings DataTables settings object
  9736. * @param {object} data The state object to be saved
  9737. *
  9738. * @dtopt Callbacks
  9739. * @name DataTable.defaults.stateSaveCallback
  9740. *
  9741. * @example
  9742. * $(document).ready( function() {
  9743. * $('#example').dataTable( {
  9744. * "stateSave": true,
  9745. * "stateSaveCallback": function (settings, data) {
  9746. * // Send an Ajax request to the server with the state object
  9747. * $.ajax( {
  9748. * "url": "/state_save",
  9749. * "data": data,
  9750. * "dataType": "json",
  9751. * "method": "POST"
  9752. * "success": function () {}
  9753. * } );
  9754. * }
  9755. * } );
  9756. * } );
  9757. */
  9758. "fnStateSaveCallback": function ( settings, data ) {
  9759. try {
  9760. (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
  9761. 'DataTables_'+settings.sInstance+'_'+location.pathname,
  9762. JSON.stringify( data )
  9763. );
  9764. } catch (e) {}
  9765. },
  9766. /**
  9767. * Callback which allows modification of the state to be saved. Called when the table
  9768. * has changed state a new state save is required. This method allows modification of
  9769. * the state saving object prior to actually doing the save, including addition or
  9770. * other state properties or modification. Note that for plug-in authors, you should
  9771. * use the `stateSaveParams` event to save parameters for a plug-in.
  9772. * @type function
  9773. * @param {object} settings DataTables settings object
  9774. * @param {object} data The state object to be saved
  9775. *
  9776. * @dtopt Callbacks
  9777. * @name DataTable.defaults.stateSaveParams
  9778. *
  9779. * @example
  9780. * // Remove a saved filter, so filtering is never saved
  9781. * $(document).ready( function() {
  9782. * $('#example').dataTable( {
  9783. * "stateSave": true,
  9784. * "stateSaveParams": function (settings, data) {
  9785. * data.oSearch.sSearch = "";
  9786. * }
  9787. * } );
  9788. * } );
  9789. */
  9790. "fnStateSaveParams": null,
  9791. /**
  9792. * Duration for which the saved state information is considered valid. After this period
  9793. * has elapsed the state will be returned to the default.
  9794. * Value is given in seconds.
  9795. * @type int
  9796. * @default 7200 <i>(2 hours)</i>
  9797. *
  9798. * @dtopt Options
  9799. * @name DataTable.defaults.stateDuration
  9800. *
  9801. * @example
  9802. * $(document).ready( function() {
  9803. * $('#example').dataTable( {
  9804. * "stateDuration": 60*60*24; // 1 day
  9805. * } );
  9806. * } )
  9807. */
  9808. "iStateDuration": 7200,
  9809. /**
  9810. * When enabled DataTables will not make a request to the server for the first
  9811. * page draw - rather it will use the data already on the page (no sorting etc
  9812. * will be applied to it), thus saving on an XHR at load time. `deferLoading`
  9813. * is used to indicate that deferred loading is required, but it is also used
  9814. * to tell DataTables how many records there are in the full table (allowing
  9815. * the information element and pagination to be displayed correctly). In the case
  9816. * where a filtering is applied to the table on initial load, this can be
  9817. * indicated by giving the parameter as an array, where the first element is
  9818. * the number of records available after filtering and the second element is the
  9819. * number of records without filtering (allowing the table information element
  9820. * to be shown correctly).
  9821. * @type int | array
  9822. * @default null
  9823. *
  9824. * @dtopt Options
  9825. * @name DataTable.defaults.deferLoading
  9826. *
  9827. * @example
  9828. * // 57 records available in the table, no filtering applied
  9829. * $(document).ready( function() {
  9830. * $('#example').dataTable( {
  9831. * "serverSide": true,
  9832. * "ajax": "scripts/server_processing.php",
  9833. * "deferLoading": 57
  9834. * } );
  9835. * } );
  9836. *
  9837. * @example
  9838. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  9839. * $(document).ready( function() {
  9840. * $('#example').dataTable( {
  9841. * "serverSide": true,
  9842. * "ajax": "scripts/server_processing.php",
  9843. * "deferLoading": [ 57, 100 ],
  9844. * "search": {
  9845. * "search": "my_filter"
  9846. * }
  9847. * } );
  9848. * } );
  9849. */
  9850. "iDeferLoading": null,
  9851. /**
  9852. * Number of rows to display on a single page when using pagination. If
  9853. * feature enabled (`lengthChange`) then the end user will be able to override
  9854. * this to a custom setting using a pop-up menu.
  9855. * @type int
  9856. * @default 10
  9857. *
  9858. * @dtopt Options
  9859. * @name DataTable.defaults.pageLength
  9860. *
  9861. * @example
  9862. * $(document).ready( function() {
  9863. * $('#example').dataTable( {
  9864. * "pageLength": 50
  9865. * } );
  9866. * } )
  9867. */
  9868. "iDisplayLength": 10,
  9869. /**
  9870. * Define the starting point for data display when using DataTables with
  9871. * pagination. Note that this parameter is the number of records, rather than
  9872. * the page number, so if you have 10 records per page and want to start on
  9873. * the third page, it should be "20".
  9874. * @type int
  9875. * @default 0
  9876. *
  9877. * @dtopt Options
  9878. * @name DataTable.defaults.displayStart
  9879. *
  9880. * @example
  9881. * $(document).ready( function() {
  9882. * $('#example').dataTable( {
  9883. * "displayStart": 20
  9884. * } );
  9885. * } )
  9886. */
  9887. "iDisplayStart": 0,
  9888. /**
  9889. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  9890. * and filtering) by adding a `tabindex` attribute to the required elements. This
  9891. * allows you to tab through the controls and press the enter key to activate them.
  9892. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  9893. * You can overrule this using this parameter if you wish. Use a value of -1 to
  9894. * disable built-in keyboard navigation.
  9895. * @type int
  9896. * @default 0
  9897. *
  9898. * @dtopt Options
  9899. * @name DataTable.defaults.tabIndex
  9900. *
  9901. * @example
  9902. * $(document).ready( function() {
  9903. * $('#example').dataTable( {
  9904. * "tabIndex": 1
  9905. * } );
  9906. * } );
  9907. */
  9908. "iTabIndex": 0,
  9909. /**
  9910. * Classes that DataTables assigns to the various components and features
  9911. * that it adds to the HTML table. This allows classes to be configured
  9912. * during initialisation in addition to through the static
  9913. * {@link DataTable.ext.oStdClasses} object).
  9914. * @namespace
  9915. * @name DataTable.defaults.classes
  9916. */
  9917. "oClasses": {},
  9918. /**
  9919. * All strings that DataTables uses in the user interface that it creates
  9920. * are defined in this object, allowing you to modified them individually or
  9921. * completely replace them all as required.
  9922. * @namespace
  9923. * @name DataTable.defaults.language
  9924. */
  9925. "oLanguage": {
  9926. /**
  9927. * Strings that are used for WAI-ARIA labels and controls only (these are not
  9928. * actually visible on the page, but will be read by screenreaders, and thus
  9929. * must be internationalised as well).
  9930. * @namespace
  9931. * @name DataTable.defaults.language.aria
  9932. */
  9933. "oAria": {
  9934. /**
  9935. * ARIA label that is added to the table headers when the column may be
  9936. * sorted ascending by activing the column (click or return when focused).
  9937. * Note that the column header is prefixed to this string.
  9938. * @type string
  9939. * @default : activate to sort column ascending
  9940. *
  9941. * @dtopt Language
  9942. * @name DataTable.defaults.language.aria.sortAscending
  9943. *
  9944. * @example
  9945. * $(document).ready( function() {
  9946. * $('#example').dataTable( {
  9947. * "language": {
  9948. * "aria": {
  9949. * "sortAscending": " - click/return to sort ascending"
  9950. * }
  9951. * }
  9952. * } );
  9953. * } );
  9954. */
  9955. "sSortAscending": ": activate to sort column ascending",
  9956. /**
  9957. * ARIA label that is added to the table headers when the column may be
  9958. * sorted descending by activing the column (click or return when focused).
  9959. * Note that the column header is prefixed to this string.
  9960. * @type string
  9961. * @default : activate to sort column ascending
  9962. *
  9963. * @dtopt Language
  9964. * @name DataTable.defaults.language.aria.sortDescending
  9965. *
  9966. * @example
  9967. * $(document).ready( function() {
  9968. * $('#example').dataTable( {
  9969. * "language": {
  9970. * "aria": {
  9971. * "sortDescending": " - click/return to sort descending"
  9972. * }
  9973. * }
  9974. * } );
  9975. * } );
  9976. */
  9977. "sSortDescending": ": activate to sort column descending"
  9978. },
  9979. /**
  9980. * Pagination string used by DataTables for the built-in pagination
  9981. * control types.
  9982. * @namespace
  9983. * @name DataTable.defaults.language.paginate
  9984. */
  9985. "oPaginate": {
  9986. /**
  9987. * Text to use when using the 'full_numbers' type of pagination for the
  9988. * button to take the user to the first page.
  9989. * @type string
  9990. * @default First
  9991. *
  9992. * @dtopt Language
  9993. * @name DataTable.defaults.language.paginate.first
  9994. *
  9995. * @example
  9996. * $(document).ready( function() {
  9997. * $('#example').dataTable( {
  9998. * "language": {
  9999. * "paginate": {
  10000. * "first": "First page"
  10001. * }
  10002. * }
  10003. * } );
  10004. * } );
  10005. */
  10006. "sFirst": "First",
  10007. /**
  10008. * Text to use when using the 'full_numbers' type of pagination for the
  10009. * button to take the user to the last page.
  10010. * @type string
  10011. * @default Last
  10012. *
  10013. * @dtopt Language
  10014. * @name DataTable.defaults.language.paginate.last
  10015. *
  10016. * @example
  10017. * $(document).ready( function() {
  10018. * $('#example').dataTable( {
  10019. * "language": {
  10020. * "paginate": {
  10021. * "last": "Last page"
  10022. * }
  10023. * }
  10024. * } );
  10025. * } );
  10026. */
  10027. "sLast": "Last",
  10028. /**
  10029. * Text to use for the 'next' pagination button (to take the user to the
  10030. * next page).
  10031. * @type string
  10032. * @default Next
  10033. *
  10034. * @dtopt Language
  10035. * @name DataTable.defaults.language.paginate.next
  10036. *
  10037. * @example
  10038. * $(document).ready( function() {
  10039. * $('#example').dataTable( {
  10040. * "language": {
  10041. * "paginate": {
  10042. * "next": "Next page"
  10043. * }
  10044. * }
  10045. * } );
  10046. * } );
  10047. */
  10048. "sNext": "Next",
  10049. /**
  10050. * Text to use for the 'previous' pagination button (to take the user to
  10051. * the previous page).
  10052. * @type string
  10053. * @default Previous
  10054. *
  10055. * @dtopt Language
  10056. * @name DataTable.defaults.language.paginate.previous
  10057. *
  10058. * @example
  10059. * $(document).ready( function() {
  10060. * $('#example').dataTable( {
  10061. * "language": {
  10062. * "paginate": {
  10063. * "previous": "Previous page"
  10064. * }
  10065. * }
  10066. * } );
  10067. * } );
  10068. */
  10069. "sPrevious": "Previous"
  10070. },
  10071. /**
  10072. * This string is shown in preference to `zeroRecords` when the table is
  10073. * empty of data (regardless of filtering). Note that this is an optional
  10074. * parameter - if it is not given, the value of `zeroRecords` will be used
  10075. * instead (either the default or given value).
  10076. * @type string
  10077. * @default No data available in table
  10078. *
  10079. * @dtopt Language
  10080. * @name DataTable.defaults.language.emptyTable
  10081. *
  10082. * @example
  10083. * $(document).ready( function() {
  10084. * $('#example').dataTable( {
  10085. * "language": {
  10086. * "emptyTable": "No data available in table"
  10087. * }
  10088. * } );
  10089. * } );
  10090. */
  10091. "sEmptyTable": "No data available in table",
  10092. /**
  10093. * This string gives information to the end user about the information
  10094. * that is current on display on the page. The following tokens can be
  10095. * used in the string and will be dynamically replaced as the table
  10096. * display updates. This tokens can be placed anywhere in the string, or
  10097. * removed as needed by the language requires:
  10098. *
  10099. * * `\_START\_` - Display index of the first record on the current page
  10100. * * `\_END\_` - Display index of the last record on the current page
  10101. * * `\_TOTAL\_` - Number of records in the table after filtering
  10102. * * `\_MAX\_` - Number of records in the table without filtering
  10103. * * `\_PAGE\_` - Current page number
  10104. * * `\_PAGES\_` - Total number of pages of data in the table
  10105. *
  10106. * @type string
  10107. * @default Showing _START_ to _END_ of _TOTAL_ entries
  10108. *
  10109. * @dtopt Language
  10110. * @name DataTable.defaults.language.info
  10111. *
  10112. * @example
  10113. * $(document).ready( function() {
  10114. * $('#example').dataTable( {
  10115. * "language": {
  10116. * "info": "Showing page _PAGE_ of _PAGES_"
  10117. * }
  10118. * } );
  10119. * } );
  10120. */
  10121. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  10122. /**
  10123. * Display information string for when the table is empty. Typically the
  10124. * format of this string should match `info`.
  10125. * @type string
  10126. * @default Showing 0 to 0 of 0 entries
  10127. *
  10128. * @dtopt Language
  10129. * @name DataTable.defaults.language.infoEmpty
  10130. *
  10131. * @example
  10132. * $(document).ready( function() {
  10133. * $('#example').dataTable( {
  10134. * "language": {
  10135. * "infoEmpty": "No entries to show"
  10136. * }
  10137. * } );
  10138. * } );
  10139. */
  10140. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  10141. /**
  10142. * When a user filters the information in a table, this string is appended
  10143. * to the information (`info`) to give an idea of how strong the filtering
  10144. * is. The variable _MAX_ is dynamically updated.
  10145. * @type string
  10146. * @default (filtered from _MAX_ total entries)
  10147. *
  10148. * @dtopt Language
  10149. * @name DataTable.defaults.language.infoFiltered
  10150. *
  10151. * @example
  10152. * $(document).ready( function() {
  10153. * $('#example').dataTable( {
  10154. * "language": {
  10155. * "infoFiltered": " - filtering from _MAX_ records"
  10156. * }
  10157. * } );
  10158. * } );
  10159. */
  10160. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  10161. /**
  10162. * If can be useful to append extra information to the info string at times,
  10163. * and this variable does exactly that. This information will be appended to
  10164. * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
  10165. * being used) at all times.
  10166. * @type string
  10167. * @default <i>Empty string</i>
  10168. *
  10169. * @dtopt Language
  10170. * @name DataTable.defaults.language.infoPostFix
  10171. *
  10172. * @example
  10173. * $(document).ready( function() {
  10174. * $('#example').dataTable( {
  10175. * "language": {
  10176. * "infoPostFix": "All records shown are derived from real information."
  10177. * }
  10178. * } );
  10179. * } );
  10180. */
  10181. "sInfoPostFix": "",
  10182. /**
  10183. * This decimal place operator is a little different from the other
  10184. * language options since DataTables doesn't output floating point
  10185. * numbers, so it won't ever use this for display of a number. Rather,
  10186. * what this parameter does is modify the sort methods of the table so
  10187. * that numbers which are in a format which has a character other than
  10188. * a period (`.`) as a decimal place will be sorted numerically.
  10189. *
  10190. * Note that numbers with different decimal places cannot be shown in
  10191. * the same table and still be sortable, the table must be consistent.
  10192. * However, multiple different tables on the page can use different
  10193. * decimal place characters.
  10194. * @type string
  10195. * @default
  10196. *
  10197. * @dtopt Language
  10198. * @name DataTable.defaults.language.decimal
  10199. *
  10200. * @example
  10201. * $(document).ready( function() {
  10202. * $('#example').dataTable( {
  10203. * "language": {
  10204. * "decimal": ","
  10205. * "thousands": "."
  10206. * }
  10207. * } );
  10208. * } );
  10209. */
  10210. "sDecimal": "",
  10211. /**
  10212. * DataTables has a build in number formatter (`formatNumber`) which is
  10213. * used to format large numbers that are used in the table information.
  10214. * By default a comma is used, but this can be trivially changed to any
  10215. * character you wish with this parameter.
  10216. * @type string
  10217. * @default ,
  10218. *
  10219. * @dtopt Language
  10220. * @name DataTable.defaults.language.thousands
  10221. *
  10222. * @example
  10223. * $(document).ready( function() {
  10224. * $('#example').dataTable( {
  10225. * "language": {
  10226. * "thousands": "'"
  10227. * }
  10228. * } );
  10229. * } );
  10230. */
  10231. "sThousands": ",",
  10232. /**
  10233. * Detail the action that will be taken when the drop down menu for the
  10234. * pagination length option is changed. The '_MENU_' variable is replaced
  10235. * with a default select list of 10, 25, 50 and 100, and can be replaced
  10236. * with a custom select box if required.
  10237. * @type string
  10238. * @default Show _MENU_ entries
  10239. *
  10240. * @dtopt Language
  10241. * @name DataTable.defaults.language.lengthMenu
  10242. *
  10243. * @example
  10244. * // Language change only
  10245. * $(document).ready( function() {
  10246. * $('#example').dataTable( {
  10247. * "language": {
  10248. * "lengthMenu": "Display _MENU_ records"
  10249. * }
  10250. * } );
  10251. * } );
  10252. *
  10253. * @example
  10254. * // Language and options change
  10255. * $(document).ready( function() {
  10256. * $('#example').dataTable( {
  10257. * "language": {
  10258. * "lengthMenu": 'Display <select>'+
  10259. * '<option value="10">10</option>'+
  10260. * '<option value="20">20</option>'+
  10261. * '<option value="30">30</option>'+
  10262. * '<option value="40">40</option>'+
  10263. * '<option value="50">50</option>'+
  10264. * '<option value="-1">All</option>'+
  10265. * '</select> records'
  10266. * }
  10267. * } );
  10268. * } );
  10269. */
  10270. "sLengthMenu": "Show _MENU_ entries",
  10271. /**
  10272. * When using Ajax sourced data and during the first draw when DataTables is
  10273. * gathering the data, this message is shown in an empty row in the table to
  10274. * indicate to the end user the the data is being loaded. Note that this
  10275. * parameter is not used when loading data by server-side processing, just
  10276. * Ajax sourced data with client-side processing.
  10277. * @type string
  10278. * @default Loading...
  10279. *
  10280. * @dtopt Language
  10281. * @name DataTable.defaults.language.loadingRecords
  10282. *
  10283. * @example
  10284. * $(document).ready( function() {
  10285. * $('#example').dataTable( {
  10286. * "language": {
  10287. * "loadingRecords": "Please wait - loading..."
  10288. * }
  10289. * } );
  10290. * } );
  10291. */
  10292. "sLoadingRecords": "Loading...",
  10293. /**
  10294. * Text which is displayed when the table is processing a user action
  10295. * (usually a sort command or similar).
  10296. * @type string
  10297. *
  10298. * @dtopt Language
  10299. * @name DataTable.defaults.language.processing
  10300. *
  10301. * @example
  10302. * $(document).ready( function() {
  10303. * $('#example').dataTable( {
  10304. * "language": {
  10305. * "processing": "DataTables is currently busy"
  10306. * }
  10307. * } );
  10308. * } );
  10309. */
  10310. "sProcessing": "",
  10311. /**
  10312. * Details the actions that will be taken when the user types into the
  10313. * filtering input text box. The variable "_INPUT_", if used in the string,
  10314. * is replaced with the HTML text box for the filtering input allowing
  10315. * control over where it appears in the string. If "_INPUT_" is not given
  10316. * then the input box is appended to the string automatically.
  10317. * @type string
  10318. * @default Search:
  10319. *
  10320. * @dtopt Language
  10321. * @name DataTable.defaults.language.search
  10322. *
  10323. * @example
  10324. * // Input text box will be appended at the end automatically
  10325. * $(document).ready( function() {
  10326. * $('#example').dataTable( {
  10327. * "language": {
  10328. * "search": "Filter records:"
  10329. * }
  10330. * } );
  10331. * } );
  10332. *
  10333. * @example
  10334. * // Specify where the filter should appear
  10335. * $(document).ready( function() {
  10336. * $('#example').dataTable( {
  10337. * "language": {
  10338. * "search": "Apply filter _INPUT_ to table"
  10339. * }
  10340. * } );
  10341. * } );
  10342. */
  10343. "sSearch": "Search:",
  10344. /**
  10345. * Assign a `placeholder` attribute to the search `input` element
  10346. * @type string
  10347. * @default
  10348. *
  10349. * @dtopt Language
  10350. * @name DataTable.defaults.language.searchPlaceholder
  10351. */
  10352. "sSearchPlaceholder": "",
  10353. /**
  10354. * All of the language information can be stored in a file on the
  10355. * server-side, which DataTables will look up if this parameter is passed.
  10356. * It must store the URL of the language file, which is in a JSON format,
  10357. * and the object has the same properties as the oLanguage object in the
  10358. * initialiser object (i.e. the above parameters). Please refer to one of
  10359. * the example language files to see how this works in action.
  10360. * @type string
  10361. * @default <i>Empty string - i.e. disabled</i>
  10362. *
  10363. * @dtopt Language
  10364. * @name DataTable.defaults.language.url
  10365. *
  10366. * @example
  10367. * $(document).ready( function() {
  10368. * $('#example').dataTable( {
  10369. * "language": {
  10370. * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  10371. * }
  10372. * } );
  10373. * } );
  10374. */
  10375. "sUrl": "",
  10376. /**
  10377. * Text shown inside the table records when the is no information to be
  10378. * displayed after filtering. `emptyTable` is shown when there is simply no
  10379. * information in the table at all (regardless of filtering).
  10380. * @type string
  10381. * @default No matching records found
  10382. *
  10383. * @dtopt Language
  10384. * @name DataTable.defaults.language.zeroRecords
  10385. *
  10386. * @example
  10387. * $(document).ready( function() {
  10388. * $('#example').dataTable( {
  10389. * "language": {
  10390. * "zeroRecords": "No records to display"
  10391. * }
  10392. * } );
  10393. * } );
  10394. */
  10395. "sZeroRecords": "No matching records found"
  10396. },
  10397. /**
  10398. * This parameter allows you to have define the global filtering state at
  10399. * initialisation time. As an object the `search` parameter must be
  10400. * defined, but all other parameters are optional. When `regex` is true,
  10401. * the search string will be treated as a regular expression, when false
  10402. * (default) it will be treated as a straight string. When `smart`
  10403. * DataTables will use it's smart filtering methods (to word match at
  10404. * any point in the data), when false this will not be done.
  10405. * @namespace
  10406. * @extends DataTable.models.oSearch
  10407. *
  10408. * @dtopt Options
  10409. * @name DataTable.defaults.search
  10410. *
  10411. * @example
  10412. * $(document).ready( function() {
  10413. * $('#example').dataTable( {
  10414. * "search": {"search": "Initial search"}
  10415. * } );
  10416. * } )
  10417. */
  10418. "oSearch": $.extend( {}, DataTable.models.oSearch ),
  10419. /**
  10420. * __Deprecated__ The functionality provided by this parameter has now been
  10421. * superseded by that provided through `ajax`, which should be used instead.
  10422. *
  10423. * By default DataTables will look for the property `data` (or `aaData` for
  10424. * compatibility with DataTables 1.9-) when obtaining data from an Ajax
  10425. * source or for server-side processing - this parameter allows that
  10426. * property to be changed. You can use Javascript dotted object notation to
  10427. * get a data source for multiple levels of nesting.
  10428. * @type string
  10429. * @default data
  10430. *
  10431. * @dtopt Options
  10432. * @dtopt Server-side
  10433. * @name DataTable.defaults.ajaxDataProp
  10434. *
  10435. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10436. */
  10437. "sAjaxDataProp": "data",
  10438. /**
  10439. * __Deprecated__ The functionality provided by this parameter has now been
  10440. * superseded by that provided through `ajax`, which should be used instead.
  10441. *
  10442. * You can instruct DataTables to load data from an external
  10443. * source using this parameter (use aData if you want to pass data in you
  10444. * already have). Simply provide a url a JSON object can be obtained from.
  10445. * @type string
  10446. * @default null
  10447. *
  10448. * @dtopt Options
  10449. * @dtopt Server-side
  10450. * @name DataTable.defaults.ajaxSource
  10451. *
  10452. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10453. */
  10454. "sAjaxSource": null,
  10455. /**
  10456. * This initialisation variable allows you to specify exactly where in the
  10457. * DOM you want DataTables to inject the various controls it adds to the page
  10458. * (for example you might want the pagination controls at the top of the
  10459. * table). DIV elements (with or without a custom class) can also be added to
  10460. * aid styling. The follow syntax is used:
  10461. * <ul>
  10462. * <li>The following options are allowed:
  10463. * <ul>
  10464. * <li>'l' - Length changing</li>
  10465. * <li>'f' - Filtering input</li>
  10466. * <li>'t' - The table!</li>
  10467. * <li>'i' - Information</li>
  10468. * <li>'p' - Pagination</li>
  10469. * <li>'r' - pRocessing</li>
  10470. * </ul>
  10471. * </li>
  10472. * <li>The following constants are allowed:
  10473. * <ul>
  10474. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  10475. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  10476. * </ul>
  10477. * </li>
  10478. * <li>The following syntax is expected:
  10479. * <ul>
  10480. * <li>'&lt;' and '&gt;' - div elements</li>
  10481. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  10482. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  10483. * </ul>
  10484. * </li>
  10485. * <li>Examples:
  10486. * <ul>
  10487. * <li>'&lt;"wrapper"flipt&gt;'</li>
  10488. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  10489. * </ul>
  10490. * </li>
  10491. * </ul>
  10492. * @type string
  10493. * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
  10494. * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
  10495. *
  10496. * @dtopt Options
  10497. * @name DataTable.defaults.dom
  10498. *
  10499. * @example
  10500. * $(document).ready( function() {
  10501. * $('#example').dataTable( {
  10502. * "dom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&gt;'
  10503. * } );
  10504. * } );
  10505. */
  10506. "sDom": "lfrtip",
  10507. /**
  10508. * Search delay option. This will throttle full table searches that use the
  10509. * DataTables provided search input element (it does not effect calls to
  10510. * `dt-api search()`, providing a delay before the search is made.
  10511. * @type integer
  10512. * @default 0
  10513. *
  10514. * @dtopt Options
  10515. * @name DataTable.defaults.searchDelay
  10516. *
  10517. * @example
  10518. * $(document).ready( function() {
  10519. * $('#example').dataTable( {
  10520. * "searchDelay": 200
  10521. * } );
  10522. * } )
  10523. */
  10524. "searchDelay": null,
  10525. /**
  10526. * DataTables features six different built-in options for the buttons to
  10527. * display for pagination control:
  10528. *
  10529. * * `numbers` - Page number buttons only
  10530. * * `simple` - 'Previous' and 'Next' buttons only
  10531. * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
  10532. * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
  10533. * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers
  10534. * * `first_last_numbers` - 'First' and 'Last' buttons, plus page numbers
  10535. *
  10536. * Further methods can be added using {@link DataTable.ext.oPagination}.
  10537. * @type string
  10538. * @default simple_numbers
  10539. *
  10540. * @dtopt Options
  10541. * @name DataTable.defaults.pagingType
  10542. *
  10543. * @example
  10544. * $(document).ready( function() {
  10545. * $('#example').dataTable( {
  10546. * "pagingType": "full_numbers"
  10547. * } );
  10548. * } )
  10549. */
  10550. "sPaginationType": "simple_numbers",
  10551. /**
  10552. * Enable horizontal scrolling. When a table is too wide to fit into a
  10553. * certain layout, or you have a large number of columns in the table, you
  10554. * can enable x-scrolling to show the table in a viewport, which can be
  10555. * scrolled. This property can be `true` which will allow the table to
  10556. * scroll horizontally when needed, or any CSS unit, or a number (in which
  10557. * case it will be treated as a pixel measurement). Setting as simply `true`
  10558. * is recommended.
  10559. * @type boolean|string
  10560. * @default <i>blank string - i.e. disabled</i>
  10561. *
  10562. * @dtopt Features
  10563. * @name DataTable.defaults.scrollX
  10564. *
  10565. * @example
  10566. * $(document).ready( function() {
  10567. * $('#example').dataTable( {
  10568. * "scrollX": true,
  10569. * "scrollCollapse": true
  10570. * } );
  10571. * } );
  10572. */
  10573. "sScrollX": "",
  10574. /**
  10575. * This property can be used to force a DataTable to use more width than it
  10576. * might otherwise do when x-scrolling is enabled. For example if you have a
  10577. * table which requires to be well spaced, this parameter is useful for
  10578. * "over-sizing" the table, and thus forcing scrolling. This property can by
  10579. * any CSS unit, or a number (in which case it will be treated as a pixel
  10580. * measurement).
  10581. * @type string
  10582. * @default <i>blank string - i.e. disabled</i>
  10583. *
  10584. * @dtopt Options
  10585. * @name DataTable.defaults.scrollXInner
  10586. *
  10587. * @example
  10588. * $(document).ready( function() {
  10589. * $('#example').dataTable( {
  10590. * "scrollX": "100%",
  10591. * "scrollXInner": "110%"
  10592. * } );
  10593. * } );
  10594. */
  10595. "sScrollXInner": "",
  10596. /**
  10597. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  10598. * to the given height, and enable scrolling for any data which overflows the
  10599. * current viewport. This can be used as an alternative to paging to display
  10600. * a lot of data in a small area (although paging and scrolling can both be
  10601. * enabled at the same time). This property can be any CSS unit, or a number
  10602. * (in which case it will be treated as a pixel measurement).
  10603. * @type string
  10604. * @default <i>blank string - i.e. disabled</i>
  10605. *
  10606. * @dtopt Features
  10607. * @name DataTable.defaults.scrollY
  10608. *
  10609. * @example
  10610. * $(document).ready( function() {
  10611. * $('#example').dataTable( {
  10612. * "scrollY": "200px",
  10613. * "paginate": false
  10614. * } );
  10615. * } );
  10616. */
  10617. "sScrollY": "",
  10618. /**
  10619. * __Deprecated__ The functionality provided by this parameter has now been
  10620. * superseded by that provided through `ajax`, which should be used instead.
  10621. *
  10622. * Set the HTTP method that is used to make the Ajax call for server-side
  10623. * processing or Ajax sourced data.
  10624. * @type string
  10625. * @default GET
  10626. *
  10627. * @dtopt Options
  10628. * @dtopt Server-side
  10629. * @name DataTable.defaults.serverMethod
  10630. *
  10631. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10632. */
  10633. "sServerMethod": "GET",
  10634. /**
  10635. * DataTables makes use of renderers when displaying HTML elements for
  10636. * a table. These renderers can be added or modified by plug-ins to
  10637. * generate suitable mark-up for a site. For example the Bootstrap
  10638. * integration plug-in for DataTables uses a paging button renderer to
  10639. * display pagination buttons in the mark-up required by Bootstrap.
  10640. *
  10641. * For further information about the renderers available see
  10642. * DataTable.ext.renderer
  10643. * @type string|object
  10644. * @default null
  10645. *
  10646. * @name DataTable.defaults.renderer
  10647. *
  10648. */
  10649. "renderer": null,
  10650. /**
  10651. * Set the data property name that DataTables should use to get a row's id
  10652. * to set as the `id` property in the node.
  10653. * @type string
  10654. * @default DT_RowId
  10655. *
  10656. * @name DataTable.defaults.rowId
  10657. */
  10658. "rowId": "DT_RowId"
  10659. };
  10660. _fnHungarianMap( DataTable.defaults );
  10661. /*
  10662. * Developer note - See note in model.defaults.js about the use of Hungarian
  10663. * notation and camel case.
  10664. */
  10665. /**
  10666. * Column options that can be given to DataTables at initialisation time.
  10667. * @namespace
  10668. */
  10669. DataTable.defaults.column = {
  10670. /**
  10671. * Define which column(s) an order will occur on for this column. This
  10672. * allows a column's ordering to take multiple columns into account when
  10673. * doing a sort or use the data from a different column. For example first
  10674. * name / last name columns make sense to do a multi-column sort over the
  10675. * two columns.
  10676. * @type array|int
  10677. * @default null <i>Takes the value of the column index automatically</i>
  10678. *
  10679. * @name DataTable.defaults.column.orderData
  10680. * @dtopt Columns
  10681. *
  10682. * @example
  10683. * // Using `columnDefs`
  10684. * $(document).ready( function() {
  10685. * $('#example').dataTable( {
  10686. * "columnDefs": [
  10687. * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
  10688. * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
  10689. * { "orderData": 2, "targets": [ 2 ] }
  10690. * ]
  10691. * } );
  10692. * } );
  10693. *
  10694. * @example
  10695. * // Using `columns`
  10696. * $(document).ready( function() {
  10697. * $('#example').dataTable( {
  10698. * "columns": [
  10699. * { "orderData": [ 0, 1 ] },
  10700. * { "orderData": [ 1, 0 ] },
  10701. * { "orderData": 2 },
  10702. * null,
  10703. * null
  10704. * ]
  10705. * } );
  10706. * } );
  10707. */
  10708. "aDataSort": null,
  10709. "iDataSort": -1,
  10710. /**
  10711. * You can control the default ordering direction, and even alter the
  10712. * behaviour of the sort handler (i.e. only allow ascending ordering etc)
  10713. * using this parameter.
  10714. * @type array
  10715. * @default [ 'asc', 'desc' ]
  10716. *
  10717. * @name DataTable.defaults.column.orderSequence
  10718. * @dtopt Columns
  10719. *
  10720. * @example
  10721. * // Using `columnDefs`
  10722. * $(document).ready( function() {
  10723. * $('#example').dataTable( {
  10724. * "columnDefs": [
  10725. * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
  10726. * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
  10727. * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
  10728. * ]
  10729. * } );
  10730. * } );
  10731. *
  10732. * @example
  10733. * // Using `columns`
  10734. * $(document).ready( function() {
  10735. * $('#example').dataTable( {
  10736. * "columns": [
  10737. * null,
  10738. * { "orderSequence": [ "asc" ] },
  10739. * { "orderSequence": [ "desc", "asc", "asc" ] },
  10740. * { "orderSequence": [ "desc" ] },
  10741. * null
  10742. * ]
  10743. * } );
  10744. * } );
  10745. */
  10746. "asSorting": [ 'asc', 'desc' ],
  10747. /**
  10748. * Enable or disable filtering on the data in this column.
  10749. * @type boolean
  10750. * @default true
  10751. *
  10752. * @name DataTable.defaults.column.searchable
  10753. * @dtopt Columns
  10754. *
  10755. * @example
  10756. * // Using `columnDefs`
  10757. * $(document).ready( function() {
  10758. * $('#example').dataTable( {
  10759. * "columnDefs": [
  10760. * { "searchable": false, "targets": [ 0 ] }
  10761. * ] } );
  10762. * } );
  10763. *
  10764. * @example
  10765. * // Using `columns`
  10766. * $(document).ready( function() {
  10767. * $('#example').dataTable( {
  10768. * "columns": [
  10769. * { "searchable": false },
  10770. * null,
  10771. * null,
  10772. * null,
  10773. * null
  10774. * ] } );
  10775. * } );
  10776. */
  10777. "bSearchable": true,
  10778. /**
  10779. * Enable or disable ordering on this column.
  10780. * @type boolean
  10781. * @default true
  10782. *
  10783. * @name DataTable.defaults.column.orderable
  10784. * @dtopt Columns
  10785. *
  10786. * @example
  10787. * // Using `columnDefs`
  10788. * $(document).ready( function() {
  10789. * $('#example').dataTable( {
  10790. * "columnDefs": [
  10791. * { "orderable": false, "targets": [ 0 ] }
  10792. * ] } );
  10793. * } );
  10794. *
  10795. * @example
  10796. * // Using `columns`
  10797. * $(document).ready( function() {
  10798. * $('#example').dataTable( {
  10799. * "columns": [
  10800. * { "orderable": false },
  10801. * null,
  10802. * null,
  10803. * null,
  10804. * null
  10805. * ] } );
  10806. * } );
  10807. */
  10808. "bSortable": true,
  10809. /**
  10810. * Enable or disable the display of this column.
  10811. * @type boolean
  10812. * @default true
  10813. *
  10814. * @name DataTable.defaults.column.visible
  10815. * @dtopt Columns
  10816. *
  10817. * @example
  10818. * // Using `columnDefs`
  10819. * $(document).ready( function() {
  10820. * $('#example').dataTable( {
  10821. * "columnDefs": [
  10822. * { "visible": false, "targets": [ 0 ] }
  10823. * ] } );
  10824. * } );
  10825. *
  10826. * @example
  10827. * // Using `columns`
  10828. * $(document).ready( function() {
  10829. * $('#example').dataTable( {
  10830. * "columns": [
  10831. * { "visible": false },
  10832. * null,
  10833. * null,
  10834. * null,
  10835. * null
  10836. * ] } );
  10837. * } );
  10838. */
  10839. "bVisible": true,
  10840. /**
  10841. * Developer definable function that is called whenever a cell is created (Ajax source,
  10842. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  10843. * allowing you to modify the DOM element (add background colour for example) when the
  10844. * element is available.
  10845. * @type function
  10846. * @param {element} td The TD node that has been created
  10847. * @param {*} cellData The Data for the cell
  10848. * @param {array|object} rowData The data for the whole row
  10849. * @param {int} row The row index for the aoData data store
  10850. * @param {int} col The column index for aoColumns
  10851. *
  10852. * @name DataTable.defaults.column.createdCell
  10853. * @dtopt Columns
  10854. *
  10855. * @example
  10856. * $(document).ready( function() {
  10857. * $('#example').dataTable( {
  10858. * "columnDefs": [ {
  10859. * "targets": [3],
  10860. * "createdCell": function (td, cellData, rowData, row, col) {
  10861. * if ( cellData == "1.7" ) {
  10862. * $(td).css('color', 'blue')
  10863. * }
  10864. * }
  10865. * } ]
  10866. * });
  10867. * } );
  10868. */
  10869. "fnCreatedCell": null,
  10870. /**
  10871. * This parameter has been replaced by `data` in DataTables to ensure naming
  10872. * consistency. `dataProp` can still be used, as there is backwards
  10873. * compatibility in DataTables for this option, but it is strongly
  10874. * recommended that you use `data` in preference to `dataProp`.
  10875. * @name DataTable.defaults.column.dataProp
  10876. */
  10877. /**
  10878. * This property can be used to read data from any data source property,
  10879. * including deeply nested objects / properties. `data` can be given in a
  10880. * number of different ways which effect its behaviour:
  10881. *
  10882. * * `integer` - treated as an array index for the data source. This is the
  10883. * default that DataTables uses (incrementally increased for each column).
  10884. * * `string` - read an object property from the data source. There are
  10885. * three 'special' options that can be used in the string to alter how
  10886. * DataTables reads the data from the source object:
  10887. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10888. * Javascript to read from nested objects, so to can the options
  10889. * specified in `data`. For example: `browser.version` or
  10890. * `browser.name`. If your object parameter name contains a period, use
  10891. * `\\` to escape it - i.e. `first\\.name`.
  10892. * * `[]` - Array notation. DataTables can automatically combine data
  10893. * from and array source, joining the data with the characters provided
  10894. * between the two brackets. For example: `name[, ]` would provide a
  10895. * comma-space separated list from the source array. If no characters
  10896. * are provided between the brackets, the original array source is
  10897. * returned.
  10898. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10899. * execute a function of the name given. For example: `browser()` for a
  10900. * simple function on the data source, `browser.version()` for a
  10901. * function in a nested property or even `browser().version` to get an
  10902. * object property if the function called returns an object. Note that
  10903. * function notation is recommended for use in `render` rather than
  10904. * `data` as it is much simpler to use as a renderer.
  10905. * * `null` - use the original data source for the row rather than plucking
  10906. * data directly from it. This action has effects on two other
  10907. * initialisation options:
  10908. * * `defaultContent` - When null is given as the `data` option and
  10909. * `defaultContent` is specified for the column, the value defined by
  10910. * `defaultContent` will be used for the cell.
  10911. * * `render` - When null is used for the `data` option and the `render`
  10912. * option is specified for the column, the whole data source for the
  10913. * row is used for the renderer.
  10914. * * `function` - the function given will be executed whenever DataTables
  10915. * needs to set or get the data for a cell in the column. The function
  10916. * takes three parameters:
  10917. * * Parameters:
  10918. * * `{array|object}` The data source for the row
  10919. * * `{string}` The type call data requested - this will be 'set' when
  10920. * setting data or 'filter', 'display', 'type', 'sort' or undefined
  10921. * when gathering data. Note that when `undefined` is given for the
  10922. * type DataTables expects to get the raw data for the object back<
  10923. * * `{*}` Data to set when the second parameter is 'set'.
  10924. * * Return:
  10925. * * The return value from the function is not required when 'set' is
  10926. * the type of call, but otherwise the return is what will be used
  10927. * for the data requested.
  10928. *
  10929. * Note that `data` is a getter and setter option. If you just require
  10930. * formatting of data for output, you will likely want to use `render` which
  10931. * is simply a getter and thus simpler to use.
  10932. *
  10933. * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
  10934. * name change reflects the flexibility of this property and is consistent
  10935. * with the naming of mRender. If 'mDataProp' is given, then it will still
  10936. * be used by DataTables, as it automatically maps the old name to the new
  10937. * if required.
  10938. *
  10939. * @type string|int|function|null
  10940. * @default null <i>Use automatically calculated column index</i>
  10941. *
  10942. * @name DataTable.defaults.column.data
  10943. * @dtopt Columns
  10944. *
  10945. * @example
  10946. * // Read table data from objects
  10947. * // JSON structure for each row:
  10948. * // {
  10949. * // "engine": {value},
  10950. * // "browser": {value},
  10951. * // "platform": {value},
  10952. * // "version": {value},
  10953. * // "grade": {value}
  10954. * // }
  10955. * $(document).ready( function() {
  10956. * $('#example').dataTable( {
  10957. * "ajaxSource": "sources/objects.txt",
  10958. * "columns": [
  10959. * { "data": "engine" },
  10960. * { "data": "browser" },
  10961. * { "data": "platform" },
  10962. * { "data": "version" },
  10963. * { "data": "grade" }
  10964. * ]
  10965. * } );
  10966. * } );
  10967. *
  10968. * @example
  10969. * // Read information from deeply nested objects
  10970. * // JSON structure for each row:
  10971. * // {
  10972. * // "engine": {value},
  10973. * // "browser": {value},
  10974. * // "platform": {
  10975. * // "inner": {value}
  10976. * // },
  10977. * // "details": [
  10978. * // {value}, {value}
  10979. * // ]
  10980. * // }
  10981. * $(document).ready( function() {
  10982. * $('#example').dataTable( {
  10983. * "ajaxSource": "sources/deep.txt",
  10984. * "columns": [
  10985. * { "data": "engine" },
  10986. * { "data": "browser" },
  10987. * { "data": "platform.inner" },
  10988. * { "data": "details.0" },
  10989. * { "data": "details.1" }
  10990. * ]
  10991. * } );
  10992. * } );
  10993. *
  10994. * @example
  10995. * // Using `data` as a function to provide different information for
  10996. * // sorting, filtering and display. In this case, currency (price)
  10997. * $(document).ready( function() {
  10998. * $('#example').dataTable( {
  10999. * "columnDefs": [ {
  11000. * "targets": [ 0 ],
  11001. * "data": function ( source, type, val ) {
  11002. * if (type === 'set') {
  11003. * source.price = val;
  11004. * // Store the computed display and filter values for efficiency
  11005. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  11006. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  11007. * return;
  11008. * }
  11009. * else if (type === 'display') {
  11010. * return source.price_display;
  11011. * }
  11012. * else if (type === 'filter') {
  11013. * return source.price_filter;
  11014. * }
  11015. * // 'sort', 'type' and undefined all just use the integer
  11016. * return source.price;
  11017. * }
  11018. * } ]
  11019. * } );
  11020. * } );
  11021. *
  11022. * @example
  11023. * // Using default content
  11024. * $(document).ready( function() {
  11025. * $('#example').dataTable( {
  11026. * "columnDefs": [ {
  11027. * "targets": [ 0 ],
  11028. * "data": null,
  11029. * "defaultContent": "Click to edit"
  11030. * } ]
  11031. * } );
  11032. * } );
  11033. *
  11034. * @example
  11035. * // Using array notation - outputting a list from an array
  11036. * $(document).ready( function() {
  11037. * $('#example').dataTable( {
  11038. * "columnDefs": [ {
  11039. * "targets": [ 0 ],
  11040. * "data": "name[, ]"
  11041. * } ]
  11042. * } );
  11043. * } );
  11044. *
  11045. */
  11046. "mData": null,
  11047. /**
  11048. * This property is the rendering partner to `data` and it is suggested that
  11049. * when you want to manipulate data for display (including filtering,
  11050. * sorting etc) without altering the underlying data for the table, use this
  11051. * property. `render` can be considered to be the the read only companion to
  11052. * `data` which is read / write (then as such more complex). Like `data`
  11053. * this option can be given in a number of different ways to effect its
  11054. * behaviour:
  11055. *
  11056. * * `integer` - treated as an array index for the data source. This is the
  11057. * default that DataTables uses (incrementally increased for each column).
  11058. * * `string` - read an object property from the data source. There are
  11059. * three 'special' options that can be used in the string to alter how
  11060. * DataTables reads the data from the source object:
  11061. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  11062. * Javascript to read from nested objects, so to can the options
  11063. * specified in `data`. For example: `browser.version` or
  11064. * `browser.name`. If your object parameter name contains a period, use
  11065. * `\\` to escape it - i.e. `first\\.name`.
  11066. * * `[]` - Array notation. DataTables can automatically combine data
  11067. * from and array source, joining the data with the characters provided
  11068. * between the two brackets. For example: `name[, ]` would provide a
  11069. * comma-space separated list from the source array. If no characters
  11070. * are provided between the brackets, the original array source is
  11071. * returned.
  11072. * * `()` - Function notation. Adding `()` to the end of a parameter will
  11073. * execute a function of the name given. For example: `browser()` for a
  11074. * simple function on the data source, `browser.version()` for a
  11075. * function in a nested property or even `browser().version` to get an
  11076. * object property if the function called returns an object.
  11077. * * `object` - use different data for the different data types requested by
  11078. * DataTables ('filter', 'display', 'type' or 'sort'). The property names
  11079. * of the object is the data type the property refers to and the value can
  11080. * defined using an integer, string or function using the same rules as
  11081. * `render` normally does. Note that an `_` option _must_ be specified.
  11082. * This is the default value to use if you haven't specified a value for
  11083. * the data type requested by DataTables.
  11084. * * `function` - the function given will be executed whenever DataTables
  11085. * needs to set or get the data for a cell in the column. The function
  11086. * takes three parameters:
  11087. * * Parameters:
  11088. * * {array|object} The data source for the row (based on `data`)
  11089. * * {string} The type call data requested - this will be 'filter',
  11090. * 'display', 'type' or 'sort'.
  11091. * * {array|object} The full data source for the row (not based on
  11092. * `data`)
  11093. * * Return:
  11094. * * The return value from the function is what will be used for the
  11095. * data requested.
  11096. *
  11097. * @type string|int|function|object|null
  11098. * @default null Use the data source value.
  11099. *
  11100. * @name DataTable.defaults.column.render
  11101. * @dtopt Columns
  11102. *
  11103. * @example
  11104. * // Create a comma separated list from an array of objects
  11105. * $(document).ready( function() {
  11106. * $('#example').dataTable( {
  11107. * "ajaxSource": "sources/deep.txt",
  11108. * "columns": [
  11109. * { "data": "engine" },
  11110. * { "data": "browser" },
  11111. * {
  11112. * "data": "platform",
  11113. * "render": "[, ].name"
  11114. * }
  11115. * ]
  11116. * } );
  11117. * } );
  11118. *
  11119. * @example
  11120. * // Execute a function to obtain data
  11121. * $(document).ready( function() {
  11122. * $('#example').dataTable( {
  11123. * "columnDefs": [ {
  11124. * "targets": [ 0 ],
  11125. * "data": null, // Use the full data source object for the renderer's source
  11126. * "render": "browserName()"
  11127. * } ]
  11128. * } );
  11129. * } );
  11130. *
  11131. * @example
  11132. * // As an object, extracting different data for the different types
  11133. * // This would be used with a data source such as:
  11134. * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
  11135. * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
  11136. * // (which has both forms) is used for filtering for if a user inputs either format, while
  11137. * // the formatted phone number is the one that is shown in the table.
  11138. * $(document).ready( function() {
  11139. * $('#example').dataTable( {
  11140. * "columnDefs": [ {
  11141. * "targets": [ 0 ],
  11142. * "data": null, // Use the full data source object for the renderer's source
  11143. * "render": {
  11144. * "_": "phone",
  11145. * "filter": "phone_filter",
  11146. * "display": "phone_display"
  11147. * }
  11148. * } ]
  11149. * } );
  11150. * } );
  11151. *
  11152. * @example
  11153. * // Use as a function to create a link from the data source
  11154. * $(document).ready( function() {
  11155. * $('#example').dataTable( {
  11156. * "columnDefs": [ {
  11157. * "targets": [ 0 ],
  11158. * "data": "download_link",
  11159. * "render": function ( data, type, full ) {
  11160. * return '<a href="'+data+'">Download</a>';
  11161. * }
  11162. * } ]
  11163. * } );
  11164. * } );
  11165. */
  11166. "mRender": null,
  11167. /**
  11168. * Change the cell type created for the column - either TD cells or TH cells. This
  11169. * can be useful as TH cells have semantic meaning in the table body, allowing them
  11170. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  11171. * @type string
  11172. * @default td
  11173. *
  11174. * @name DataTable.defaults.column.cellType
  11175. * @dtopt Columns
  11176. *
  11177. * @example
  11178. * // Make the first column use TH cells
  11179. * $(document).ready( function() {
  11180. * $('#example').dataTable( {
  11181. * "columnDefs": [ {
  11182. * "targets": [ 0 ],
  11183. * "cellType": "th"
  11184. * } ]
  11185. * } );
  11186. * } );
  11187. */
  11188. "sCellType": "td",
  11189. /**
  11190. * Class to give to each cell in this column.
  11191. * @type string
  11192. * @default <i>Empty string</i>
  11193. *
  11194. * @name DataTable.defaults.column.class
  11195. * @dtopt Columns
  11196. *
  11197. * @example
  11198. * // Using `columnDefs`
  11199. * $(document).ready( function() {
  11200. * $('#example').dataTable( {
  11201. * "columnDefs": [
  11202. * { "class": "my_class", "targets": [ 0 ] }
  11203. * ]
  11204. * } );
  11205. * } );
  11206. *
  11207. * @example
  11208. * // Using `columns`
  11209. * $(document).ready( function() {
  11210. * $('#example').dataTable( {
  11211. * "columns": [
  11212. * { "class": "my_class" },
  11213. * null,
  11214. * null,
  11215. * null,
  11216. * null
  11217. * ]
  11218. * } );
  11219. * } );
  11220. */
  11221. "sClass": "",
  11222. /**
  11223. * When DataTables calculates the column widths to assign to each column,
  11224. * it finds the longest string in each column and then constructs a
  11225. * temporary table and reads the widths from that. The problem with this
  11226. * is that "mmm" is much wider then "iiii", but the latter is a longer
  11227. * string - thus the calculation can go wrong (doing it properly and putting
  11228. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  11229. * a "work around" we provide this option. It will append its value to the
  11230. * text that is found to be the longest string for the column - i.e. padding.
  11231. * Generally you shouldn't need this!
  11232. * @type string
  11233. * @default <i>Empty string<i>
  11234. *
  11235. * @name DataTable.defaults.column.contentPadding
  11236. * @dtopt Columns
  11237. *
  11238. * @example
  11239. * // Using `columns`
  11240. * $(document).ready( function() {
  11241. * $('#example').dataTable( {
  11242. * "columns": [
  11243. * null,
  11244. * null,
  11245. * null,
  11246. * {
  11247. * "contentPadding": "mmm"
  11248. * }
  11249. * ]
  11250. * } );
  11251. * } );
  11252. */
  11253. "sContentPadding": "",
  11254. /**
  11255. * Allows a default value to be given for a column's data, and will be used
  11256. * whenever a null data source is encountered (this can be because `data`
  11257. * is set to null, or because the data source itself is null).
  11258. * @type string
  11259. * @default null
  11260. *
  11261. * @name DataTable.defaults.column.defaultContent
  11262. * @dtopt Columns
  11263. *
  11264. * @example
  11265. * // Using `columnDefs`
  11266. * $(document).ready( function() {
  11267. * $('#example').dataTable( {
  11268. * "columnDefs": [
  11269. * {
  11270. * "data": null,
  11271. * "defaultContent": "Edit",
  11272. * "targets": [ -1 ]
  11273. * }
  11274. * ]
  11275. * } );
  11276. * } );
  11277. *
  11278. * @example
  11279. * // Using `columns`
  11280. * $(document).ready( function() {
  11281. * $('#example').dataTable( {
  11282. * "columns": [
  11283. * null,
  11284. * null,
  11285. * null,
  11286. * {
  11287. * "data": null,
  11288. * "defaultContent": "Edit"
  11289. * }
  11290. * ]
  11291. * } );
  11292. * } );
  11293. */
  11294. "sDefaultContent": null,
  11295. /**
  11296. * This parameter is only used in DataTables' server-side processing. It can
  11297. * be exceptionally useful to know what columns are being displayed on the
  11298. * client side, and to map these to database fields. When defined, the names
  11299. * also allow DataTables to reorder information from the server if it comes
  11300. * back in an unexpected order (i.e. if you switch your columns around on the
  11301. * client-side, your server-side code does not also need updating).
  11302. * @type string
  11303. * @default <i>Empty string</i>
  11304. *
  11305. * @name DataTable.defaults.column.name
  11306. * @dtopt Columns
  11307. *
  11308. * @example
  11309. * // Using `columnDefs`
  11310. * $(document).ready( function() {
  11311. * $('#example').dataTable( {
  11312. * "columnDefs": [
  11313. * { "name": "engine", "targets": [ 0 ] },
  11314. * { "name": "browser", "targets": [ 1 ] },
  11315. * { "name": "platform", "targets": [ 2 ] },
  11316. * { "name": "version", "targets": [ 3 ] },
  11317. * { "name": "grade", "targets": [ 4 ] }
  11318. * ]
  11319. * } );
  11320. * } );
  11321. *
  11322. * @example
  11323. * // Using `columns`
  11324. * $(document).ready( function() {
  11325. * $('#example').dataTable( {
  11326. * "columns": [
  11327. * { "name": "engine" },
  11328. * { "name": "browser" },
  11329. * { "name": "platform" },
  11330. * { "name": "version" },
  11331. * { "name": "grade" }
  11332. * ]
  11333. * } );
  11334. * } );
  11335. */
  11336. "sName": "",
  11337. /**
  11338. * Defines a data source type for the ordering which can be used to read
  11339. * real-time information from the table (updating the internally cached
  11340. * version) prior to ordering. This allows ordering to occur on user
  11341. * editable elements such as form inputs.
  11342. * @type string
  11343. * @default std
  11344. *
  11345. * @name DataTable.defaults.column.orderDataType
  11346. * @dtopt Columns
  11347. *
  11348. * @example
  11349. * // Using `columnDefs`
  11350. * $(document).ready( function() {
  11351. * $('#example').dataTable( {
  11352. * "columnDefs": [
  11353. * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
  11354. * { "type": "numeric", "targets": [ 3 ] },
  11355. * { "orderDataType": "dom-select", "targets": [ 4 ] },
  11356. * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
  11357. * ]
  11358. * } );
  11359. * } );
  11360. *
  11361. * @example
  11362. * // Using `columns`
  11363. * $(document).ready( function() {
  11364. * $('#example').dataTable( {
  11365. * "columns": [
  11366. * null,
  11367. * null,
  11368. * { "orderDataType": "dom-text" },
  11369. * { "orderDataType": "dom-text", "type": "numeric" },
  11370. * { "orderDataType": "dom-select" },
  11371. * { "orderDataType": "dom-checkbox" }
  11372. * ]
  11373. * } );
  11374. * } );
  11375. */
  11376. "sSortDataType": "std",
  11377. /**
  11378. * The title of this column.
  11379. * @type string
  11380. * @default null <i>Derived from the 'TH' value for this column in the
  11381. * original HTML table.</i>
  11382. *
  11383. * @name DataTable.defaults.column.title
  11384. * @dtopt Columns
  11385. *
  11386. * @example
  11387. * // Using `columnDefs`
  11388. * $(document).ready( function() {
  11389. * $('#example').dataTable( {
  11390. * "columnDefs": [
  11391. * { "title": "My column title", "targets": [ 0 ] }
  11392. * ]
  11393. * } );
  11394. * } );
  11395. *
  11396. * @example
  11397. * // Using `columns`
  11398. * $(document).ready( function() {
  11399. * $('#example').dataTable( {
  11400. * "columns": [
  11401. * { "title": "My column title" },
  11402. * null,
  11403. * null,
  11404. * null,
  11405. * null
  11406. * ]
  11407. * } );
  11408. * } );
  11409. */
  11410. "sTitle": null,
  11411. /**
  11412. * The type allows you to specify how the data for this column will be
  11413. * ordered. Four types (string, numeric, date and html (which will strip
  11414. * HTML tags before ordering)) are currently available. Note that only date
  11415. * formats understood by Javascript's Date() object will be accepted as type
  11416. * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
  11417. * 'numeric', 'date' or 'html' (by default). Further types can be adding
  11418. * through plug-ins.
  11419. * @type string
  11420. * @default null <i>Auto-detected from raw data</i>
  11421. *
  11422. * @name DataTable.defaults.column.type
  11423. * @dtopt Columns
  11424. *
  11425. * @example
  11426. * // Using `columnDefs`
  11427. * $(document).ready( function() {
  11428. * $('#example').dataTable( {
  11429. * "columnDefs": [
  11430. * { "type": "html", "targets": [ 0 ] }
  11431. * ]
  11432. * } );
  11433. * } );
  11434. *
  11435. * @example
  11436. * // Using `columns`
  11437. * $(document).ready( function() {
  11438. * $('#example').dataTable( {
  11439. * "columns": [
  11440. * { "type": "html" },
  11441. * null,
  11442. * null,
  11443. * null,
  11444. * null
  11445. * ]
  11446. * } );
  11447. * } );
  11448. */
  11449. "sType": null,
  11450. /**
  11451. * Defining the width of the column, this parameter may take any CSS value
  11452. * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
  11453. * been given a specific width through this interface ensuring that the table
  11454. * remains readable.
  11455. * @type string
  11456. * @default null <i>Automatic</i>
  11457. *
  11458. * @name DataTable.defaults.column.width
  11459. * @dtopt Columns
  11460. *
  11461. * @example
  11462. * // Using `columnDefs`
  11463. * $(document).ready( function() {
  11464. * $('#example').dataTable( {
  11465. * "columnDefs": [
  11466. * { "width": "20%", "targets": [ 0 ] }
  11467. * ]
  11468. * } );
  11469. * } );
  11470. *
  11471. * @example
  11472. * // Using `columns`
  11473. * $(document).ready( function() {
  11474. * $('#example').dataTable( {
  11475. * "columns": [
  11476. * { "width": "20%" },
  11477. * null,
  11478. * null,
  11479. * null,
  11480. * null
  11481. * ]
  11482. * } );
  11483. * } );
  11484. */
  11485. "sWidth": null
  11486. };
  11487. _fnHungarianMap( DataTable.defaults.column );
  11488. /**
  11489. * DataTables settings object - this holds all the information needed for a
  11490. * given table, including configuration, data and current application of the
  11491. * table options. DataTables does not have a single instance for each DataTable
  11492. * with the settings attached to that instance, but rather instances of the
  11493. * DataTable "class" are created on-the-fly as needed (typically by a
  11494. * $().dataTable() call) and the settings object is then applied to that
  11495. * instance.
  11496. *
  11497. * Note that this object is related to {@link DataTable.defaults} but this
  11498. * one is the internal data store for DataTables's cache of columns. It should
  11499. * NOT be manipulated outside of DataTables. Any configuration should be done
  11500. * through the initialisation options.
  11501. * @namespace
  11502. * @todo Really should attach the settings object to individual instances so we
  11503. * don't need to create new instances on each $().dataTable() call (if the
  11504. * table already exists). It would also save passing oSettings around and
  11505. * into every single function. However, this is a very significant
  11506. * architecture change for DataTables and will almost certainly break
  11507. * backwards compatibility with older installations. This is something that
  11508. * will be done in 2.0.
  11509. */
  11510. DataTable.models.oSettings = {
  11511. /**
  11512. * Primary features of DataTables and their enablement state.
  11513. * @namespace
  11514. */
  11515. "oFeatures": {
  11516. /**
  11517. * Flag to say if DataTables should automatically try to calculate the
  11518. * optimum table and columns widths (true) or not (false).
  11519. * Note that this parameter will be set by the initialisation routine. To
  11520. * set a default use {@link DataTable.defaults}.
  11521. * @type boolean
  11522. */
  11523. "bAutoWidth": null,
  11524. /**
  11525. * Delay the creation of TR and TD elements until they are actually
  11526. * needed by a driven page draw. This can give a significant speed
  11527. * increase for Ajax source and Javascript source data, but makes no
  11528. * difference at all for DOM and server-side processing tables.
  11529. * Note that this parameter will be set by the initialisation routine. To
  11530. * set a default use {@link DataTable.defaults}.
  11531. * @type boolean
  11532. */
  11533. "bDeferRender": null,
  11534. /**
  11535. * Enable filtering on the table or not. Note that if this is disabled
  11536. * then there is no filtering at all on the table, including fnFilter.
  11537. * To just remove the filtering input use sDom and remove the 'f' option.
  11538. * Note that this parameter will be set by the initialisation routine. To
  11539. * set a default use {@link DataTable.defaults}.
  11540. * @type boolean
  11541. */
  11542. "bFilter": null,
  11543. /**
  11544. * Table information element (the 'Showing x of y records' div) enable
  11545. * flag.
  11546. * Note that this parameter will be set by the initialisation routine. To
  11547. * set a default use {@link DataTable.defaults}.
  11548. * @type boolean
  11549. */
  11550. "bInfo": null,
  11551. /**
  11552. * Present a user control allowing the end user to change the page size
  11553. * when pagination is enabled.
  11554. * Note that this parameter will be set by the initialisation routine. To
  11555. * set a default use {@link DataTable.defaults}.
  11556. * @type boolean
  11557. */
  11558. "bLengthChange": null,
  11559. /**
  11560. * Pagination enabled or not. Note that if this is disabled then length
  11561. * changing must also be disabled.
  11562. * Note that this parameter will be set by the initialisation routine. To
  11563. * set a default use {@link DataTable.defaults}.
  11564. * @type boolean
  11565. */
  11566. "bPaginate": null,
  11567. /**
  11568. * Processing indicator enable flag whenever DataTables is enacting a
  11569. * user request - typically an Ajax request for server-side processing.
  11570. * Note that this parameter will be set by the initialisation routine. To
  11571. * set a default use {@link DataTable.defaults}.
  11572. * @type boolean
  11573. */
  11574. "bProcessing": null,
  11575. /**
  11576. * Server-side processing enabled flag - when enabled DataTables will
  11577. * get all data from the server for every draw - there is no filtering,
  11578. * sorting or paging done on the client-side.
  11579. * Note that this parameter will be set by the initialisation routine. To
  11580. * set a default use {@link DataTable.defaults}.
  11581. * @type boolean
  11582. */
  11583. "bServerSide": null,
  11584. /**
  11585. * Sorting enablement flag.
  11586. * Note that this parameter will be set by the initialisation routine. To
  11587. * set a default use {@link DataTable.defaults}.
  11588. * @type boolean
  11589. */
  11590. "bSort": null,
  11591. /**
  11592. * Multi-column sorting
  11593. * Note that this parameter will be set by the initialisation routine. To
  11594. * set a default use {@link DataTable.defaults}.
  11595. * @type boolean
  11596. */
  11597. "bSortMulti": null,
  11598. /**
  11599. * Apply a class to the columns which are being sorted to provide a
  11600. * visual highlight or not. This can slow things down when enabled since
  11601. * there is a lot of DOM interaction.
  11602. * Note that this parameter will be set by the initialisation routine. To
  11603. * set a default use {@link DataTable.defaults}.
  11604. * @type boolean
  11605. */
  11606. "bSortClasses": null,
  11607. /**
  11608. * State saving enablement flag.
  11609. * Note that this parameter will be set by the initialisation routine. To
  11610. * set a default use {@link DataTable.defaults}.
  11611. * @type boolean
  11612. */
  11613. "bStateSave": null
  11614. },
  11615. /**
  11616. * Scrolling settings for a table.
  11617. * @namespace
  11618. */
  11619. "oScroll": {
  11620. /**
  11621. * When the table is shorter in height than sScrollY, collapse the
  11622. * table container down to the height of the table (when true).
  11623. * Note that this parameter will be set by the initialisation routine. To
  11624. * set a default use {@link DataTable.defaults}.
  11625. * @type boolean
  11626. */
  11627. "bCollapse": null,
  11628. /**
  11629. * Width of the scrollbar for the web-browser's platform. Calculated
  11630. * during table initialisation.
  11631. * @type int
  11632. * @default 0
  11633. */
  11634. "iBarWidth": 0,
  11635. /**
  11636. * Viewport width for horizontal scrolling. Horizontal scrolling is
  11637. * disabled if an empty string.
  11638. * Note that this parameter will be set by the initialisation routine. To
  11639. * set a default use {@link DataTable.defaults}.
  11640. * @type string
  11641. */
  11642. "sX": null,
  11643. /**
  11644. * Width to expand the table to when using x-scrolling. Typically you
  11645. * should not need to use this.
  11646. * Note that this parameter will be set by the initialisation routine. To
  11647. * set a default use {@link DataTable.defaults}.
  11648. * @type string
  11649. * @deprecated
  11650. */
  11651. "sXInner": null,
  11652. /**
  11653. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  11654. * if an empty string.
  11655. * Note that this parameter will be set by the initialisation routine. To
  11656. * set a default use {@link DataTable.defaults}.
  11657. * @type string
  11658. */
  11659. "sY": null
  11660. },
  11661. /**
  11662. * Language information for the table.
  11663. * @namespace
  11664. * @extends DataTable.defaults.oLanguage
  11665. */
  11666. "oLanguage": {
  11667. /**
  11668. * Information callback function. See
  11669. * {@link DataTable.defaults.fnInfoCallback}
  11670. * @type function
  11671. * @default null
  11672. */
  11673. "fnInfoCallback": null
  11674. },
  11675. /**
  11676. * Browser support parameters
  11677. * @namespace
  11678. */
  11679. "oBrowser": {
  11680. /**
  11681. * Indicate if the browser incorrectly calculates width:100% inside a
  11682. * scrolling element (IE6/7)
  11683. * @type boolean
  11684. * @default false
  11685. */
  11686. "bScrollOversize": false,
  11687. /**
  11688. * Determine if the vertical scrollbar is on the right or left of the
  11689. * scrolling container - needed for rtl language layout, although not
  11690. * all browsers move the scrollbar (Safari).
  11691. * @type boolean
  11692. * @default false
  11693. */
  11694. "bScrollbarLeft": false,
  11695. /**
  11696. * Flag for if `getBoundingClientRect` is fully supported or not
  11697. * @type boolean
  11698. * @default false
  11699. */
  11700. "bBounding": false,
  11701. /**
  11702. * Browser scrollbar width
  11703. * @type integer
  11704. * @default 0
  11705. */
  11706. "barWidth": 0
  11707. },
  11708. "ajax": null,
  11709. /**
  11710. * Array referencing the nodes which are used for the features. The
  11711. * parameters of this object match what is allowed by sDom - i.e.
  11712. * <ul>
  11713. * <li>'l' - Length changing</li>
  11714. * <li>'f' - Filtering input</li>
  11715. * <li>'t' - The table!</li>
  11716. * <li>'i' - Information</li>
  11717. * <li>'p' - Pagination</li>
  11718. * <li>'r' - pRocessing</li>
  11719. * </ul>
  11720. * @type array
  11721. * @default []
  11722. */
  11723. "aanFeatures": [],
  11724. /**
  11725. * Store data information - see {@link DataTable.models.oRow} for detailed
  11726. * information.
  11727. * @type array
  11728. * @default []
  11729. */
  11730. "aoData": [],
  11731. /**
  11732. * Array of indexes which are in the current display (after filtering etc)
  11733. * @type array
  11734. * @default []
  11735. */
  11736. "aiDisplay": [],
  11737. /**
  11738. * Array of indexes for display - no filtering
  11739. * @type array
  11740. * @default []
  11741. */
  11742. "aiDisplayMaster": [],
  11743. /**
  11744. * Map of row ids to data indexes
  11745. * @type object
  11746. * @default {}
  11747. */
  11748. "aIds": {},
  11749. /**
  11750. * Store information about each column that is in use
  11751. * @type array
  11752. * @default []
  11753. */
  11754. "aoColumns": [],
  11755. /**
  11756. * Store information about the table's header
  11757. * @type array
  11758. * @default []
  11759. */
  11760. "aoHeader": [],
  11761. /**
  11762. * Store information about the table's footer
  11763. * @type array
  11764. * @default []
  11765. */
  11766. "aoFooter": [],
  11767. /**
  11768. * Store the applied global search information in case we want to force a
  11769. * research or compare the old search to a new one.
  11770. * Note that this parameter will be set by the initialisation routine. To
  11771. * set a default use {@link DataTable.defaults}.
  11772. * @namespace
  11773. * @extends DataTable.models.oSearch
  11774. */
  11775. "oPreviousSearch": {},
  11776. /**
  11777. * Store the applied search for each column - see
  11778. * {@link DataTable.models.oSearch} for the format that is used for the
  11779. * filtering information for each column.
  11780. * @type array
  11781. * @default []
  11782. */
  11783. "aoPreSearchCols": [],
  11784. /**
  11785. * Sorting that is applied to the table. Note that the inner arrays are
  11786. * used in the following manner:
  11787. * <ul>
  11788. * <li>Index 0 - column number</li>
  11789. * <li>Index 1 - current sorting direction</li>
  11790. * </ul>
  11791. * Note that this parameter will be set by the initialisation routine. To
  11792. * set a default use {@link DataTable.defaults}.
  11793. * @type array
  11794. * @todo These inner arrays should really be objects
  11795. */
  11796. "aaSorting": null,
  11797. /**
  11798. * Sorting that is always applied to the table (i.e. prefixed in front of
  11799. * aaSorting).
  11800. * Note that this parameter will be set by the initialisation routine. To
  11801. * set a default use {@link DataTable.defaults}.
  11802. * @type array
  11803. * @default []
  11804. */
  11805. "aaSortingFixed": [],
  11806. /**
  11807. * Classes to use for the striping of a table.
  11808. * Note that this parameter will be set by the initialisation routine. To
  11809. * set a default use {@link DataTable.defaults}.
  11810. * @type array
  11811. * @default []
  11812. */
  11813. "asStripeClasses": null,
  11814. /**
  11815. * If restoring a table - we should restore its striping classes as well
  11816. * @type array
  11817. * @default []
  11818. */
  11819. "asDestroyStripes": [],
  11820. /**
  11821. * If restoring a table - we should restore its width
  11822. * @type int
  11823. * @default 0
  11824. */
  11825. "sDestroyWidth": 0,
  11826. /**
  11827. * Callback functions array for every time a row is inserted (i.e. on a draw).
  11828. * @type array
  11829. * @default []
  11830. */
  11831. "aoRowCallback": [],
  11832. /**
  11833. * Callback functions for the header on each draw.
  11834. * @type array
  11835. * @default []
  11836. */
  11837. "aoHeaderCallback": [],
  11838. /**
  11839. * Callback function for the footer on each draw.
  11840. * @type array
  11841. * @default []
  11842. */
  11843. "aoFooterCallback": [],
  11844. /**
  11845. * Array of callback functions for draw callback functions
  11846. * @type array
  11847. * @default []
  11848. */
  11849. "aoDrawCallback": [],
  11850. /**
  11851. * Array of callback functions for row created function
  11852. * @type array
  11853. * @default []
  11854. */
  11855. "aoRowCreatedCallback": [],
  11856. /**
  11857. * Callback functions for just before the table is redrawn. A return of
  11858. * false will be used to cancel the draw.
  11859. * @type array
  11860. * @default []
  11861. */
  11862. "aoPreDrawCallback": [],
  11863. /**
  11864. * Callback functions for when the table has been initialised.
  11865. * @type array
  11866. * @default []
  11867. */
  11868. "aoInitComplete": [],
  11869. /**
  11870. * Callbacks for modifying the settings to be stored for state saving, prior to
  11871. * saving state.
  11872. * @type array
  11873. * @default []
  11874. */
  11875. "aoStateSaveParams": [],
  11876. /**
  11877. * Callbacks for modifying the settings that have been stored for state saving
  11878. * prior to using the stored values to restore the state.
  11879. * @type array
  11880. * @default []
  11881. */
  11882. "aoStateLoadParams": [],
  11883. /**
  11884. * Callbacks for operating on the settings object once the saved state has been
  11885. * loaded
  11886. * @type array
  11887. * @default []
  11888. */
  11889. "aoStateLoaded": [],
  11890. /**
  11891. * Cache the table ID for quick access
  11892. * @type string
  11893. * @default <i>Empty string</i>
  11894. */
  11895. "sTableId": "",
  11896. /**
  11897. * The TABLE node for the main table
  11898. * @type node
  11899. * @default null
  11900. */
  11901. "nTable": null,
  11902. /**
  11903. * Permanent ref to the thead element
  11904. * @type node
  11905. * @default null
  11906. */
  11907. "nTHead": null,
  11908. /**
  11909. * Permanent ref to the tfoot element - if it exists
  11910. * @type node
  11911. * @default null
  11912. */
  11913. "nTFoot": null,
  11914. /**
  11915. * Permanent ref to the tbody element
  11916. * @type node
  11917. * @default null
  11918. */
  11919. "nTBody": null,
  11920. /**
  11921. * Cache the wrapper node (contains all DataTables controlled elements)
  11922. * @type node
  11923. * @default null
  11924. */
  11925. "nTableWrapper": null,
  11926. /**
  11927. * Indicate if when using server-side processing the loading of data
  11928. * should be deferred until the second draw.
  11929. * Note that this parameter will be set by the initialisation routine. To
  11930. * set a default use {@link DataTable.defaults}.
  11931. * @type boolean
  11932. * @default false
  11933. */
  11934. "bDeferLoading": false,
  11935. /**
  11936. * Indicate if all required information has been read in
  11937. * @type boolean
  11938. * @default false
  11939. */
  11940. "bInitialised": false,
  11941. /**
  11942. * Information about open rows. Each object in the array has the parameters
  11943. * 'nTr' and 'nParent'
  11944. * @type array
  11945. * @default []
  11946. */
  11947. "aoOpenRows": [],
  11948. /**
  11949. * Dictate the positioning of DataTables' control elements - see
  11950. * {@link DataTable.model.oInit.sDom}.
  11951. * Note that this parameter will be set by the initialisation routine. To
  11952. * set a default use {@link DataTable.defaults}.
  11953. * @type string
  11954. * @default null
  11955. */
  11956. "sDom": null,
  11957. /**
  11958. * Search delay (in mS)
  11959. * @type integer
  11960. * @default null
  11961. */
  11962. "searchDelay": null,
  11963. /**
  11964. * Which type of pagination should be used.
  11965. * Note that this parameter will be set by the initialisation routine. To
  11966. * set a default use {@link DataTable.defaults}.
  11967. * @type string
  11968. * @default two_button
  11969. */
  11970. "sPaginationType": "two_button",
  11971. /**
  11972. * The state duration (for `stateSave`) in seconds.
  11973. * Note that this parameter will be set by the initialisation routine. To
  11974. * set a default use {@link DataTable.defaults}.
  11975. * @type int
  11976. * @default 0
  11977. */
  11978. "iStateDuration": 0,
  11979. /**
  11980. * Array of callback functions for state saving. Each array element is an
  11981. * object with the following parameters:
  11982. * <ul>
  11983. * <li>function:fn - function to call. Takes two parameters, oSettings
  11984. * and the JSON string to save that has been thus far created. Returns
  11985. * a JSON string to be inserted into a json object
  11986. * (i.e. '"param": [ 0, 1, 2]')</li>
  11987. * <li>string:sName - name of callback</li>
  11988. * </ul>
  11989. * @type array
  11990. * @default []
  11991. */
  11992. "aoStateSave": [],
  11993. /**
  11994. * Array of callback functions for state loading. Each array element is an
  11995. * object with the following parameters:
  11996. * <ul>
  11997. * <li>function:fn - function to call. Takes two parameters, oSettings
  11998. * and the object stored. May return false to cancel state loading</li>
  11999. * <li>string:sName - name of callback</li>
  12000. * </ul>
  12001. * @type array
  12002. * @default []
  12003. */
  12004. "aoStateLoad": [],
  12005. /**
  12006. * State that was saved. Useful for back reference
  12007. * @type object
  12008. * @default null
  12009. */
  12010. "oSavedState": null,
  12011. /**
  12012. * State that was loaded. Useful for back reference
  12013. * @type object
  12014. * @default null
  12015. */
  12016. "oLoadedState": null,
  12017. /**
  12018. * Source url for AJAX data for the table.
  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. * @default null
  12023. */
  12024. "sAjaxSource": null,
  12025. /**
  12026. * Property from a given object from which to read the table data from. This
  12027. * can be an empty string (when not server-side processing), in which case
  12028. * it is assumed an an array is given directly.
  12029. * Note that this parameter will be set by the initialisation routine. To
  12030. * set a default use {@link DataTable.defaults}.
  12031. * @type string
  12032. */
  12033. "sAjaxDataProp": null,
  12034. /**
  12035. * The last jQuery XHR object that was used for server-side data gathering.
  12036. * This can be used for working with the XHR information in one of the
  12037. * callbacks
  12038. * @type object
  12039. * @default null
  12040. */
  12041. "jqXHR": null,
  12042. /**
  12043. * JSON returned from the server in the last Ajax request
  12044. * @type object
  12045. * @default undefined
  12046. */
  12047. "json": undefined,
  12048. /**
  12049. * Data submitted as part of the last Ajax request
  12050. * @type object
  12051. * @default undefined
  12052. */
  12053. "oAjaxData": undefined,
  12054. /**
  12055. * Function to get the server-side data.
  12056. * Note that this parameter will be set by the initialisation routine. To
  12057. * set a default use {@link DataTable.defaults}.
  12058. * @type function
  12059. */
  12060. "fnServerData": null,
  12061. /**
  12062. * Functions which are called prior to sending an Ajax request so extra
  12063. * parameters can easily be sent to the server
  12064. * @type array
  12065. * @default []
  12066. */
  12067. "aoServerParams": [],
  12068. /**
  12069. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  12070. * required).
  12071. * Note that this parameter will be set by the initialisation routine. To
  12072. * set a default use {@link DataTable.defaults}.
  12073. * @type string
  12074. */
  12075. "sServerMethod": null,
  12076. /**
  12077. * Format numbers for display.
  12078. * Note that this parameter will be set by the initialisation routine. To
  12079. * set a default use {@link DataTable.defaults}.
  12080. * @type function
  12081. */
  12082. "fnFormatNumber": null,
  12083. /**
  12084. * List of options that can be used for the user selectable length menu.
  12085. * Note that this parameter will be set by the initialisation routine. To
  12086. * set a default use {@link DataTable.defaults}.
  12087. * @type array
  12088. * @default []
  12089. */
  12090. "aLengthMenu": null,
  12091. /**
  12092. * Counter for the draws that the table does. Also used as a tracker for
  12093. * server-side processing
  12094. * @type int
  12095. * @default 0
  12096. */
  12097. "iDraw": 0,
  12098. /**
  12099. * Indicate if a redraw is being done - useful for Ajax
  12100. * @type boolean
  12101. * @default false
  12102. */
  12103. "bDrawing": false,
  12104. /**
  12105. * Draw index (iDraw) of the last error when parsing the returned data
  12106. * @type int
  12107. * @default -1
  12108. */
  12109. "iDrawError": -1,
  12110. /**
  12111. * Paging display length
  12112. * @type int
  12113. * @default 10
  12114. */
  12115. "_iDisplayLength": 10,
  12116. /**
  12117. * Paging start point - aiDisplay index
  12118. * @type int
  12119. * @default 0
  12120. */
  12121. "_iDisplayStart": 0,
  12122. /**
  12123. * Server-side processing - number of records in the result set
  12124. * (i.e. before filtering), Use fnRecordsTotal rather than
  12125. * this property to get the value of the number of records, regardless of
  12126. * the server-side processing setting.
  12127. * @type int
  12128. * @default 0
  12129. * @private
  12130. */
  12131. "_iRecordsTotal": 0,
  12132. /**
  12133. * Server-side processing - number of records in the current display set
  12134. * (i.e. after filtering). Use fnRecordsDisplay rather than
  12135. * this property to get the value of the number of records, regardless of
  12136. * the server-side processing setting.
  12137. * @type boolean
  12138. * @default 0
  12139. * @private
  12140. */
  12141. "_iRecordsDisplay": 0,
  12142. /**
  12143. * The classes to use for the table
  12144. * @type object
  12145. * @default {}
  12146. */
  12147. "oClasses": {},
  12148. /**
  12149. * Flag attached to the settings object so you can check in the draw
  12150. * callback if filtering has been done in the draw. Deprecated in favour of
  12151. * events.
  12152. * @type boolean
  12153. * @default false
  12154. * @deprecated
  12155. */
  12156. "bFiltered": false,
  12157. /**
  12158. * Flag attached to the settings object so you can check in the draw
  12159. * callback if sorting has been done in the draw. Deprecated in favour of
  12160. * events.
  12161. * @type boolean
  12162. * @default false
  12163. * @deprecated
  12164. */
  12165. "bSorted": false,
  12166. /**
  12167. * Indicate that if multiple rows are in the header and there is more than
  12168. * one unique cell per column, if the top one (true) or bottom one (false)
  12169. * should be used for sorting / title by DataTables.
  12170. * Note that this parameter will be set by the initialisation routine. To
  12171. * set a default use {@link DataTable.defaults}.
  12172. * @type boolean
  12173. */
  12174. "bSortCellsTop": null,
  12175. /**
  12176. * Initialisation object that is used for the table
  12177. * @type object
  12178. * @default null
  12179. */
  12180. "oInit": null,
  12181. /**
  12182. * Destroy callback functions - for plug-ins to attach themselves to the
  12183. * destroy so they can clean up markup and events.
  12184. * @type array
  12185. * @default []
  12186. */
  12187. "aoDestroyCallback": [],
  12188. /**
  12189. * Get the number of records in the current record set, before filtering
  12190. * @type function
  12191. */
  12192. "fnRecordsTotal": function ()
  12193. {
  12194. return _fnDataSource( this ) == 'ssp' ?
  12195. this._iRecordsTotal * 1 :
  12196. this.aiDisplayMaster.length;
  12197. },
  12198. /**
  12199. * Get the number of records in the current record set, after filtering
  12200. * @type function
  12201. */
  12202. "fnRecordsDisplay": function ()
  12203. {
  12204. return _fnDataSource( this ) == 'ssp' ?
  12205. this._iRecordsDisplay * 1 :
  12206. this.aiDisplay.length;
  12207. },
  12208. /**
  12209. * Get the display end point - aiDisplay index
  12210. * @type function
  12211. */
  12212. "fnDisplayEnd": function ()
  12213. {
  12214. var
  12215. len = this._iDisplayLength,
  12216. start = this._iDisplayStart,
  12217. calc = start + len,
  12218. records = this.aiDisplay.length,
  12219. features = this.oFeatures,
  12220. paginate = features.bPaginate;
  12221. if ( features.bServerSide ) {
  12222. return paginate === false || len === -1 ?
  12223. start + records :
  12224. Math.min( start+len, this._iRecordsDisplay );
  12225. }
  12226. else {
  12227. return ! paginate || calc>records || len===-1 ?
  12228. records :
  12229. calc;
  12230. }
  12231. },
  12232. /**
  12233. * The DataTables object for this table
  12234. * @type object
  12235. * @default null
  12236. */
  12237. "oInstance": null,
  12238. /**
  12239. * Unique identifier for each instance of the DataTables object. If there
  12240. * is an ID on the table node, then it takes that value, otherwise an
  12241. * incrementing internal counter is used.
  12242. * @type string
  12243. * @default null
  12244. */
  12245. "sInstance": null,
  12246. /**
  12247. * tabindex attribute value that is added to DataTables control elements, allowing
  12248. * keyboard navigation of the table and its controls.
  12249. */
  12250. "iTabIndex": 0,
  12251. /**
  12252. * DIV container for the footer scrolling table if scrolling
  12253. */
  12254. "nScrollHead": null,
  12255. /**
  12256. * DIV container for the footer scrolling table if scrolling
  12257. */
  12258. "nScrollFoot": null,
  12259. /**
  12260. * Last applied sort
  12261. * @type array
  12262. * @default []
  12263. */
  12264. "aLastSort": [],
  12265. /**
  12266. * Stored plug-in instances
  12267. * @type object
  12268. * @default {}
  12269. */
  12270. "oPlugins": {},
  12271. /**
  12272. * Function used to get a row's id from the row's data
  12273. * @type function
  12274. * @default null
  12275. */
  12276. "rowIdFn": null,
  12277. /**
  12278. * Data location where to store a row's id
  12279. * @type string
  12280. * @default null
  12281. */
  12282. "rowId": null
  12283. };
  12284. /**
  12285. * Extension object for DataTables that is used to provide all extension
  12286. * options.
  12287. *
  12288. * Note that the `DataTable.ext` object is available through
  12289. * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
  12290. * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
  12291. * @namespace
  12292. * @extends DataTable.models.ext
  12293. */
  12294. /**
  12295. * DataTables extensions
  12296. *
  12297. * This namespace acts as a collection area for plug-ins that can be used to
  12298. * extend DataTables capabilities. Indeed many of the build in methods
  12299. * use this method to provide their own capabilities (sorting methods for
  12300. * example).
  12301. *
  12302. * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
  12303. * reasons
  12304. *
  12305. * @namespace
  12306. */
  12307. DataTable.ext = _ext = {
  12308. /**
  12309. * Buttons. For use with the Buttons extension for DataTables. This is
  12310. * defined here so other extensions can define buttons regardless of load
  12311. * order. It is _not_ used by DataTables core.
  12312. *
  12313. * @type object
  12314. * @default {}
  12315. */
  12316. buttons: {},
  12317. /**
  12318. * Element class names
  12319. *
  12320. * @type object
  12321. * @default {}
  12322. */
  12323. classes: {},
  12324. /**
  12325. * DataTables build type (expanded by the download builder)
  12326. *
  12327. * @type string
  12328. */
  12329. builder: "-source-",
  12330. /**
  12331. * Error reporting.
  12332. *
  12333. * How should DataTables report an error. Can take the value 'alert',
  12334. * 'throw', 'none' or a function.
  12335. *
  12336. * @type string|function
  12337. * @default alert
  12338. */
  12339. errMode: "alert",
  12340. /**
  12341. * Feature plug-ins.
  12342. *
  12343. * This is an array of objects which describe the feature plug-ins that are
  12344. * available to DataTables. These feature plug-ins are then available for
  12345. * use through the `dom` initialisation option.
  12346. *
  12347. * Each feature plug-in is described by an object which must have the
  12348. * following properties:
  12349. *
  12350. * * `fnInit` - function that is used to initialise the plug-in,
  12351. * * `cFeature` - a character so the feature can be enabled by the `dom`
  12352. * instillation option. This is case sensitive.
  12353. *
  12354. * The `fnInit` function has the following input parameters:
  12355. *
  12356. * 1. `{object}` DataTables settings object: see
  12357. * {@link DataTable.models.oSettings}
  12358. *
  12359. * And the following return is expected:
  12360. *
  12361. * * {node|null} The element which contains your feature. Note that the
  12362. * return may also be void if your plug-in does not require to inject any
  12363. * DOM elements into DataTables control (`dom`) - for example this might
  12364. * be useful when developing a plug-in which allows table control via
  12365. * keyboard entry
  12366. *
  12367. * @type array
  12368. *
  12369. * @example
  12370. * $.fn.dataTable.ext.features.push( {
  12371. * "fnInit": function( oSettings ) {
  12372. * return new TableTools( { "oDTSettings": oSettings } );
  12373. * },
  12374. * "cFeature": "T"
  12375. * } );
  12376. */
  12377. feature: [],
  12378. /**
  12379. * Row searching.
  12380. *
  12381. * This method of searching is complimentary to the default type based
  12382. * searching, and a lot more comprehensive as it allows you complete control
  12383. * over the searching logic. Each element in this array is a function
  12384. * (parameters described below) that is called for every row in the table,
  12385. * and your logic decides if it should be included in the searching data set
  12386. * or not.
  12387. *
  12388. * Searching functions have the following input parameters:
  12389. *
  12390. * 1. `{object}` DataTables settings object: see
  12391. * {@link DataTable.models.oSettings}
  12392. * 2. `{array|object}` Data for the row to be processed (same as the
  12393. * original format that was passed in as the data source, or an array
  12394. * from a DOM data source
  12395. * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
  12396. * can be useful to retrieve the `TR` element if you need DOM interaction.
  12397. *
  12398. * And the following return is expected:
  12399. *
  12400. * * {boolean} Include the row in the searched result set (true) or not
  12401. * (false)
  12402. *
  12403. * Note that as with the main search ability in DataTables, technically this
  12404. * is "filtering", since it is subtractive. However, for consistency in
  12405. * naming we call it searching here.
  12406. *
  12407. * @type array
  12408. * @default []
  12409. *
  12410. * @example
  12411. * // The following example shows custom search being applied to the
  12412. * // fourth column (i.e. the data[3] index) based on two input values
  12413. * // from the end-user, matching the data in a certain range.
  12414. * $.fn.dataTable.ext.search.push(
  12415. * function( settings, data, dataIndex ) {
  12416. * var min = document.getElementById('min').value * 1;
  12417. * var max = document.getElementById('max').value * 1;
  12418. * var version = data[3] == "-" ? 0 : data[3]*1;
  12419. *
  12420. * if ( min == "" && max == "" ) {
  12421. * return true;
  12422. * }
  12423. * else if ( min == "" && version < max ) {
  12424. * return true;
  12425. * }
  12426. * else if ( min < version && "" == max ) {
  12427. * return true;
  12428. * }
  12429. * else if ( min < version && version < max ) {
  12430. * return true;
  12431. * }
  12432. * return false;
  12433. * }
  12434. * );
  12435. */
  12436. search: [],
  12437. /**
  12438. * Selector extensions
  12439. *
  12440. * The `selector` option can be used to extend the options available for the
  12441. * selector modifier options (`selector-modifier` object data type) that
  12442. * each of the three built in selector types offer (row, column and cell +
  12443. * their plural counterparts). For example the Select extension uses this
  12444. * mechanism to provide an option to select only rows, columns and cells
  12445. * that have been marked as selected by the end user (`{selected: true}`),
  12446. * which can be used in conjunction with the existing built in selector
  12447. * options.
  12448. *
  12449. * Each property is an array to which functions can be pushed. The functions
  12450. * take three attributes:
  12451. *
  12452. * * Settings object for the host table
  12453. * * Options object (`selector-modifier` object type)
  12454. * * Array of selected item indexes
  12455. *
  12456. * The return is an array of the resulting item indexes after the custom
  12457. * selector has been applied.
  12458. *
  12459. * @type object
  12460. */
  12461. selector: {
  12462. cell: [],
  12463. column: [],
  12464. row: []
  12465. },
  12466. /**
  12467. * Internal functions, exposed for used in plug-ins.
  12468. *
  12469. * Please note that you should not need to use the internal methods for
  12470. * anything other than a plug-in (and even then, try to avoid if possible).
  12471. * The internal function may change between releases.
  12472. *
  12473. * @type object
  12474. * @default {}
  12475. */
  12476. internal: {},
  12477. /**
  12478. * Legacy configuration options. Enable and disable legacy options that
  12479. * are available in DataTables.
  12480. *
  12481. * @type object
  12482. */
  12483. legacy: {
  12484. /**
  12485. * Enable / disable DataTables 1.9 compatible server-side processing
  12486. * requests
  12487. *
  12488. * @type boolean
  12489. * @default null
  12490. */
  12491. ajax: null
  12492. },
  12493. /**
  12494. * Pagination plug-in methods.
  12495. *
  12496. * Each entry in this object is a function and defines which buttons should
  12497. * be shown by the pagination rendering method that is used for the table:
  12498. * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
  12499. * buttons are displayed in the document, while the functions here tell it
  12500. * what buttons to display. This is done by returning an array of button
  12501. * descriptions (what each button will do).
  12502. *
  12503. * Pagination types (the four built in options and any additional plug-in
  12504. * options defined here) can be used through the `paginationType`
  12505. * initialisation parameter.
  12506. *
  12507. * The functions defined take two parameters:
  12508. *
  12509. * 1. `{int} page` The current page index
  12510. * 2. `{int} pages` The number of pages in the table
  12511. *
  12512. * Each function is expected to return an array where each element of the
  12513. * array can be one of:
  12514. *
  12515. * * `first` - Jump to first page when activated
  12516. * * `last` - Jump to last page when activated
  12517. * * `previous` - Show previous page when activated
  12518. * * `next` - Show next page when activated
  12519. * * `{int}` - Show page of the index given
  12520. * * `{array}` - A nested array containing the above elements to add a
  12521. * containing 'DIV' element (might be useful for styling).
  12522. *
  12523. * Note that DataTables v1.9- used this object slightly differently whereby
  12524. * an object with two functions would be defined for each plug-in. That
  12525. * ability is still supported by DataTables 1.10+ to provide backwards
  12526. * compatibility, but this option of use is now decremented and no longer
  12527. * documented in DataTables 1.10+.
  12528. *
  12529. * @type object
  12530. * @default {}
  12531. *
  12532. * @example
  12533. * // Show previous, next and current page buttons only
  12534. * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
  12535. * return [ 'previous', page, 'next' ];
  12536. * };
  12537. */
  12538. pager: {},
  12539. renderer: {
  12540. pageButton: {},
  12541. header: {}
  12542. },
  12543. /**
  12544. * Ordering plug-ins - custom data source
  12545. *
  12546. * The extension options for ordering of data available here is complimentary
  12547. * to the default type based ordering that DataTables typically uses. It
  12548. * allows much greater control over the the data that is being used to
  12549. * order a column, but is necessarily therefore more complex.
  12550. *
  12551. * This type of ordering is useful if you want to do ordering based on data
  12552. * live from the DOM (for example the contents of an 'input' element) rather
  12553. * than just the static string that DataTables knows of.
  12554. *
  12555. * The way these plug-ins work is that you create an array of the values you
  12556. * wish to be ordering for the column in question and then return that
  12557. * array. The data in the array much be in the index order of the rows in
  12558. * the table (not the currently ordering order!). Which order data gathering
  12559. * function is run here depends on the `dt-init columns.orderDataType`
  12560. * parameter that is used for the column (if any).
  12561. *
  12562. * The functions defined take two parameters:
  12563. *
  12564. * 1. `{object}` DataTables settings object: see
  12565. * {@link DataTable.models.oSettings}
  12566. * 2. `{int}` Target column index
  12567. *
  12568. * Each function is expected to return an array:
  12569. *
  12570. * * `{array}` Data for the column to be ordering upon
  12571. *
  12572. * @type array
  12573. *
  12574. * @example
  12575. * // Ordering using `input` node values
  12576. * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
  12577. * {
  12578. * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
  12579. * return $('input', td).val();
  12580. * } );
  12581. * }
  12582. */
  12583. order: {},
  12584. /**
  12585. * Type based plug-ins.
  12586. *
  12587. * Each column in DataTables has a type assigned to it, either by automatic
  12588. * detection or by direct assignment using the `type` option for the column.
  12589. * The type of a column will effect how it is ordering and search (plug-ins
  12590. * can also make use of the column type if required).
  12591. *
  12592. * @namespace
  12593. */
  12594. type: {
  12595. /**
  12596. * Type detection functions.
  12597. *
  12598. * The functions defined in this object are used to automatically detect
  12599. * a column's type, making initialisation of DataTables super easy, even
  12600. * when complex data is in the table.
  12601. *
  12602. * The functions defined take two parameters:
  12603. *
  12604. * 1. `{*}` Data from the column cell to be analysed
  12605. * 2. `{settings}` DataTables settings object. This can be used to
  12606. * perform context specific type detection - for example detection
  12607. * based on language settings such as using a comma for a decimal
  12608. * place. Generally speaking the options from the settings will not
  12609. * be required
  12610. *
  12611. * Each function is expected to return:
  12612. *
  12613. * * `{string|null}` Data type detected, or null if unknown (and thus
  12614. * pass it on to the other type detection functions.
  12615. *
  12616. * @type array
  12617. *
  12618. * @example
  12619. * // Currency type detection plug-in:
  12620. * $.fn.dataTable.ext.type.detect.push(
  12621. * function ( data, settings ) {
  12622. * // Check the numeric part
  12623. * if ( ! data.substring(1).match(/[0-9]/) ) {
  12624. * return null;
  12625. * }
  12626. *
  12627. * // Check prefixed by currency
  12628. * if ( data.charAt(0) == '$' || data.charAt(0) == '&pound;' ) {
  12629. * return 'currency';
  12630. * }
  12631. * return null;
  12632. * }
  12633. * );
  12634. */
  12635. detect: [],
  12636. /**
  12637. * Type based search formatting.
  12638. *
  12639. * The type based searching functions can be used to pre-format the
  12640. * data to be search on. For example, it can be used to strip HTML
  12641. * tags or to de-format telephone numbers for numeric only searching.
  12642. *
  12643. * Note that is a search is not defined for a column of a given type,
  12644. * no search formatting will be performed.
  12645. *
  12646. * Pre-processing of searching data plug-ins - When you assign the sType
  12647. * for a column (or have it automatically detected for you by DataTables
  12648. * or a type detection plug-in), you will typically be using this for
  12649. * custom sorting, but it can also be used to provide custom searching
  12650. * by allowing you to pre-processing the data and returning the data in
  12651. * the format that should be searched upon. This is done by adding
  12652. * functions this object with a parameter name which matches the sType
  12653. * for that target column. This is the corollary of <i>afnSortData</i>
  12654. * for searching data.
  12655. *
  12656. * The functions defined take a single parameter:
  12657. *
  12658. * 1. `{*}` Data from the column cell to be prepared for searching
  12659. *
  12660. * Each function is expected to return:
  12661. *
  12662. * * `{string|null}` Formatted string that will be used for the searching.
  12663. *
  12664. * @type object
  12665. * @default {}
  12666. *
  12667. * @example
  12668. * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
  12669. * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
  12670. * }
  12671. */
  12672. search: {},
  12673. /**
  12674. * Type based ordering.
  12675. *
  12676. * The column type tells DataTables what ordering to apply to the table
  12677. * when a column is sorted upon. The order for each type that is defined,
  12678. * is defined by the functions available in this object.
  12679. *
  12680. * Each ordering option can be described by three properties added to
  12681. * this object:
  12682. *
  12683. * * `{type}-pre` - Pre-formatting function
  12684. * * `{type}-asc` - Ascending order function
  12685. * * `{type}-desc` - Descending order function
  12686. *
  12687. * All three can be used together, only `{type}-pre` or only
  12688. * `{type}-asc` and `{type}-desc` together. It is generally recommended
  12689. * that only `{type}-pre` is used, as this provides the optimal
  12690. * implementation in terms of speed, although the others are provided
  12691. * for compatibility with existing Javascript sort functions.
  12692. *
  12693. * `{type}-pre`: Functions defined take a single parameter:
  12694. *
  12695. * 1. `{*}` Data from the column cell to be prepared for ordering
  12696. *
  12697. * And return:
  12698. *
  12699. * * `{*}` Data to be sorted upon
  12700. *
  12701. * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
  12702. * functions, taking two parameters:
  12703. *
  12704. * 1. `{*}` Data to compare to the second parameter
  12705. * 2. `{*}` Data to compare to the first parameter
  12706. *
  12707. * And returning:
  12708. *
  12709. * * `{*}` Ordering match: <0 if first parameter should be sorted lower
  12710. * than the second parameter, ===0 if the two parameters are equal and
  12711. * >0 if the first parameter should be sorted height than the second
  12712. * parameter.
  12713. *
  12714. * @type object
  12715. * @default {}
  12716. *
  12717. * @example
  12718. * // Numeric ordering of formatted numbers with a pre-formatter
  12719. * $.extend( $.fn.dataTable.ext.type.order, {
  12720. * "string-pre": function(x) {
  12721. * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  12722. * return parseFloat( a );
  12723. * }
  12724. * } );
  12725. *
  12726. * @example
  12727. * // Case-sensitive string ordering, with no pre-formatting method
  12728. * $.extend( $.fn.dataTable.ext.order, {
  12729. * "string-case-asc": function(x,y) {
  12730. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12731. * },
  12732. * "string-case-desc": function(x,y) {
  12733. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12734. * }
  12735. * } );
  12736. */
  12737. order: {}
  12738. },
  12739. /**
  12740. * Unique DataTables instance counter
  12741. *
  12742. * @type int
  12743. * @private
  12744. */
  12745. _unique: 0,
  12746. //
  12747. // Depreciated
  12748. // The following properties are retained for backwards compatibility only.
  12749. // The should not be used in new projects and will be removed in a future
  12750. // version
  12751. //
  12752. /**
  12753. * Version check function.
  12754. * @type function
  12755. * @depreciated Since 1.10
  12756. */
  12757. fnVersionCheck: DataTable.fnVersionCheck,
  12758. /**
  12759. * Index for what 'this' index API functions should use
  12760. * @type int
  12761. * @deprecated Since v1.10
  12762. */
  12763. iApiIndex: 0,
  12764. /**
  12765. * jQuery UI class container
  12766. * @type object
  12767. * @deprecated Since v1.10
  12768. */
  12769. oJUIClasses: {},
  12770. /**
  12771. * Software version
  12772. * @type string
  12773. * @deprecated Since v1.10
  12774. */
  12775. sVersion: DataTable.version
  12776. };
  12777. //
  12778. // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
  12779. //
  12780. $.extend( _ext, {
  12781. afnFiltering: _ext.search,
  12782. aTypes: _ext.type.detect,
  12783. ofnSearch: _ext.type.search,
  12784. oSort: _ext.type.order,
  12785. afnSortData: _ext.order,
  12786. aoFeatures: _ext.feature,
  12787. oApi: _ext.internal,
  12788. oStdClasses: _ext.classes,
  12789. oPagination: _ext.pager
  12790. } );
  12791. $.extend( DataTable.ext.classes, {
  12792. "sTable": "dataTable",
  12793. "sNoFooter": "no-footer",
  12794. /* Paging buttons */
  12795. "sPageButton": "paginate_button",
  12796. "sPageButtonActive": "current",
  12797. "sPageButtonDisabled": "disabled",
  12798. /* Striping classes */
  12799. "sStripeOdd": "odd",
  12800. "sStripeEven": "even",
  12801. /* Empty row */
  12802. "sRowEmpty": "dataTables_empty",
  12803. /* Features */
  12804. "sWrapper": "dataTables_wrapper",
  12805. "sFilter": "dataTables_filter",
  12806. "sInfo": "dataTables_info",
  12807. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  12808. "sLength": "dataTables_length",
  12809. "sProcessing": "dataTables_processing",
  12810. /* Sorting */
  12811. "sSortAsc": "sorting_asc",
  12812. "sSortDesc": "sorting_desc",
  12813. "sSortable": "sorting", /* Sortable in both directions */
  12814. "sSortableAsc": "sorting_desc_disabled",
  12815. "sSortableDesc": "sorting_asc_disabled",
  12816. "sSortableNone": "sorting_disabled",
  12817. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  12818. /* Filtering */
  12819. "sFilterInput": "",
  12820. /* Page length */
  12821. "sLengthSelect": "",
  12822. /* Scrolling */
  12823. "sScrollWrapper": "dataTables_scroll",
  12824. "sScrollHead": "dataTables_scrollHead",
  12825. "sScrollHeadInner": "dataTables_scrollHeadInner",
  12826. "sScrollBody": "dataTables_scrollBody",
  12827. "sScrollFoot": "dataTables_scrollFoot",
  12828. "sScrollFootInner": "dataTables_scrollFootInner",
  12829. /* Misc */
  12830. "sHeaderTH": "",
  12831. "sFooterTH": "",
  12832. // Deprecated
  12833. "sSortJUIAsc": "",
  12834. "sSortJUIDesc": "",
  12835. "sSortJUI": "",
  12836. "sSortJUIAscAllowed": "",
  12837. "sSortJUIDescAllowed": "",
  12838. "sSortJUIWrapper": "",
  12839. "sSortIcon": "",
  12840. "sJUIHeader": "",
  12841. "sJUIFooter": ""
  12842. } );
  12843. var extPagination = DataTable.ext.pager;
  12844. function _numbers ( page, pages ) {
  12845. var
  12846. numbers = [],
  12847. buttons = extPagination.numbers_length,
  12848. half = Math.floor( buttons / 2 ),
  12849. i = 1;
  12850. if ( pages <= buttons ) {
  12851. numbers = _range( 0, pages );
  12852. }
  12853. else if ( page <= half ) {
  12854. numbers = _range( 0, buttons-2 );
  12855. numbers.push( 'ellipsis' );
  12856. numbers.push( pages-1 );
  12857. }
  12858. else if ( page >= pages - 1 - half ) {
  12859. numbers = _range( pages-(buttons-2), pages );
  12860. numbers.splice( 0, 0, 'ellipsis' ); // no unshift in ie6
  12861. numbers.splice( 0, 0, 0 );
  12862. }
  12863. else {
  12864. numbers = _range( page-half+2, page+half-1 );
  12865. numbers.push( 'ellipsis' );
  12866. numbers.push( pages-1 );
  12867. numbers.splice( 0, 0, 'ellipsis' );
  12868. numbers.splice( 0, 0, 0 );
  12869. }
  12870. numbers.DT_el = 'span';
  12871. return numbers;
  12872. }
  12873. $.extend( extPagination, {
  12874. simple: function ( page, pages ) {
  12875. return [ 'previous', 'next' ];
  12876. },
  12877. full: function ( page, pages ) {
  12878. return [ 'first', 'previous', 'next', 'last' ];
  12879. },
  12880. numbers: function ( page, pages ) {
  12881. return [ _numbers(page, pages) ];
  12882. },
  12883. simple_numbers: function ( page, pages ) {
  12884. return [ 'previous', _numbers(page, pages), 'next' ];
  12885. },
  12886. full_numbers: function ( page, pages ) {
  12887. return [ 'first', 'previous', _numbers(page, pages), 'next', 'last' ];
  12888. },
  12889. first_last_numbers: function (page, pages) {
  12890. return ['first', _numbers(page, pages), 'last'];
  12891. },
  12892. // For testing and plug-ins to use
  12893. _numbers: _numbers,
  12894. // Number of number buttons (including ellipsis) to show. _Must be odd!_
  12895. numbers_length: 7
  12896. } );
  12897. $.extend( true, DataTable.ext.renderer, {
  12898. pageButton: {
  12899. _: function ( settings, host, idx, buttons, page, pages ) {
  12900. var classes = settings.oClasses;
  12901. var lang = settings.oLanguage.oPaginate;
  12902. var aria = settings.oLanguage.oAria.paginate || {};
  12903. var btnDisplay, btnClass;
  12904. var attach = function( container, buttons ) {
  12905. var i, ien, node, button, tabIndex;
  12906. var disabledClass = classes.sPageButtonDisabled;
  12907. var clickHandler = function ( e ) {
  12908. _fnPageChange( settings, e.data.action, true );
  12909. };
  12910. for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
  12911. button = buttons[i];
  12912. if ( Array.isArray( button ) ) {
  12913. var inner = $( '<'+(button.DT_el || 'div')+'/>' )
  12914. .appendTo( container );
  12915. attach( inner, button );
  12916. }
  12917. else {
  12918. btnDisplay = null;
  12919. btnClass = button;
  12920. tabIndex = settings.iTabIndex;
  12921. switch ( button ) {
  12922. case 'ellipsis':
  12923. container.append('<span class="ellipsis">&#x2026;</span>');
  12924. break;
  12925. case 'first':
  12926. btnDisplay = lang.sFirst;
  12927. if ( page === 0 ) {
  12928. tabIndex = -1;
  12929. btnClass += ' ' + disabledClass;
  12930. }
  12931. break;
  12932. case 'previous':
  12933. btnDisplay = lang.sPrevious;
  12934. if ( page === 0 ) {
  12935. tabIndex = -1;
  12936. btnClass += ' ' + disabledClass;
  12937. }
  12938. break;
  12939. case 'next':
  12940. btnDisplay = lang.sNext;
  12941. if ( pages === 0 || page === pages-1 ) {
  12942. tabIndex = -1;
  12943. btnClass += ' ' + disabledClass;
  12944. }
  12945. break;
  12946. case 'last':
  12947. btnDisplay = lang.sLast;
  12948. if ( pages === 0 || page === pages-1 ) {
  12949. tabIndex = -1;
  12950. btnClass += ' ' + disabledClass;
  12951. }
  12952. break;
  12953. default:
  12954. btnDisplay = settings.fnFormatNumber( button + 1 );
  12955. btnClass = page === button ?
  12956. classes.sPageButtonActive : '';
  12957. break;
  12958. }
  12959. if ( btnDisplay !== null ) {
  12960. var tag = settings.oInit.pagingTag || 'a';
  12961. var disabled = btnClass.indexOf(disabledClass) !== -1;
  12962. node = $('<'+tag+'>', {
  12963. 'class': classes.sPageButton+' '+btnClass,
  12964. 'aria-controls': settings.sTableId,
  12965. 'aria-disabled': disabled ? 'true' : null,
  12966. 'aria-label': aria[ button ],
  12967. 'role': 'link',
  12968. 'aria-current': btnClass === classes.sPageButtonActive ? 'page' : null,
  12969. 'data-dt-idx': button,
  12970. 'tabindex': tabIndex,
  12971. 'id': idx === 0 && typeof button === 'string' ?
  12972. settings.sTableId +'_'+ button :
  12973. null
  12974. } )
  12975. .html( btnDisplay )
  12976. .appendTo( container );
  12977. _fnBindAction(
  12978. node, {action: button}, clickHandler
  12979. );
  12980. }
  12981. }
  12982. }
  12983. };
  12984. // IE9 throws an 'unknown error' if document.activeElement is used
  12985. // inside an iframe or frame. Try / catch the error. Not good for
  12986. // accessibility, but neither are frames.
  12987. var activeEl;
  12988. try {
  12989. // Because this approach is destroying and recreating the paging
  12990. // elements, focus is lost on the select button which is bad for
  12991. // accessibility. So we want to restore focus once the draw has
  12992. // completed
  12993. activeEl = $(host).find(document.activeElement).data('dt-idx');
  12994. }
  12995. catch (e) {}
  12996. attach( $(host).empty(), buttons );
  12997. if ( activeEl !== undefined ) {
  12998. $(host).find( '[data-dt-idx='+activeEl+']' ).trigger('focus');
  12999. }
  13000. }
  13001. }
  13002. } );
  13003. // Built in type detection. See model.ext.aTypes for information about
  13004. // what is required from this methods.
  13005. $.extend( DataTable.ext.type.detect, [
  13006. // Plain numbers - first since V8 detects some plain numbers as dates
  13007. // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
  13008. function ( d, settings )
  13009. {
  13010. var decimal = settings.oLanguage.sDecimal;
  13011. return _isNumber( d, decimal ) ? 'num'+decimal : null;
  13012. },
  13013. // Dates (only those recognised by the browser's Date.parse)
  13014. function ( d, settings )
  13015. {
  13016. // V8 tries _very_ hard to make a string passed into `Date.parse()`
  13017. // valid, so we need to use a regex to restrict date formats. Use a
  13018. // plug-in for anything other than ISO8601 style strings
  13019. if ( d && !(d instanceof Date) && ! _re_date.test(d) ) {
  13020. return null;
  13021. }
  13022. var parsed = Date.parse(d);
  13023. return (parsed !== null && !isNaN(parsed)) || _empty(d) ? 'date' : null;
  13024. },
  13025. // Formatted numbers
  13026. function ( d, settings )
  13027. {
  13028. var decimal = settings.oLanguage.sDecimal;
  13029. return _isNumber( d, decimal, true ) ? 'num-fmt'+decimal : null;
  13030. },
  13031. // HTML numeric
  13032. function ( d, settings )
  13033. {
  13034. var decimal = settings.oLanguage.sDecimal;
  13035. return _htmlNumeric( d, decimal ) ? 'html-num'+decimal : null;
  13036. },
  13037. // HTML numeric, formatted
  13038. function ( d, settings )
  13039. {
  13040. var decimal = settings.oLanguage.sDecimal;
  13041. return _htmlNumeric( d, decimal, true ) ? 'html-num-fmt'+decimal : null;
  13042. },
  13043. // HTML (this is strict checking - there must be html)
  13044. function ( d, settings )
  13045. {
  13046. return _empty( d ) || (typeof d === 'string' && d.indexOf('<') !== -1) ?
  13047. 'html' : null;
  13048. }
  13049. ] );
  13050. // Filter formatting functions. See model.ext.ofnSearch for information about
  13051. // what is required from these methods.
  13052. //
  13053. // Note that additional search methods are added for the html numbers and
  13054. // html formatted numbers by `_addNumericSort()` when we know what the decimal
  13055. // place is
  13056. $.extend( DataTable.ext.type.search, {
  13057. html: function ( data ) {
  13058. return _empty(data) ?
  13059. data :
  13060. typeof data === 'string' ?
  13061. data
  13062. .replace( _re_new_lines, " " )
  13063. .replace( _re_html, "" ) :
  13064. '';
  13065. },
  13066. string: function ( data ) {
  13067. return _empty(data) ?
  13068. data :
  13069. typeof data === 'string' ?
  13070. data.replace( _re_new_lines, " " ) :
  13071. data;
  13072. }
  13073. } );
  13074. var __numericReplace = function ( d, decimalPlace, re1, re2 ) {
  13075. if ( d !== 0 && (!d || d === '-') ) {
  13076. return -Infinity;
  13077. }
  13078. var type = typeof d;
  13079. if (type === 'number' || type === 'bigint') {
  13080. return d;
  13081. }
  13082. // If a decimal place other than `.` is used, it needs to be given to the
  13083. // function so we can detect it and replace with a `.` which is the only
  13084. // decimal place Javascript recognises - it is not locale aware.
  13085. if ( decimalPlace ) {
  13086. d = _numToDecimal( d, decimalPlace );
  13087. }
  13088. if ( d.replace ) {
  13089. if ( re1 ) {
  13090. d = d.replace( re1, '' );
  13091. }
  13092. if ( re2 ) {
  13093. d = d.replace( re2, '' );
  13094. }
  13095. }
  13096. return d * 1;
  13097. };
  13098. // Add the numeric 'deformatting' functions for sorting and search. This is done
  13099. // in a function to provide an easy ability for the language options to add
  13100. // additional methods if a non-period decimal place is used.
  13101. function _addNumericSort ( decimalPlace ) {
  13102. $.each(
  13103. {
  13104. // Plain numbers
  13105. "num": function ( d ) {
  13106. return __numericReplace( d, decimalPlace );
  13107. },
  13108. // Formatted numbers
  13109. "num-fmt": function ( d ) {
  13110. return __numericReplace( d, decimalPlace, _re_formatted_numeric );
  13111. },
  13112. // HTML numeric
  13113. "html-num": function ( d ) {
  13114. return __numericReplace( d, decimalPlace, _re_html );
  13115. },
  13116. // HTML numeric, formatted
  13117. "html-num-fmt": function ( d ) {
  13118. return __numericReplace( d, decimalPlace, _re_html, _re_formatted_numeric );
  13119. }
  13120. },
  13121. function ( key, fn ) {
  13122. // Add the ordering method
  13123. _ext.type.order[ key+decimalPlace+'-pre' ] = fn;
  13124. // For HTML types add a search formatter that will strip the HTML
  13125. if ( key.match(/^html\-/) ) {
  13126. _ext.type.search[ key+decimalPlace ] = _ext.type.search.html;
  13127. }
  13128. }
  13129. );
  13130. }
  13131. // Default sort methods
  13132. $.extend( _ext.type.order, {
  13133. // Dates
  13134. "date-pre": function ( d ) {
  13135. var ts = Date.parse( d );
  13136. return isNaN(ts) ? -Infinity : ts;
  13137. },
  13138. // html
  13139. "html-pre": function ( a ) {
  13140. return _empty(a) ?
  13141. '' :
  13142. a.replace ?
  13143. a.replace( /<.*?>/g, "" ).toLowerCase() :
  13144. a+'';
  13145. },
  13146. // string
  13147. "string-pre": function ( a ) {
  13148. // This is a little complex, but faster than always calling toString,
  13149. // http://jsperf.com/tostring-v-check
  13150. return _empty(a) ?
  13151. '' :
  13152. typeof a === 'string' ?
  13153. a.toLowerCase() :
  13154. ! a.toString ?
  13155. '' :
  13156. a.toString();
  13157. },
  13158. // string-asc and -desc are retained only for compatibility with the old
  13159. // sort methods
  13160. "string-asc": function ( x, y ) {
  13161. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  13162. },
  13163. "string-desc": function ( x, y ) {
  13164. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  13165. }
  13166. } );
  13167. // Numeric sorting types - order doesn't matter here
  13168. _addNumericSort( '' );
  13169. $.extend( true, DataTable.ext.renderer, {
  13170. header: {
  13171. _: function ( settings, cell, column, classes ) {
  13172. // No additional mark-up required
  13173. // Attach a sort listener to update on sort - note that using the
  13174. // `DT` namespace will allow the event to be removed automatically
  13175. // on destroy, while the `dt` namespaced event is the one we are
  13176. // listening for
  13177. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  13178. if ( settings !== ctx ) { // need to check this this is the host
  13179. return; // table, not a nested one
  13180. }
  13181. var colIdx = column.idx;
  13182. cell
  13183. .removeClass(
  13184. classes.sSortAsc +' '+
  13185. classes.sSortDesc
  13186. )
  13187. .addClass( columns[ colIdx ] == 'asc' ?
  13188. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  13189. classes.sSortDesc :
  13190. column.sSortingClass
  13191. );
  13192. } );
  13193. },
  13194. jqueryui: function ( settings, cell, column, classes ) {
  13195. $('<div/>')
  13196. .addClass( classes.sSortJUIWrapper )
  13197. .append( cell.contents() )
  13198. .append( $('<span/>')
  13199. .addClass( classes.sSortIcon+' '+column.sSortingClassJUI )
  13200. )
  13201. .appendTo( cell );
  13202. // Attach a sort listener to update on sort
  13203. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  13204. if ( settings !== ctx ) {
  13205. return;
  13206. }
  13207. var colIdx = column.idx;
  13208. cell
  13209. .removeClass( classes.sSortAsc +" "+classes.sSortDesc )
  13210. .addClass( columns[ colIdx ] == 'asc' ?
  13211. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  13212. classes.sSortDesc :
  13213. column.sSortingClass
  13214. );
  13215. cell
  13216. .find( 'span.'+classes.sSortIcon )
  13217. .removeClass(
  13218. classes.sSortJUIAsc +" "+
  13219. classes.sSortJUIDesc +" "+
  13220. classes.sSortJUI +" "+
  13221. classes.sSortJUIAscAllowed +" "+
  13222. classes.sSortJUIDescAllowed
  13223. )
  13224. .addClass( columns[ colIdx ] == 'asc' ?
  13225. classes.sSortJUIAsc : columns[ colIdx ] == 'desc' ?
  13226. classes.sSortJUIDesc :
  13227. column.sSortingClassJUI
  13228. );
  13229. } );
  13230. }
  13231. }
  13232. } );
  13233. /*
  13234. * Public helper functions. These aren't used internally by DataTables, or
  13235. * called by any of the options passed into DataTables, but they can be used
  13236. * externally by developers working with DataTables. They are helper functions
  13237. * to make working with DataTables a little bit easier.
  13238. */
  13239. var __htmlEscapeEntities = function ( d ) {
  13240. if (Array.isArray(d)) {
  13241. d = d.join(',');
  13242. }
  13243. return typeof d === 'string' ?
  13244. d
  13245. .replace(/&/g, '&amp;')
  13246. .replace(/</g, '&lt;')
  13247. .replace(/>/g, '&gt;')
  13248. .replace(/"/g, '&quot;') :
  13249. d;
  13250. };
  13251. // Common logic for moment, luxon or a date action
  13252. function __mld( dt, momentFn, luxonFn, dateFn, arg1 ) {
  13253. if (window.moment) {
  13254. return dt[momentFn]( arg1 );
  13255. }
  13256. else if (window.luxon) {
  13257. return dt[luxonFn]( arg1 );
  13258. }
  13259. return dateFn ? dt[dateFn]( arg1 ) : dt;
  13260. }
  13261. var __mlWarning = false;
  13262. function __mldObj (d, format, locale) {
  13263. var dt;
  13264. if (window.moment) {
  13265. dt = window.moment.utc( d, format, locale, true );
  13266. if (! dt.isValid()) {
  13267. return null;
  13268. }
  13269. }
  13270. else if (window.luxon) {
  13271. dt = format && typeof d === 'string'
  13272. ? window.luxon.DateTime.fromFormat( d, format )
  13273. : window.luxon.DateTime.fromISO( d );
  13274. if (! dt.isValid) {
  13275. return null;
  13276. }
  13277. dt.setLocale(locale);
  13278. }
  13279. else if (! format) {
  13280. // No format given, must be ISO
  13281. dt = new Date(d);
  13282. }
  13283. else {
  13284. if (! __mlWarning) {
  13285. alert('DataTables warning: Formatted date without Moment.js or Luxon - https://datatables.net/tn/17');
  13286. }
  13287. __mlWarning = true;
  13288. }
  13289. return dt;
  13290. }
  13291. // Wrapper for date, datetime and time which all operate the same way with the exception of
  13292. // the output string for auto locale support
  13293. function __mlHelper (localeString) {
  13294. return function ( from, to, locale, def ) {
  13295. // Luxon and Moment support
  13296. // Argument shifting
  13297. if ( arguments.length === 0 ) {
  13298. locale = 'en';
  13299. to = null; // means toLocaleString
  13300. from = null; // means iso8601
  13301. }
  13302. else if ( arguments.length === 1 ) {
  13303. locale = 'en';
  13304. to = from;
  13305. from = null;
  13306. }
  13307. else if ( arguments.length === 2 ) {
  13308. locale = to;
  13309. to = from;
  13310. from = null;
  13311. }
  13312. var typeName = 'datetime-' + to;
  13313. // Add type detection and sorting specific to this date format - we need to be able to identify
  13314. // date type columns as such, rather than as numbers in extensions. Hence the need for this.
  13315. if (! DataTable.ext.type.order[typeName]) {
  13316. // The renderer will give the value to type detect as the type!
  13317. DataTable.ext.type.detect.unshift(function (d) {
  13318. return d === typeName ? typeName : false;
  13319. });
  13320. // The renderer gives us Moment, Luxon or Date obects for the sorting, all of which have a
  13321. // `valueOf` which gives milliseconds epoch
  13322. DataTable.ext.type.order[typeName + '-asc'] = function (a, b) {
  13323. var x = a.valueOf();
  13324. var y = b.valueOf();
  13325. return x === y
  13326. ? 0
  13327. : x < y
  13328. ? -1
  13329. : 1;
  13330. }
  13331. DataTable.ext.type.order[typeName + '-desc'] = function (a, b) {
  13332. var x = a.valueOf();
  13333. var y = b.valueOf();
  13334. return x === y
  13335. ? 0
  13336. : x > y
  13337. ? -1
  13338. : 1;
  13339. }
  13340. }
  13341. return function ( d, type ) {
  13342. // Allow for a default value
  13343. if (d === null || d === undefined) {
  13344. if (def === '--now') {
  13345. // We treat everything as UTC further down, so no changes are
  13346. // made, as such need to get the local date / time as if it were
  13347. // UTC
  13348. var local = new Date();
  13349. d = new Date( Date.UTC(
  13350. local.getFullYear(), local.getMonth(), local.getDate(),
  13351. local.getHours(), local.getMinutes(), local.getSeconds()
  13352. ) );
  13353. }
  13354. else {
  13355. d = '';
  13356. }
  13357. }
  13358. if (type === 'type') {
  13359. // Typing uses the type name for fast matching
  13360. return typeName;
  13361. }
  13362. if (d === '') {
  13363. return type !== 'sort'
  13364. ? ''
  13365. : __mldObj('0000-01-01 00:00:00', null, locale);
  13366. }
  13367. // Shortcut. If `from` and `to` are the same, we are using the renderer to
  13368. // format for ordering, not display - its already in the display format.
  13369. if ( to !== null && from === to && type !== 'sort' && type !== 'type' && ! (d instanceof Date) ) {
  13370. return d;
  13371. }
  13372. var dt = __mldObj(d, from, locale);
  13373. if (dt === null) {
  13374. return d;
  13375. }
  13376. if (type === 'sort') {
  13377. return dt;
  13378. }
  13379. var formatted = to === null
  13380. ? __mld(dt, 'toDate', 'toJSDate', '')[localeString]()
  13381. : __mld(dt, 'format', 'toFormat', 'toISOString', to);
  13382. // XSS protection
  13383. return type === 'display' ?
  13384. __htmlEscapeEntities( formatted ) :
  13385. formatted;
  13386. };
  13387. }
  13388. }
  13389. // Based on locale, determine standard number formatting
  13390. // Fallback for legacy browsers is US English
  13391. var __thousands = ',';
  13392. var __decimal = '.';
  13393. if (window.Intl !== undefined) {
  13394. try {
  13395. var num = new Intl.NumberFormat().formatToParts(100000.1);
  13396. for (var i=0 ; i<num.length ; i++) {
  13397. if (num[i].type === 'group') {
  13398. __thousands = num[i].value;
  13399. }
  13400. else if (num[i].type === 'decimal') {
  13401. __decimal = num[i].value;
  13402. }
  13403. }
  13404. }
  13405. catch (e) {
  13406. // noop
  13407. }
  13408. }
  13409. // Formatted date time detection - use by declaring the formats you are going to use
  13410. DataTable.datetime = function ( format, locale ) {
  13411. var typeName = 'datetime-detect-' + format;
  13412. if (! locale) {
  13413. locale = 'en';
  13414. }
  13415. if (! DataTable.ext.type.order[typeName]) {
  13416. DataTable.ext.type.detect.unshift(function (d) {
  13417. var dt = __mldObj(d, format, locale);
  13418. return d === '' || dt ? typeName : false;
  13419. });
  13420. DataTable.ext.type.order[typeName + '-pre'] = function (d) {
  13421. return __mldObj(d, format, locale) || 0;
  13422. }
  13423. }
  13424. }
  13425. /**
  13426. * Helpers for `columns.render`.
  13427. *
  13428. * The options defined here can be used with the `columns.render` initialisation
  13429. * option to provide a display renderer. The following functions are defined:
  13430. *
  13431. * * `number` - Will format numeric data (defined by `columns.data`) for
  13432. * display, retaining the original unformatted data for sorting and filtering.
  13433. * It takes 5 parameters:
  13434. * * `string` - Thousands grouping separator
  13435. * * `string` - Decimal point indicator
  13436. * * `integer` - Number of decimal points to show
  13437. * * `string` (optional) - Prefix.
  13438. * * `string` (optional) - Postfix (/suffix).
  13439. * * `text` - Escape HTML to help prevent XSS attacks. It has no optional
  13440. * parameters.
  13441. *
  13442. * @example
  13443. * // Column definition using the number renderer
  13444. * {
  13445. * data: "salary",
  13446. * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
  13447. * }
  13448. *
  13449. * @namespace
  13450. */
  13451. DataTable.render = {
  13452. date: __mlHelper('toLocaleDateString'),
  13453. datetime: __mlHelper('toLocaleString'),
  13454. time: __mlHelper('toLocaleTimeString'),
  13455. number: function ( thousands, decimal, precision, prefix, postfix ) {
  13456. // Auto locale detection
  13457. if (thousands === null || thousands === undefined) {
  13458. thousands = __thousands;
  13459. }
  13460. if (decimal === null || decimal === undefined) {
  13461. decimal = __decimal;
  13462. }
  13463. return {
  13464. display: function ( d ) {
  13465. if ( typeof d !== 'number' && typeof d !== 'string' ) {
  13466. return d;
  13467. }
  13468. if (d === '' || d === null) {
  13469. return d;
  13470. }
  13471. var negative = d < 0 ? '-' : '';
  13472. var flo = parseFloat( d );
  13473. // If NaN then there isn't much formatting that we can do - just
  13474. // return immediately, escaping any HTML (this was supposed to
  13475. // be a number after all)
  13476. if ( isNaN( flo ) ) {
  13477. return __htmlEscapeEntities( d );
  13478. }
  13479. flo = flo.toFixed( precision );
  13480. d = Math.abs( flo );
  13481. var intPart = parseInt( d, 10 );
  13482. var floatPart = precision ?
  13483. decimal+(d - intPart).toFixed( precision ).substring( 2 ):
  13484. '';
  13485. // If zero, then can't have a negative prefix
  13486. if (intPart === 0 && parseFloat(floatPart) === 0) {
  13487. negative = '';
  13488. }
  13489. return negative + (prefix||'') +
  13490. intPart.toString().replace(
  13491. /\B(?=(\d{3})+(?!\d))/g, thousands
  13492. ) +
  13493. floatPart +
  13494. (postfix||'');
  13495. }
  13496. };
  13497. },
  13498. text: function () {
  13499. return {
  13500. display: __htmlEscapeEntities,
  13501. filter: __htmlEscapeEntities
  13502. };
  13503. }
  13504. };
  13505. /*
  13506. * This is really a good bit rubbish this method of exposing the internal methods
  13507. * publicly... - To be fixed in 2.0 using methods on the prototype
  13508. */
  13509. /**
  13510. * Create a wrapper function for exporting an internal functions to an external API.
  13511. * @param {string} fn API function name
  13512. * @returns {function} wrapped function
  13513. * @memberof DataTable#internal
  13514. */
  13515. function _fnExternApiFunc (fn)
  13516. {
  13517. return function() {
  13518. var args = [_fnSettingsFromNode( this[DataTable.ext.iApiIndex] )].concat(
  13519. Array.prototype.slice.call(arguments)
  13520. );
  13521. return DataTable.ext.internal[fn].apply( this, args );
  13522. };
  13523. }
  13524. /**
  13525. * Reference to internal functions for use by plug-in developers. Note that
  13526. * these methods are references to internal functions and are considered to be
  13527. * private. If you use these methods, be aware that they are liable to change
  13528. * between versions.
  13529. * @namespace
  13530. */
  13531. $.extend( DataTable.ext.internal, {
  13532. _fnExternApiFunc: _fnExternApiFunc,
  13533. _fnBuildAjax: _fnBuildAjax,
  13534. _fnAjaxUpdate: _fnAjaxUpdate,
  13535. _fnAjaxParameters: _fnAjaxParameters,
  13536. _fnAjaxUpdateDraw: _fnAjaxUpdateDraw,
  13537. _fnAjaxDataSrc: _fnAjaxDataSrc,
  13538. _fnAddColumn: _fnAddColumn,
  13539. _fnColumnOptions: _fnColumnOptions,
  13540. _fnAdjustColumnSizing: _fnAdjustColumnSizing,
  13541. _fnVisibleToColumnIndex: _fnVisibleToColumnIndex,
  13542. _fnColumnIndexToVisible: _fnColumnIndexToVisible,
  13543. _fnVisbleColumns: _fnVisbleColumns,
  13544. _fnGetColumns: _fnGetColumns,
  13545. _fnColumnTypes: _fnColumnTypes,
  13546. _fnApplyColumnDefs: _fnApplyColumnDefs,
  13547. _fnHungarianMap: _fnHungarianMap,
  13548. _fnCamelToHungarian: _fnCamelToHungarian,
  13549. _fnLanguageCompat: _fnLanguageCompat,
  13550. _fnBrowserDetect: _fnBrowserDetect,
  13551. _fnAddData: _fnAddData,
  13552. _fnAddTr: _fnAddTr,
  13553. _fnNodeToDataIndex: _fnNodeToDataIndex,
  13554. _fnNodeToColumnIndex: _fnNodeToColumnIndex,
  13555. _fnGetCellData: _fnGetCellData,
  13556. _fnSetCellData: _fnSetCellData,
  13557. _fnSplitObjNotation: _fnSplitObjNotation,
  13558. _fnGetObjectDataFn: _fnGetObjectDataFn,
  13559. _fnSetObjectDataFn: _fnSetObjectDataFn,
  13560. _fnGetDataMaster: _fnGetDataMaster,
  13561. _fnClearTable: _fnClearTable,
  13562. _fnDeleteIndex: _fnDeleteIndex,
  13563. _fnInvalidate: _fnInvalidate,
  13564. _fnGetRowElements: _fnGetRowElements,
  13565. _fnCreateTr: _fnCreateTr,
  13566. _fnBuildHead: _fnBuildHead,
  13567. _fnDrawHead: _fnDrawHead,
  13568. _fnDraw: _fnDraw,
  13569. _fnReDraw: _fnReDraw,
  13570. _fnAddOptionsHtml: _fnAddOptionsHtml,
  13571. _fnDetectHeader: _fnDetectHeader,
  13572. _fnGetUniqueThs: _fnGetUniqueThs,
  13573. _fnFeatureHtmlFilter: _fnFeatureHtmlFilter,
  13574. _fnFilterComplete: _fnFilterComplete,
  13575. _fnFilterCustom: _fnFilterCustom,
  13576. _fnFilterColumn: _fnFilterColumn,
  13577. _fnFilter: _fnFilter,
  13578. _fnFilterCreateSearch: _fnFilterCreateSearch,
  13579. _fnEscapeRegex: _fnEscapeRegex,
  13580. _fnFilterData: _fnFilterData,
  13581. _fnFeatureHtmlInfo: _fnFeatureHtmlInfo,
  13582. _fnUpdateInfo: _fnUpdateInfo,
  13583. _fnInfoMacros: _fnInfoMacros,
  13584. _fnInitialise: _fnInitialise,
  13585. _fnInitComplete: _fnInitComplete,
  13586. _fnLengthChange: _fnLengthChange,
  13587. _fnFeatureHtmlLength: _fnFeatureHtmlLength,
  13588. _fnFeatureHtmlPaginate: _fnFeatureHtmlPaginate,
  13589. _fnPageChange: _fnPageChange,
  13590. _fnFeatureHtmlProcessing: _fnFeatureHtmlProcessing,
  13591. _fnProcessingDisplay: _fnProcessingDisplay,
  13592. _fnFeatureHtmlTable: _fnFeatureHtmlTable,
  13593. _fnScrollDraw: _fnScrollDraw,
  13594. _fnApplyToChildren: _fnApplyToChildren,
  13595. _fnCalculateColumnWidths: _fnCalculateColumnWidths,
  13596. _fnThrottle: _fnThrottle,
  13597. _fnConvertToWidth: _fnConvertToWidth,
  13598. _fnGetWidestNode: _fnGetWidestNode,
  13599. _fnGetMaxLenString: _fnGetMaxLenString,
  13600. _fnStringToCss: _fnStringToCss,
  13601. _fnSortFlatten: _fnSortFlatten,
  13602. _fnSort: _fnSort,
  13603. _fnSortAria: _fnSortAria,
  13604. _fnSortListener: _fnSortListener,
  13605. _fnSortAttachListener: _fnSortAttachListener,
  13606. _fnSortingClasses: _fnSortingClasses,
  13607. _fnSortData: _fnSortData,
  13608. _fnSaveState: _fnSaveState,
  13609. _fnLoadState: _fnLoadState,
  13610. _fnImplementState: _fnImplementState,
  13611. _fnSettingsFromNode: _fnSettingsFromNode,
  13612. _fnLog: _fnLog,
  13613. _fnMap: _fnMap,
  13614. _fnBindAction: _fnBindAction,
  13615. _fnCallbackReg: _fnCallbackReg,
  13616. _fnCallbackFire: _fnCallbackFire,
  13617. _fnLengthOverflow: _fnLengthOverflow,
  13618. _fnRenderer: _fnRenderer,
  13619. _fnDataSource: _fnDataSource,
  13620. _fnRowAttributes: _fnRowAttributes,
  13621. _fnExtend: _fnExtend,
  13622. _fnCalculateEnd: function () {} // Used by a lot of plug-ins, but redundant
  13623. // in 1.10, so this dead-end function is
  13624. // added to prevent errors
  13625. } );
  13626. // jQuery access
  13627. $.fn.dataTable = DataTable;
  13628. // Provide access to the host jQuery object (circular reference)
  13629. DataTable.$ = $;
  13630. // Legacy aliases
  13631. $.fn.dataTableSettings = DataTable.settings;
  13632. $.fn.dataTableExt = DataTable.ext;
  13633. // With a capital `D` we return a DataTables API instance rather than a
  13634. // jQuery object
  13635. $.fn.DataTable = function ( opts ) {
  13636. return $(this).dataTable( opts ).api();
  13637. };
  13638. // All properties that are available to $.fn.dataTable should also be
  13639. // available on $.fn.DataTable
  13640. $.each( DataTable, function ( prop, val ) {
  13641. $.fn.DataTable[ prop ] = val;
  13642. } );
  13643. return DataTable;
  13644. }));