jquery.dataTables.js 437 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296
  1. /*! DataTables 1.10.18
  2. * ©2008-2018 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary DataTables
  6. * @description Paginate, search and order HTML tables
  7. * @version 1.10.18
  8. * @file jquery.dataTables.js
  9. * @author SpryMedia Ltd
  10. * @contact www.datatables.net
  11. * @copyright Copyright 2008-2018 SpryMedia Ltd.
  12. *
  13. * This source file is free software, available under the following license:
  14. * MIT license - http://datatables.net/license
  15. *
  16. * This source file is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  18. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  19. *
  20. * For details please refer to: http://www.datatables.net
  21. */
  22. /*jslint evil: true, undef: true, browser: true */
  23. /*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*/
  24. (function( factory ) {
  25. "use strict";
  26. if ( typeof define === 'function' && define.amd ) {
  27. // AMD
  28. define( ['jquery'], function ( $ ) {
  29. return factory( $, window, document );
  30. } );
  31. }
  32. else if ( typeof exports === 'object' ) {
  33. // CommonJS
  34. module.exports = function (root, $) {
  35. if ( ! root ) {
  36. // CommonJS environments without a window global must pass a
  37. // root. This will give an error otherwise
  38. root = window;
  39. }
  40. if ( ! $ ) {
  41. $ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
  42. require('jquery') :
  43. require('jquery')( root );
  44. }
  45. return factory( $, root, root.document );
  46. };
  47. }
  48. else {
  49. // Browser
  50. factory( jQuery, window, document );
  51. }
  52. }
  53. (function( $, window, document, undefined ) {
  54. "use strict";
  55. /**
  56. * DataTables is a plug-in for the jQuery Javascript library. It is a highly
  57. * flexible tool, based upon the foundations of progressive enhancement,
  58. * which will add advanced interaction controls to any HTML table. For a
  59. * full list of features please refer to
  60. * [DataTables.net](href="http://datatables.net).
  61. *
  62. * Note that the `DataTable` object is not a global variable but is aliased
  63. * to `jQuery.fn.DataTable` and `jQuery.fn.dataTable` through which it may
  64. * be accessed.
  65. *
  66. * @class
  67. * @param {object} [init={}] Configuration object for DataTables. Options
  68. * are defined by {@link DataTable.defaults}
  69. * @requires jQuery 1.7+
  70. *
  71. * @example
  72. * // Basic initialisation
  73. * $(document).ready( function {
  74. * $('#example').dataTable();
  75. * } );
  76. *
  77. * @example
  78. * // Initialisation with configuration options - in this case, disable
  79. * // pagination and sorting.
  80. * $(document).ready( function {
  81. * $('#example').dataTable( {
  82. * "paginate": false,
  83. * "sort": false
  84. * } );
  85. * } );
  86. */
  87. var DataTable = function ( options )
  88. {
  89. /**
  90. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  91. * return the resulting jQuery object.
  92. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  93. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  94. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  95. * criterion ("applied") or all TR elements (i.e. no filter).
  96. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  97. * Can be either 'current', whereby the current sorting of the table is used, or
  98. * 'original' whereby the original order the data was read into the table is used.
  99. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  100. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  101. * 'current' and filter is 'applied', regardless of what they might be given as.
  102. * @returns {object} jQuery object, filtered by the given selector.
  103. * @dtopt API
  104. * @deprecated Since v1.10
  105. *
  106. * @example
  107. * $(document).ready(function() {
  108. * var oTable = $('#example').dataTable();
  109. *
  110. * // Highlight every second row
  111. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  112. * } );
  113. *
  114. * @example
  115. * $(document).ready(function() {
  116. * var oTable = $('#example').dataTable();
  117. *
  118. * // Filter to rows with 'Webkit' in them, add a background colour and then
  119. * // remove the filter, thus highlighting the 'Webkit' rows only.
  120. * oTable.fnFilter('Webkit');
  121. * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
  122. * oTable.fnFilter('');
  123. * } );
  124. */
  125. this.$ = function ( sSelector, oOpts )
  126. {
  127. return this.api(true).$( sSelector, oOpts );
  128. };
  129. /**
  130. * Almost identical to $ in operation, but in this case returns the data for the matched
  131. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  132. * rather than any descendants, so the data can be obtained for the row/cell. If matching
  133. * rows are found, the data returned is the original data array/object that was used to
  134. * create the row (or a generated array if from a DOM source).
  135. *
  136. * This method is often useful in-combination with $ where both functions are given the
  137. * same parameters and the array indexes will match identically.
  138. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  139. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  140. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  141. * criterion ("applied") or all elements (i.e. no filter).
  142. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  143. * Can be either 'current', whereby the current sorting of the table is used, or
  144. * 'original' whereby the original order the data was read into the table is used.
  145. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  146. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  147. * 'current' and filter is 'applied', regardless of what they might be given as.
  148. * @returns {array} Data for the matched elements. If any elements, as a result of the
  149. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  150. * entry in the array.
  151. * @dtopt API
  152. * @deprecated Since v1.10
  153. *
  154. * @example
  155. * $(document).ready(function() {
  156. * var oTable = $('#example').dataTable();
  157. *
  158. * // Get the data from the first row in the table
  159. * var data = oTable._('tr:first');
  160. *
  161. * // Do something useful with the data
  162. * alert( "First cell is: "+data[0] );
  163. * } );
  164. *
  165. * @example
  166. * $(document).ready(function() {
  167. * var oTable = $('#example').dataTable();
  168. *
  169. * // Filter to 'Webkit' and get all data for
  170. * oTable.fnFilter('Webkit');
  171. * var data = oTable._('tr', {"search": "applied"});
  172. *
  173. * // Do something with the data
  174. * alert( data.length+" rows matched the search" );
  175. * } );
  176. */
  177. this._ = function ( sSelector, oOpts )
  178. {
  179. return this.api(true).rows( sSelector, oOpts ).data();
  180. };
  181. /**
  182. * Create a DataTables Api instance, with the currently selected tables for
  183. * the Api's context.
  184. * @param {boolean} [traditional=false] Set the API instance's context to be
  185. * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
  186. * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
  187. * or if all tables captured in the jQuery object should be used.
  188. * @return {DataTables.Api}
  189. */
  190. this.api = function ( traditional )
  191. {
  192. return traditional ?
  193. new _Api(
  194. _fnSettingsFromNode( this[ _ext.iApiIndex ] )
  195. ) :
  196. new _Api( this );
  197. };
  198. /**
  199. * Add a single new row or multiple rows of data to the table. Please note
  200. * that this is suitable for client-side processing only - if you are using
  201. * server-side processing (i.e. "bServerSide": true), then to add data, you
  202. * must add it to the data source, i.e. the server-side, through an Ajax call.
  203. * @param {array|object} data The data to be added to the table. This can be:
  204. * <ul>
  205. * <li>1D array of data - add a single row with the data provided</li>
  206. * <li>2D array of arrays - add multiple rows in a single call</li>
  207. * <li>object - data object when using <i>mData</i></li>
  208. * <li>array of objects - multiple data objects when using <i>mData</i></li>
  209. * </ul>
  210. * @param {bool} [redraw=true] redraw the table or not
  211. * @returns {array} An array of integers, representing the list of indexes in
  212. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  213. * the table.
  214. * @dtopt API
  215. * @deprecated Since v1.10
  216. *
  217. * @example
  218. * // Global var for counter
  219. * var giCount = 2;
  220. *
  221. * $(document).ready(function() {
  222. * $('#example').dataTable();
  223. * } );
  224. *
  225. * function fnClickAddRow() {
  226. * $('#example').dataTable().fnAddData( [
  227. * giCount+".1",
  228. * giCount+".2",
  229. * giCount+".3",
  230. * giCount+".4" ]
  231. * );
  232. *
  233. * giCount++;
  234. * }
  235. */
  236. this.fnAddData = function( data, redraw )
  237. {
  238. var api = this.api( true );
  239. /* Check if we want to add multiple rows or not */
  240. var rows = $.isArray(data) && ( $.isArray(data[0]) || $.isPlainObject(data[0]) ) ?
  241. api.rows.add( data ) :
  242. api.row.add( data );
  243. if ( redraw === undefined || redraw ) {
  244. api.draw();
  245. }
  246. return rows.flatten().toArray();
  247. };
  248. /**
  249. * This function will make DataTables recalculate the column sizes, based on the data
  250. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  251. * through the sWidth parameter). This can be useful when the width of the table's
  252. * parent element changes (for example a window resize).
  253. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  254. * @dtopt API
  255. * @deprecated Since v1.10
  256. *
  257. * @example
  258. * $(document).ready(function() {
  259. * var oTable = $('#example').dataTable( {
  260. * "sScrollY": "200px",
  261. * "bPaginate": false
  262. * } );
  263. *
  264. * $(window).on('resize', function () {
  265. * oTable.fnAdjustColumnSizing();
  266. * } );
  267. * } );
  268. */
  269. this.fnAdjustColumnSizing = function ( bRedraw )
  270. {
  271. var api = this.api( true ).columns.adjust();
  272. var settings = api.settings()[0];
  273. var scroll = settings.oScroll;
  274. if ( bRedraw === undefined || bRedraw ) {
  275. api.draw( false );
  276. }
  277. else if ( scroll.sX !== "" || scroll.sY !== "" ) {
  278. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  279. _fnScrollDraw( settings );
  280. }
  281. };
  282. /**
  283. * Quickly and simply clear a table
  284. * @param {bool} [bRedraw=true] redraw the table or not
  285. * @dtopt API
  286. * @deprecated Since v1.10
  287. *
  288. * @example
  289. * $(document).ready(function() {
  290. * var oTable = $('#example').dataTable();
  291. *
  292. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  293. * oTable.fnClearTable();
  294. * } );
  295. */
  296. this.fnClearTable = function( bRedraw )
  297. {
  298. var api = this.api( true ).clear();
  299. if ( bRedraw === undefined || bRedraw ) {
  300. api.draw();
  301. }
  302. };
  303. /**
  304. * The exact opposite of 'opening' a row, this function will close any rows which
  305. * are currently 'open'.
  306. * @param {node} nTr the table row to 'close'
  307. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  308. * @dtopt API
  309. * @deprecated Since v1.10
  310. *
  311. * @example
  312. * $(document).ready(function() {
  313. * var oTable;
  314. *
  315. * // 'open' an information row when a row is clicked on
  316. * $('#example tbody tr').click( function () {
  317. * if ( oTable.fnIsOpen(this) ) {
  318. * oTable.fnClose( this );
  319. * } else {
  320. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  321. * }
  322. * } );
  323. *
  324. * oTable = $('#example').dataTable();
  325. * } );
  326. */
  327. this.fnClose = function( nTr )
  328. {
  329. this.api( true ).row( nTr ).child.hide();
  330. };
  331. /**
  332. * Remove a row for the table
  333. * @param {mixed} target The index of the row from aoData to be deleted, or
  334. * the TR element you want to delete
  335. * @param {function|null} [callBack] Callback function
  336. * @param {bool} [redraw=true] Redraw the table or not
  337. * @returns {array} The row that was deleted
  338. * @dtopt API
  339. * @deprecated Since v1.10
  340. *
  341. * @example
  342. * $(document).ready(function() {
  343. * var oTable = $('#example').dataTable();
  344. *
  345. * // Immediately remove the first row
  346. * oTable.fnDeleteRow( 0 );
  347. * } );
  348. */
  349. this.fnDeleteRow = function( target, callback, redraw )
  350. {
  351. var api = this.api( true );
  352. var rows = api.rows( target );
  353. var settings = rows.settings()[0];
  354. var data = settings.aoData[ rows[0][0] ];
  355. rows.remove();
  356. if ( callback ) {
  357. callback.call( this, settings, data );
  358. }
  359. if ( redraw === undefined || redraw ) {
  360. api.draw();
  361. }
  362. return data;
  363. };
  364. /**
  365. * Restore the table to it's original state in the DOM by removing all of DataTables
  366. * enhancements, alterations to the DOM structure of the table and event listeners.
  367. * @param {boolean} [remove=false] Completely remove the table from the DOM
  368. * @dtopt API
  369. * @deprecated Since v1.10
  370. *
  371. * @example
  372. * $(document).ready(function() {
  373. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  374. * var oTable = $('#example').dataTable();
  375. * oTable.fnDestroy();
  376. * } );
  377. */
  378. this.fnDestroy = function ( remove )
  379. {
  380. this.api( true ).destroy( remove );
  381. };
  382. /**
  383. * Redraw the table
  384. * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
  385. * @dtopt API
  386. * @deprecated Since v1.10
  387. *
  388. * @example
  389. * $(document).ready(function() {
  390. * var oTable = $('#example').dataTable();
  391. *
  392. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  393. * oTable.fnDraw();
  394. * } );
  395. */
  396. this.fnDraw = function( complete )
  397. {
  398. // Note that this isn't an exact match to the old call to _fnDraw - it takes
  399. // into account the new data, but can hold position.
  400. this.api( true ).draw( complete );
  401. };
  402. /**
  403. * Filter the input based on data
  404. * @param {string} sInput String to filter the table on
  405. * @param {int|null} [iColumn] Column to limit filtering to
  406. * @param {bool} [bRegex=false] Treat as regular expression or not
  407. * @param {bool} [bSmart=true] Perform smart filtering or not
  408. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  409. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  410. * @dtopt API
  411. * @deprecated Since v1.10
  412. *
  413. * @example
  414. * $(document).ready(function() {
  415. * var oTable = $('#example').dataTable();
  416. *
  417. * // Sometime later - filter...
  418. * oTable.fnFilter( 'test string' );
  419. * } );
  420. */
  421. this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
  422. {
  423. var api = this.api( true );
  424. if ( iColumn === null || iColumn === undefined ) {
  425. api.search( sInput, bRegex, bSmart, bCaseInsensitive );
  426. }
  427. else {
  428. api.column( iColumn ).search( sInput, bRegex, bSmart, bCaseInsensitive );
  429. }
  430. api.draw();
  431. };
  432. /**
  433. * Get the data for the whole table, an individual row or an individual cell based on the
  434. * provided parameters.
  435. * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
  436. * a TR node then the data source for the whole row will be returned. If given as a
  437. * TD/TH cell node then iCol will be automatically calculated and the data for the
  438. * cell returned. If given as an integer, then this is treated as the aoData internal
  439. * data index for the row (see fnGetPosition) and the data for that row used.
  440. * @param {int} [col] Optional column index that you want the data of.
  441. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  442. * returned. If mRow is defined, just data for that row, and is iCol is
  443. * defined, only data for the designated cell is returned.
  444. * @dtopt API
  445. * @deprecated Since v1.10
  446. *
  447. * @example
  448. * // Row data
  449. * $(document).ready(function() {
  450. * oTable = $('#example').dataTable();
  451. *
  452. * oTable.$('tr').click( function () {
  453. * var data = oTable.fnGetData( this );
  454. * // ... do something with the array / object of data for the row
  455. * } );
  456. * } );
  457. *
  458. * @example
  459. * // Individual cell data
  460. * $(document).ready(function() {
  461. * oTable = $('#example').dataTable();
  462. *
  463. * oTable.$('td').click( function () {
  464. * var sData = oTable.fnGetData( this );
  465. * alert( 'The cell clicked on had the value of '+sData );
  466. * } );
  467. * } );
  468. */
  469. this.fnGetData = function( src, col )
  470. {
  471. var api = this.api( true );
  472. if ( src !== undefined ) {
  473. var type = src.nodeName ? src.nodeName.toLowerCase() : '';
  474. return col !== undefined || type == 'td' || type == 'th' ?
  475. api.cell( src, col ).data() :
  476. api.row( src ).data() || null;
  477. }
  478. return api.data().toArray();
  479. };
  480. /**
  481. * Get an array of the TR nodes that are used in the table's body. Note that you will
  482. * typically want to use the '$' API method in preference to this as it is more
  483. * flexible.
  484. * @param {int} [iRow] Optional row index for the TR element you want
  485. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  486. * in the table's body, or iRow is defined, just the TR element requested.
  487. * @dtopt API
  488. * @deprecated Since v1.10
  489. *
  490. * @example
  491. * $(document).ready(function() {
  492. * var oTable = $('#example').dataTable();
  493. *
  494. * // Get the nodes from the table
  495. * var nNodes = oTable.fnGetNodes( );
  496. * } );
  497. */
  498. this.fnGetNodes = function( iRow )
  499. {
  500. var api = this.api( true );
  501. return iRow !== undefined ?
  502. api.row( iRow ).node() :
  503. api.rows().nodes().flatten().toArray();
  504. };
  505. /**
  506. * Get the array indexes of a particular cell from it's DOM element
  507. * and column index including hidden columns
  508. * @param {node} node this can either be a TR, TD or TH in the table's body
  509. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  510. * if given as a cell, an array of [row index, column index (visible),
  511. * column index (all)] is given.
  512. * @dtopt API
  513. * @deprecated Since v1.10
  514. *
  515. * @example
  516. * $(document).ready(function() {
  517. * $('#example tbody td').click( function () {
  518. * // Get the position of the current data from the node
  519. * var aPos = oTable.fnGetPosition( this );
  520. *
  521. * // Get the data array for this row
  522. * var aData = oTable.fnGetData( aPos[0] );
  523. *
  524. * // Update the data array and return the value
  525. * aData[ aPos[1] ] = 'clicked';
  526. * this.innerHTML = 'clicked';
  527. * } );
  528. *
  529. * // Init DataTables
  530. * oTable = $('#example').dataTable();
  531. * } );
  532. */
  533. this.fnGetPosition = function( node )
  534. {
  535. var api = this.api( true );
  536. var nodeName = node.nodeName.toUpperCase();
  537. if ( nodeName == 'TR' ) {
  538. return api.row( node ).index();
  539. }
  540. else if ( nodeName == 'TD' || nodeName == 'TH' ) {
  541. var cell = api.cell( node ).index();
  542. return [
  543. cell.row,
  544. cell.columnVisible,
  545. cell.column
  546. ];
  547. }
  548. return null;
  549. };
  550. /**
  551. * Check to see if a row is 'open' or not.
  552. * @param {node} nTr the table row to check
  553. * @returns {boolean} true if the row is currently open, false otherwise
  554. * @dtopt API
  555. * @deprecated Since v1.10
  556. *
  557. * @example
  558. * $(document).ready(function() {
  559. * var oTable;
  560. *
  561. * // 'open' an information row when a row is clicked on
  562. * $('#example tbody tr').click( function () {
  563. * if ( oTable.fnIsOpen(this) ) {
  564. * oTable.fnClose( this );
  565. * } else {
  566. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  567. * }
  568. * } );
  569. *
  570. * oTable = $('#example').dataTable();
  571. * } );
  572. */
  573. this.fnIsOpen = function( nTr )
  574. {
  575. return this.api( true ).row( nTr ).child.isShown();
  576. };
  577. /**
  578. * This function will place a new row directly after a row which is currently
  579. * on display on the page, with the HTML contents that is passed into the
  580. * function. This can be used, for example, to ask for confirmation that a
  581. * particular record should be deleted.
  582. * @param {node} nTr The table row to 'open'
  583. * @param {string|node|jQuery} mHtml The HTML to put into the row
  584. * @param {string} sClass Class to give the new TD cell
  585. * @returns {node} The row opened. Note that if the table row passed in as the
  586. * first parameter, is not found in the table, this method will silently
  587. * return.
  588. * @dtopt API
  589. * @deprecated Since v1.10
  590. *
  591. * @example
  592. * $(document).ready(function() {
  593. * var oTable;
  594. *
  595. * // 'open' an information row when a row is clicked on
  596. * $('#example tbody tr').click( function () {
  597. * if ( oTable.fnIsOpen(this) ) {
  598. * oTable.fnClose( this );
  599. * } else {
  600. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  601. * }
  602. * } );
  603. *
  604. * oTable = $('#example').dataTable();
  605. * } );
  606. */
  607. this.fnOpen = function( nTr, mHtml, sClass )
  608. {
  609. return this.api( true )
  610. .row( nTr )
  611. .child( mHtml, sClass )
  612. .show()
  613. .child()[0];
  614. };
  615. /**
  616. * Change the pagination - provides the internal logic for pagination in a simple API
  617. * function. With this function you can have a DataTables table go to the next,
  618. * previous, first or last pages.
  619. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  620. * or page number to jump to (integer), note that page 0 is the first page.
  621. * @param {bool} [bRedraw=true] Redraw the table or not
  622. * @dtopt API
  623. * @deprecated Since v1.10
  624. *
  625. * @example
  626. * $(document).ready(function() {
  627. * var oTable = $('#example').dataTable();
  628. * oTable.fnPageChange( 'next' );
  629. * } );
  630. */
  631. this.fnPageChange = function ( mAction, bRedraw )
  632. {
  633. var api = this.api( true ).page( mAction );
  634. if ( bRedraw === undefined || bRedraw ) {
  635. api.draw(false);
  636. }
  637. };
  638. /**
  639. * Show a particular column
  640. * @param {int} iCol The column whose display should be changed
  641. * @param {bool} bShow Show (true) or hide (false) the column
  642. * @param {bool} [bRedraw=true] Redraw the table or not
  643. * @dtopt API
  644. * @deprecated Since v1.10
  645. *
  646. * @example
  647. * $(document).ready(function() {
  648. * var oTable = $('#example').dataTable();
  649. *
  650. * // Hide the second column after initialisation
  651. * oTable.fnSetColumnVis( 1, false );
  652. * } );
  653. */
  654. this.fnSetColumnVis = function ( iCol, bShow, bRedraw )
  655. {
  656. var api = this.api( true ).column( iCol ).visible( bShow );
  657. if ( bRedraw === undefined || bRedraw ) {
  658. api.columns.adjust().draw();
  659. }
  660. };
  661. /**
  662. * Get the settings for a particular table for external manipulation
  663. * @returns {object} DataTables settings object. See
  664. * {@link DataTable.models.oSettings}
  665. * @dtopt API
  666. * @deprecated Since v1.10
  667. *
  668. * @example
  669. * $(document).ready(function() {
  670. * var oTable = $('#example').dataTable();
  671. * var oSettings = oTable.fnSettings();
  672. *
  673. * // Show an example parameter from the settings
  674. * alert( oSettings._iDisplayStart );
  675. * } );
  676. */
  677. this.fnSettings = function()
  678. {
  679. return _fnSettingsFromNode( this[_ext.iApiIndex] );
  680. };
  681. /**
  682. * Sort the table by a particular column
  683. * @param {int} iCol the data index to sort on. Note that this will not match the
  684. * 'display index' if you have hidden data entries
  685. * @dtopt API
  686. * @deprecated Since v1.10
  687. *
  688. * @example
  689. * $(document).ready(function() {
  690. * var oTable = $('#example').dataTable();
  691. *
  692. * // Sort immediately with columns 0 and 1
  693. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  694. * } );
  695. */
  696. this.fnSort = function( aaSort )
  697. {
  698. this.api( true ).order( aaSort ).draw();
  699. };
  700. /**
  701. * Attach a sort listener to an element for a given column
  702. * @param {node} nNode the element to attach the sort listener to
  703. * @param {int} iColumn the column that a click on this node will sort on
  704. * @param {function} [fnCallback] callback function when sort is run
  705. * @dtopt API
  706. * @deprecated Since v1.10
  707. *
  708. * @example
  709. * $(document).ready(function() {
  710. * var oTable = $('#example').dataTable();
  711. *
  712. * // Sort on column 1, when 'sorter' is clicked on
  713. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  714. * } );
  715. */
  716. this.fnSortListener = function( nNode, iColumn, fnCallback )
  717. {
  718. this.api( true ).order.listener( nNode, iColumn, fnCallback );
  719. };
  720. /**
  721. * Update a table cell or row - this method will accept either a single value to
  722. * update the cell with, an array of values with one element for each column or
  723. * an object in the same format as the original data source. The function is
  724. * self-referencing in order to make the multi column updates easier.
  725. * @param {object|array|string} mData Data to update the cell/row with
  726. * @param {node|int} mRow TR element you want to update or the aoData index
  727. * @param {int} [iColumn] The column to update, give as null or undefined to
  728. * update a whole row.
  729. * @param {bool} [bRedraw=true] Redraw the table or not
  730. * @param {bool} [bAction=true] Perform pre-draw actions or not
  731. * @returns {int} 0 on success, 1 on error
  732. * @dtopt API
  733. * @deprecated Since v1.10
  734. *
  735. * @example
  736. * $(document).ready(function() {
  737. * var oTable = $('#example').dataTable();
  738. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  739. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
  740. * } );
  741. */
  742. this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
  743. {
  744. var api = this.api( true );
  745. if ( iColumn === undefined || iColumn === null ) {
  746. api.row( mRow ).data( mData );
  747. }
  748. else {
  749. api.cell( mRow, iColumn ).data( mData );
  750. }
  751. if ( bAction === undefined || bAction ) {
  752. api.columns.adjust();
  753. }
  754. if ( bRedraw === undefined || bRedraw ) {
  755. api.draw();
  756. }
  757. return 0;
  758. };
  759. /**
  760. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  761. * to ensure compatibility.
  762. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  763. * formats "X" and "X.Y" are also acceptable.
  764. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  765. * version, or false if this version of DataTales is not suitable
  766. * @method
  767. * @dtopt API
  768. * @deprecated Since v1.10
  769. *
  770. * @example
  771. * $(document).ready(function() {
  772. * var oTable = $('#example').dataTable();
  773. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  774. * } );
  775. */
  776. this.fnVersionCheck = _ext.fnVersionCheck;
  777. var _that = this;
  778. var emptyInit = options === undefined;
  779. var len = this.length;
  780. if ( emptyInit ) {
  781. options = {};
  782. }
  783. this.oApi = this.internal = _ext.internal;
  784. // Extend with old style plug-in API methods
  785. for ( var fn in DataTable.ext.internal ) {
  786. if ( fn ) {
  787. this[fn] = _fnExternApiFunc(fn);
  788. }
  789. }
  790. this.each(function() {
  791. // For each initialisation we want to give it a clean initialisation
  792. // object that can be bashed around
  793. var o = {};
  794. var oInit = len > 1 ? // optimisation for single table case
  795. _fnExtend( o, options, true ) :
  796. options;
  797. /*global oInit,_that,emptyInit*/
  798. var i=0, iLen, j, jLen, k, kLen;
  799. var sId = this.getAttribute( 'id' );
  800. var bInitHandedOff = false;
  801. var defaults = DataTable.defaults;
  802. var $this = $(this);
  803. /* Sanity check */
  804. if ( this.nodeName.toLowerCase() != 'table' )
  805. {
  806. _fnLog( null, 0, 'Non-table node initialisation ('+this.nodeName+')', 2 );
  807. return;
  808. }
  809. /* Backwards compatibility for the defaults */
  810. _fnCompatOpts( defaults );
  811. _fnCompatCols( defaults.column );
  812. /* Convert the camel-case defaults to Hungarian */
  813. _fnCamelToHungarian( defaults, defaults, true );
  814. _fnCamelToHungarian( defaults.column, defaults.column, true );
  815. /* Setting up the initialisation object */
  816. _fnCamelToHungarian( defaults, $.extend( oInit, $this.data() ) );
  817. /* Check to see if we are re-initialising a table */
  818. var allSettings = DataTable.settings;
  819. for ( i=0, iLen=allSettings.length ; i<iLen ; i++ )
  820. {
  821. var s = allSettings[i];
  822. /* Base check on table node */
  823. if (
  824. s.nTable == this ||
  825. (s.nTHead && s.nTHead.parentNode == this) ||
  826. (s.nTFoot && s.nTFoot.parentNode == this)
  827. ) {
  828. var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
  829. var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
  830. if ( emptyInit || bRetrieve )
  831. {
  832. return s.oInstance;
  833. }
  834. else if ( bDestroy )
  835. {
  836. s.oInstance.fnDestroy();
  837. break;
  838. }
  839. else
  840. {
  841. _fnLog( s, 0, 'Cannot reinitialise DataTable', 3 );
  842. return;
  843. }
  844. }
  845. /* If the element we are initialising has the same ID as a table which was previously
  846. * initialised, but the table nodes don't match (from before) then we destroy the old
  847. * instance by simply deleting it. This is under the assumption that the table has been
  848. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  849. */
  850. if ( s.sTableId == this.id )
  851. {
  852. allSettings.splice( i, 1 );
  853. break;
  854. }
  855. }
  856. /* Ensure the table has an ID - required for accessibility */
  857. if ( sId === null || sId === "" )
  858. {
  859. sId = "DataTables_Table_"+(DataTable.ext._unique++);
  860. this.id = sId;
  861. }
  862. /* Create the settings object for this table and set some of the default parameters */
  863. var oSettings = $.extend( true, {}, DataTable.models.oSettings, {
  864. "sDestroyWidth": $this[0].style.width,
  865. "sInstance": sId,
  866. "sTableId": sId
  867. } );
  868. oSettings.nTable = this;
  869. oSettings.oApi = _that.internal;
  870. oSettings.oInit = oInit;
  871. allSettings.push( oSettings );
  872. // Need to add the instance after the instance after the settings object has been added
  873. // to the settings array, so we can self reference the table instance if more than one
  874. oSettings.oInstance = (_that.length===1) ? _that : $this.dataTable();
  875. // Backwards compatibility, before we apply all the defaults
  876. _fnCompatOpts( oInit );
  877. _fnLanguageCompat( oInit.oLanguage );
  878. // If the length menu is given, but the init display length is not, use the length menu
  879. if ( oInit.aLengthMenu && ! oInit.iDisplayLength )
  880. {
  881. oInit.iDisplayLength = $.isArray( oInit.aLengthMenu[0] ) ?
  882. oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
  883. }
  884. // Apply the defaults and init options to make a single init object will all
  885. // options defined from defaults and instance options.
  886. oInit = _fnExtend( $.extend( true, {}, defaults ), oInit );
  887. // Map the initialisation options onto the settings object
  888. _fnMap( oSettings.oFeatures, oInit, [
  889. "bPaginate",
  890. "bLengthChange",
  891. "bFilter",
  892. "bSort",
  893. "bSortMulti",
  894. "bInfo",
  895. "bProcessing",
  896. "bAutoWidth",
  897. "bSortClasses",
  898. "bServerSide",
  899. "bDeferRender"
  900. ] );
  901. _fnMap( oSettings, oInit, [
  902. "asStripeClasses",
  903. "ajax",
  904. "fnServerData",
  905. "fnFormatNumber",
  906. "sServerMethod",
  907. "aaSorting",
  908. "aaSortingFixed",
  909. "aLengthMenu",
  910. "sPaginationType",
  911. "sAjaxSource",
  912. "sAjaxDataProp",
  913. "iStateDuration",
  914. "sDom",
  915. "bSortCellsTop",
  916. "iTabIndex",
  917. "fnStateLoadCallback",
  918. "fnStateSaveCallback",
  919. "renderer",
  920. "searchDelay",
  921. "rowId",
  922. [ "iCookieDuration", "iStateDuration" ], // backwards compat
  923. [ "oSearch", "oPreviousSearch" ],
  924. [ "aoSearchCols", "aoPreSearchCols" ],
  925. [ "iDisplayLength", "_iDisplayLength" ]
  926. ] );
  927. _fnMap( oSettings.oScroll, oInit, [
  928. [ "sScrollX", "sX" ],
  929. [ "sScrollXInner", "sXInner" ],
  930. [ "sScrollY", "sY" ],
  931. [ "bScrollCollapse", "bCollapse" ]
  932. ] );
  933. _fnMap( oSettings.oLanguage, oInit, "fnInfoCallback" );
  934. /* Callback functions which are array driven */
  935. _fnCallbackReg( oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user' );
  936. _fnCallbackReg( oSettings, 'aoServerParams', oInit.fnServerParams, 'user' );
  937. _fnCallbackReg( oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user' );
  938. _fnCallbackReg( oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user' );
  939. _fnCallbackReg( oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user' );
  940. _fnCallbackReg( oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user' );
  941. _fnCallbackReg( oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user' );
  942. _fnCallbackReg( oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user' );
  943. _fnCallbackReg( oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user' );
  944. _fnCallbackReg( oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user' );
  945. _fnCallbackReg( oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user' );
  946. oSettings.rowIdFn = _fnGetObjectDataFn( oInit.rowId );
  947. /* Browser support detection */
  948. _fnBrowserDetect( oSettings );
  949. var oClasses = oSettings.oClasses;
  950. $.extend( oClasses, DataTable.ext.classes, oInit.oClasses );
  951. $this.addClass( oClasses.sTable );
  952. if ( oSettings.iInitDisplayStart === undefined )
  953. {
  954. /* Display start point, taking into account the save saving */
  955. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  956. oSettings._iDisplayStart = oInit.iDisplayStart;
  957. }
  958. if ( oInit.iDeferLoading !== null )
  959. {
  960. oSettings.bDeferLoading = true;
  961. var tmp = $.isArray( oInit.iDeferLoading );
  962. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  963. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  964. }
  965. /* Language definitions */
  966. var oLanguage = oSettings.oLanguage;
  967. $.extend( true, oLanguage, oInit.oLanguage );
  968. if ( oLanguage.sUrl )
  969. {
  970. /* Get the language definitions from a file - because this Ajax call makes the language
  971. * get async to the remainder of this function we use bInitHandedOff to indicate that
  972. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  973. */
  974. $.ajax( {
  975. dataType: 'json',
  976. url: oLanguage.sUrl,
  977. success: function ( json ) {
  978. _fnLanguageCompat( json );
  979. _fnCamelToHungarian( defaults.oLanguage, json );
  980. $.extend( true, oLanguage, json );
  981. _fnInitialise( oSettings );
  982. },
  983. error: function () {
  984. // Error occurred loading language file, continue on as best we can
  985. _fnInitialise( oSettings );
  986. }
  987. } );
  988. bInitHandedOff = true;
  989. }
  990. /*
  991. * Stripes
  992. */
  993. if ( oInit.asStripeClasses === null )
  994. {
  995. oSettings.asStripeClasses =[
  996. oClasses.sStripeOdd,
  997. oClasses.sStripeEven
  998. ];
  999. }
  1000. /* Remove row stripe classes if they are already on the table row */
  1001. var stripeClasses = oSettings.asStripeClasses;
  1002. var rowOne = $this.children('tbody').find('tr').eq(0);
  1003. if ( $.inArray( true, $.map( stripeClasses, function(el, i) {
  1004. return rowOne.hasClass(el);
  1005. } ) ) !== -1 ) {
  1006. $('tbody tr', this).removeClass( stripeClasses.join(' ') );
  1007. oSettings.asDestroyStripes = stripeClasses.slice();
  1008. }
  1009. /*
  1010. * Columns
  1011. * See if we should load columns automatically or use defined ones
  1012. */
  1013. var anThs = [];
  1014. var aoColumnsInit;
  1015. var nThead = this.getElementsByTagName('thead');
  1016. if ( nThead.length !== 0 )
  1017. {
  1018. _fnDetectHeader( oSettings.aoHeader, nThead[0] );
  1019. anThs = _fnGetUniqueThs( oSettings );
  1020. }
  1021. /* If not given a column array, generate one with nulls */
  1022. if ( oInit.aoColumns === null )
  1023. {
  1024. aoColumnsInit = [];
  1025. for ( i=0, iLen=anThs.length ; i<iLen ; i++ )
  1026. {
  1027. aoColumnsInit.push( null );
  1028. }
  1029. }
  1030. else
  1031. {
  1032. aoColumnsInit = oInit.aoColumns;
  1033. }
  1034. /* Add the columns */
  1035. for ( i=0, iLen=aoColumnsInit.length ; i<iLen ; i++ )
  1036. {
  1037. _fnAddColumn( oSettings, anThs ? anThs[i] : null );
  1038. }
  1039. /* Apply the column definitions */
  1040. _fnApplyColumnDefs( oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  1041. _fnColumnOptions( oSettings, iCol, oDef );
  1042. } );
  1043. /* HTML5 attribute detection - build an mData object automatically if the
  1044. * attributes are found
  1045. */
  1046. if ( rowOne.length ) {
  1047. var a = function ( cell, name ) {
  1048. return cell.getAttribute( 'data-'+name ) !== null ? name : null;
  1049. };
  1050. $( rowOne[0] ).children('th, td').each( function (i, cell) {
  1051. var col = oSettings.aoColumns[i];
  1052. if ( col.mData === i ) {
  1053. var sort = a( cell, 'sort' ) || a( cell, 'order' );
  1054. var filter = a( cell, 'filter' ) || a( cell, 'search' );
  1055. if ( sort !== null || filter !== null ) {
  1056. col.mData = {
  1057. _: i+'.display',
  1058. sort: sort !== null ? i+'.@data-'+sort : undefined,
  1059. type: sort !== null ? i+'.@data-'+sort : undefined,
  1060. filter: filter !== null ? i+'.@data-'+filter : undefined
  1061. };
  1062. _fnColumnOptions( oSettings, i );
  1063. }
  1064. }
  1065. } );
  1066. }
  1067. var features = oSettings.oFeatures;
  1068. var loadedInit = function () {
  1069. /*
  1070. * Sorting
  1071. * @todo For modularisation (1.11) this needs to do into a sort start up handler
  1072. */
  1073. // If aaSorting is not defined, then we use the first indicator in asSorting
  1074. // in case that has been altered, so the default sort reflects that option
  1075. if ( oInit.aaSorting === undefined ) {
  1076. var sorting = oSettings.aaSorting;
  1077. for ( i=0, iLen=sorting.length ; i<iLen ; i++ ) {
  1078. sorting[i][1] = oSettings.aoColumns[ i ].asSorting[0];
  1079. }
  1080. }
  1081. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  1082. * account, and also will apply sorting disabled classes if disabled
  1083. */
  1084. _fnSortingClasses( oSettings );
  1085. if ( features.bSort ) {
  1086. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1087. if ( oSettings.bSorted ) {
  1088. var aSort = _fnSortFlatten( oSettings );
  1089. var sortedColumns = {};
  1090. $.each( aSort, function (i, val) {
  1091. sortedColumns[ val.src ] = val.dir;
  1092. } );
  1093. _fnCallbackFire( oSettings, null, 'order', [oSettings, aSort, sortedColumns] );
  1094. _fnSortAria( oSettings );
  1095. }
  1096. } );
  1097. }
  1098. _fnCallbackReg( oSettings, 'aoDrawCallback', function () {
  1099. if ( oSettings.bSorted || _fnDataSource( oSettings ) === 'ssp' || features.bDeferRender ) {
  1100. _fnSortingClasses( oSettings );
  1101. }
  1102. }, 'sc' );
  1103. /*
  1104. * Final init
  1105. * Cache the header, body and footer as required, creating them if needed
  1106. */
  1107. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  1108. var captions = $this.children('caption').each( function () {
  1109. this._captionSide = $(this).css('caption-side');
  1110. } );
  1111. var thead = $this.children('thead');
  1112. if ( thead.length === 0 ) {
  1113. thead = $('<thead/>').appendTo($this);
  1114. }
  1115. oSettings.nTHead = thead[0];
  1116. var tbody = $this.children('tbody');
  1117. if ( tbody.length === 0 ) {
  1118. tbody = $('<tbody/>').appendTo($this);
  1119. }
  1120. oSettings.nTBody = tbody[0];
  1121. var tfoot = $this.children('tfoot');
  1122. if ( tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "") ) {
  1123. // If we are a scrolling table, and no footer has been given, then we need to create
  1124. // a tfoot element for the caption element to be appended to
  1125. tfoot = $('<tfoot/>').appendTo($this);
  1126. }
  1127. if ( tfoot.length === 0 || tfoot.children().length === 0 ) {
  1128. $this.addClass( oClasses.sNoFooter );
  1129. }
  1130. else if ( tfoot.length > 0 ) {
  1131. oSettings.nTFoot = tfoot[0];
  1132. _fnDetectHeader( oSettings.aoFooter, oSettings.nTFoot );
  1133. }
  1134. /* Check if there is data passing into the constructor */
  1135. if ( oInit.aaData ) {
  1136. for ( i=0 ; i<oInit.aaData.length ; i++ ) {
  1137. _fnAddData( oSettings, oInit.aaData[ i ] );
  1138. }
  1139. }
  1140. else if ( oSettings.bDeferLoading || _fnDataSource( oSettings ) == 'dom' ) {
  1141. /* Grab the data from the page - only do this when deferred loading or no Ajax
  1142. * source since there is no point in reading the DOM data if we are then going
  1143. * to replace it with Ajax data
  1144. */
  1145. _fnAddTr( oSettings, $(oSettings.nTBody).children('tr') );
  1146. }
  1147. /* Copy the data index array */
  1148. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  1149. /* Initialisation complete - table can be drawn */
  1150. oSettings.bInitialised = true;
  1151. /* Check if we need to initialise the table (it might not have been handed off to the
  1152. * language processor)
  1153. */
  1154. if ( bInitHandedOff === false ) {
  1155. _fnInitialise( oSettings );
  1156. }
  1157. };
  1158. /* Must be done after everything which can be overridden by the state saving! */
  1159. if ( oInit.bStateSave )
  1160. {
  1161. features.bStateSave = true;
  1162. _fnCallbackReg( oSettings, 'aoDrawCallback', _fnSaveState, 'state_save' );
  1163. _fnLoadState( oSettings, oInit, loadedInit );
  1164. }
  1165. else {
  1166. loadedInit();
  1167. }
  1168. } );
  1169. _that = null;
  1170. return this;
  1171. };
  1172. /*
  1173. * It is useful to have variables which are scoped locally so only the
  1174. * DataTables functions can access them and they don't leak into global space.
  1175. * At the same time these functions are often useful over multiple files in the
  1176. * core and API, so we list, or at least document, all variables which are used
  1177. * by DataTables as private variables here. This also ensures that there is no
  1178. * clashing of variable names and that they can easily referenced for reuse.
  1179. */
  1180. // Defined else where
  1181. // _selector_run
  1182. // _selector_opts
  1183. // _selector_first
  1184. // _selector_row_indexes
  1185. var _ext; // DataTable.ext
  1186. var _Api; // DataTable.Api
  1187. var _api_register; // DataTable.Api.register
  1188. var _api_registerPlural; // DataTable.Api.registerPlural
  1189. var _re_dic = {};
  1190. var _re_new_lines = /[\r\n]/g;
  1191. var _re_html = /<.*?>/g;
  1192. // This is not strict ISO8601 - Date.parse() is quite lax, although
  1193. // implementations differ between browsers.
  1194. var _re_date = /^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/;
  1195. // Escape regular expression special characters
  1196. var _re_escape_regex = new RegExp( '(\\' + [ '/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-' ].join('|\\') + ')', 'g' );
  1197. // http://en.wikipedia.org/wiki/Foreign_exchange_market
  1198. // - \u20BD - Russian ruble.
  1199. // - \u20a9 - South Korean Won
  1200. // - \u20BA - Turkish Lira
  1201. // - \u20B9 - Indian Rupee
  1202. // - R - Brazil (R$) and South Africa
  1203. // - fr - Swiss Franc
  1204. // - kr - Swedish krona, Norwegian krone and Danish krone
  1205. // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
  1206. // - Ƀ - Bitcoin
  1207. // - Ξ - Ethereum
  1208. // standards as thousands separators.
  1209. var _re_formatted_numeric = /[',$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi;
  1210. var _empty = function ( d ) {
  1211. return !d || d === true || d === '-' ? true : false;
  1212. };
  1213. var _intVal = function ( s ) {
  1214. var integer = parseInt( s, 10 );
  1215. return !isNaN(integer) && isFinite(s) ? integer : null;
  1216. };
  1217. // Convert from a formatted number with characters other than `.` as the
  1218. // decimal place, to a Javascript number
  1219. var _numToDecimal = function ( num, decimalPoint ) {
  1220. // Cache created regular expressions for speed as this function is called often
  1221. if ( ! _re_dic[ decimalPoint ] ) {
  1222. _re_dic[ decimalPoint ] = new RegExp( _fnEscapeRegex( decimalPoint ), 'g' );
  1223. }
  1224. return typeof num === 'string' && decimalPoint !== '.' ?
  1225. num.replace( /\./g, '' ).replace( _re_dic[ decimalPoint ], '.' ) :
  1226. num;
  1227. };
  1228. var _isNumber = function ( d, decimalPoint, formatted ) {
  1229. var strType = typeof d === 'string';
  1230. // If empty return immediately so there must be a number if it is a
  1231. // formatted string (this stops the string "k", or "kr", etc being detected
  1232. // as a formatted number for currency
  1233. if ( _empty( d ) ) {
  1234. return true;
  1235. }
  1236. if ( decimalPoint && strType ) {
  1237. d = _numToDecimal( d, decimalPoint );
  1238. }
  1239. if ( formatted && strType ) {
  1240. d = d.replace( _re_formatted_numeric, '' );
  1241. }
  1242. return !isNaN( parseFloat(d) ) && isFinite( d );
  1243. };
  1244. // A string without HTML in it can be considered to be HTML still
  1245. var _isHtml = function ( d ) {
  1246. return _empty( d ) || typeof d === 'string';
  1247. };
  1248. var _htmlNumeric = function ( d, decimalPoint, formatted ) {
  1249. if ( _empty( d ) ) {
  1250. return true;
  1251. }
  1252. var html = _isHtml( d );
  1253. return ! html ?
  1254. null :
  1255. _isNumber( _stripHtml( d ), decimalPoint, formatted ) ?
  1256. true :
  1257. null;
  1258. };
  1259. var _pluck = function ( a, prop, prop2 ) {
  1260. var out = [];
  1261. var i=0, ien=a.length;
  1262. // Could have the test in the loop for slightly smaller code, but speed
  1263. // is essential here
  1264. if ( prop2 !== undefined ) {
  1265. for ( ; i<ien ; i++ ) {
  1266. if ( a[i] && a[i][ prop ] ) {
  1267. out.push( a[i][ prop ][ prop2 ] );
  1268. }
  1269. }
  1270. }
  1271. else {
  1272. for ( ; i<ien ; i++ ) {
  1273. if ( a[i] ) {
  1274. out.push( a[i][ prop ] );
  1275. }
  1276. }
  1277. }
  1278. return out;
  1279. };
  1280. // Basically the same as _pluck, but rather than looping over `a` we use `order`
  1281. // as the indexes to pick from `a`
  1282. var _pluck_order = function ( a, order, prop, prop2 )
  1283. {
  1284. var out = [];
  1285. var i=0, ien=order.length;
  1286. // Could have the test in the loop for slightly smaller code, but speed
  1287. // is essential here
  1288. if ( prop2 !== undefined ) {
  1289. for ( ; i<ien ; i++ ) {
  1290. if ( a[ order[i] ][ prop ] ) {
  1291. out.push( a[ order[i] ][ prop ][ prop2 ] );
  1292. }
  1293. }
  1294. }
  1295. else {
  1296. for ( ; i<ien ; i++ ) {
  1297. out.push( a[ order[i] ][ prop ] );
  1298. }
  1299. }
  1300. return out;
  1301. };
  1302. var _range = function ( len, start )
  1303. {
  1304. var out = [];
  1305. var end;
  1306. if ( start === undefined ) {
  1307. start = 0;
  1308. end = len;
  1309. }
  1310. else {
  1311. end = start;
  1312. start = len;
  1313. }
  1314. for ( var i=start ; i<end ; i++ ) {
  1315. out.push( i );
  1316. }
  1317. return out;
  1318. };
  1319. var _removeEmpty = function ( a )
  1320. {
  1321. var out = [];
  1322. for ( var i=0, ien=a.length ; i<ien ; i++ ) {
  1323. if ( a[i] ) { // careful - will remove all falsy values!
  1324. out.push( a[i] );
  1325. }
  1326. }
  1327. return out;
  1328. };
  1329. var _stripHtml = function ( d ) {
  1330. return d.replace( _re_html, '' );
  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. /**
  1389. * DataTables utility methods
  1390. *
  1391. * This namespace provides helper methods that DataTables uses internally to
  1392. * create a DataTable, but which are not exclusively used only for DataTables.
  1393. * These methods can be used by extension authors to save the duplication of
  1394. * code.
  1395. *
  1396. * @namespace
  1397. */
  1398. DataTable.util = {
  1399. /**
  1400. * Throttle the calls to a function. Arguments and context are maintained
  1401. * for the throttled function.
  1402. *
  1403. * @param {function} fn Function to be called
  1404. * @param {integer} freq Call frequency in mS
  1405. * @return {function} Wrapped function
  1406. */
  1407. throttle: function ( fn, freq ) {
  1408. var
  1409. frequency = freq !== undefined ? freq : 200,
  1410. last,
  1411. timer;
  1412. return function () {
  1413. var
  1414. that = this,
  1415. now = +new Date(),
  1416. args = arguments;
  1417. if ( last && now < last + frequency ) {
  1418. clearTimeout( timer );
  1419. timer = setTimeout( function () {
  1420. last = undefined;
  1421. fn.apply( that, args );
  1422. }, frequency );
  1423. }
  1424. else {
  1425. last = now;
  1426. fn.apply( that, args );
  1427. }
  1428. };
  1429. },
  1430. /**
  1431. * Escape a string such that it can be used in a regular expression
  1432. *
  1433. * @param {string} val string to escape
  1434. * @returns {string} escaped string
  1435. */
  1436. escapeRegex: function ( val ) {
  1437. return val.replace( _re_escape_regex, '\\$1' );
  1438. }
  1439. };
  1440. /**
  1441. * Create a mapping object that allows camel case parameters to be looked up
  1442. * for their Hungarian counterparts. The mapping is stored in a private
  1443. * parameter called `_hungarianMap` which can be accessed on the source object.
  1444. * @param {object} o
  1445. * @memberof DataTable#oApi
  1446. */
  1447. function _fnHungarianMap ( o )
  1448. {
  1449. var
  1450. hungarian = 'a aa ai ao as b fn i m o s ',
  1451. match,
  1452. newKey,
  1453. map = {};
  1454. $.each( o, function (key, val) {
  1455. match = key.match(/^([^A-Z]+?)([A-Z])/);
  1456. if ( match && hungarian.indexOf(match[1]+' ') !== -1 )
  1457. {
  1458. newKey = key.replace( match[0], match[2].toLowerCase() );
  1459. map[ newKey ] = key;
  1460. if ( match[1] === 'o' )
  1461. {
  1462. _fnHungarianMap( o[key] );
  1463. }
  1464. }
  1465. } );
  1466. o._hungarianMap = map;
  1467. }
  1468. /**
  1469. * Convert from camel case parameters to Hungarian, based on a Hungarian map
  1470. * created by _fnHungarianMap.
  1471. * @param {object} src The model object which holds all parameters that can be
  1472. * mapped.
  1473. * @param {object} user The object to convert from camel case to Hungarian.
  1474. * @param {boolean} force When set to `true`, properties which already have a
  1475. * Hungarian value in the `user` object will be overwritten. Otherwise they
  1476. * won't be.
  1477. * @memberof DataTable#oApi
  1478. */
  1479. function _fnCamelToHungarian ( src, user, force )
  1480. {
  1481. if ( ! src._hungarianMap ) {
  1482. _fnHungarianMap( src );
  1483. }
  1484. var hungarianKey;
  1485. $.each( user, function (key, val) {
  1486. hungarianKey = src._hungarianMap[ key ];
  1487. if ( hungarianKey !== undefined && (force || user[hungarianKey] === undefined) )
  1488. {
  1489. // For objects, we need to buzz down into the object to copy parameters
  1490. if ( hungarianKey.charAt(0) === 'o' )
  1491. {
  1492. // Copy the camelCase options over to the hungarian
  1493. if ( ! user[ hungarianKey ] ) {
  1494. user[ hungarianKey ] = {};
  1495. }
  1496. $.extend( true, user[hungarianKey], user[key] );
  1497. _fnCamelToHungarian( src[hungarianKey], user[hungarianKey], force );
  1498. }
  1499. else {
  1500. user[hungarianKey] = user[ key ];
  1501. }
  1502. }
  1503. } );
  1504. }
  1505. /**
  1506. * Language compatibility - when certain options are given, and others aren't, we
  1507. * need to duplicate the values over, in order to provide backwards compatibility
  1508. * with older language files.
  1509. * @param {object} oSettings dataTables settings object
  1510. * @memberof DataTable#oApi
  1511. */
  1512. function _fnLanguageCompat( lang )
  1513. {
  1514. // Note the use of the Hungarian notation for the parameters in this method as
  1515. // this is called after the mapping of camelCase to Hungarian
  1516. var defaults = DataTable.defaults.oLanguage;
  1517. // Default mapping
  1518. var defaultDecimal = defaults.sDecimal;
  1519. if ( defaultDecimal ) {
  1520. _addNumericSort( defaultDecimal );
  1521. }
  1522. if ( lang ) {
  1523. var zeroRecords = lang.sZeroRecords;
  1524. // Backwards compatibility - if there is no sEmptyTable given, then use the same as
  1525. // sZeroRecords - assuming that is given.
  1526. if ( ! lang.sEmptyTable && zeroRecords &&
  1527. defaults.sEmptyTable === "No data available in table" )
  1528. {
  1529. _fnMap( lang, lang, 'sZeroRecords', 'sEmptyTable' );
  1530. }
  1531. // Likewise with loading records
  1532. if ( ! lang.sLoadingRecords && zeroRecords &&
  1533. defaults.sLoadingRecords === "Loading..." )
  1534. {
  1535. _fnMap( lang, lang, 'sZeroRecords', 'sLoadingRecords' );
  1536. }
  1537. // Old parameter name of the thousands separator mapped onto the new
  1538. if ( lang.sInfoThousands ) {
  1539. lang.sThousands = lang.sInfoThousands;
  1540. }
  1541. var decimal = lang.sDecimal;
  1542. if ( decimal && defaultDecimal !== decimal ) {
  1543. _addNumericSort( decimal );
  1544. }
  1545. }
  1546. }
  1547. /**
  1548. * Map one parameter onto another
  1549. * @param {object} o Object to map
  1550. * @param {*} knew The new parameter name
  1551. * @param {*} old The old parameter name
  1552. */
  1553. var _fnCompatMap = function ( o, knew, old ) {
  1554. if ( o[ knew ] !== undefined ) {
  1555. o[ old ] = o[ knew ];
  1556. }
  1557. };
  1558. /**
  1559. * Provide backwards compatibility for the main DT options. Note that the new
  1560. * options are mapped onto the old parameters, so this is an external interface
  1561. * change only.
  1562. * @param {object} init Object to map
  1563. */
  1564. function _fnCompatOpts ( init )
  1565. {
  1566. _fnCompatMap( init, 'ordering', 'bSort' );
  1567. _fnCompatMap( init, 'orderMulti', 'bSortMulti' );
  1568. _fnCompatMap( init, 'orderClasses', 'bSortClasses' );
  1569. _fnCompatMap( init, 'orderCellsTop', 'bSortCellsTop' );
  1570. _fnCompatMap( init, 'order', 'aaSorting' );
  1571. _fnCompatMap( init, 'orderFixed', 'aaSortingFixed' );
  1572. _fnCompatMap( init, 'paging', 'bPaginate' );
  1573. _fnCompatMap( init, 'pagingType', 'sPaginationType' );
  1574. _fnCompatMap( init, 'pageLength', 'iDisplayLength' );
  1575. _fnCompatMap( init, 'searching', 'bFilter' );
  1576. // Boolean initialisation of x-scrolling
  1577. if ( typeof init.sScrollX === 'boolean' ) {
  1578. init.sScrollX = init.sScrollX ? '100%' : '';
  1579. }
  1580. if ( typeof init.scrollX === 'boolean' ) {
  1581. init.scrollX = init.scrollX ? '100%' : '';
  1582. }
  1583. // Column search objects are in an array, so it needs to be converted
  1584. // element by element
  1585. var searchCols = init.aoSearchCols;
  1586. if ( searchCols ) {
  1587. for ( var i=0, ien=searchCols.length ; i<ien ; i++ ) {
  1588. if ( searchCols[i] ) {
  1589. _fnCamelToHungarian( DataTable.models.oSearch, searchCols[i] );
  1590. }
  1591. }
  1592. }
  1593. }
  1594. /**
  1595. * Provide backwards compatibility for column options. Note that the new options
  1596. * are mapped onto the old parameters, so this is an external interface change
  1597. * only.
  1598. * @param {object} init Object to map
  1599. */
  1600. function _fnCompatCols ( init )
  1601. {
  1602. _fnCompatMap( init, 'orderable', 'bSortable' );
  1603. _fnCompatMap( init, 'orderData', 'aDataSort' );
  1604. _fnCompatMap( init, 'orderSequence', 'asSorting' );
  1605. _fnCompatMap( init, 'orderDataType', 'sortDataType' );
  1606. // orderData can be given as an integer
  1607. var dataSort = init.aDataSort;
  1608. if ( typeof dataSort === 'number' && ! $.isArray( dataSort ) ) {
  1609. init.aDataSort = [ dataSort ];
  1610. }
  1611. }
  1612. /**
  1613. * Browser feature detection for capabilities, quirks
  1614. * @param {object} settings dataTables settings object
  1615. * @memberof DataTable#oApi
  1616. */
  1617. function _fnBrowserDetect( settings )
  1618. {
  1619. // We don't need to do this every time DataTables is constructed, the values
  1620. // calculated are specific to the browser and OS configuration which we
  1621. // don't expect to change between initialisations
  1622. if ( ! DataTable.__browser ) {
  1623. var browser = {};
  1624. DataTable.__browser = browser;
  1625. // Scrolling feature / quirks detection
  1626. var n = $('<div/>')
  1627. .css( {
  1628. position: 'fixed',
  1629. top: 0,
  1630. left: $(window).scrollLeft()*-1, // allow for scrolling
  1631. height: 1,
  1632. width: 1,
  1633. overflow: 'hidden'
  1634. } )
  1635. .append(
  1636. $('<div/>')
  1637. .css( {
  1638. position: 'absolute',
  1639. top: 1,
  1640. left: 1,
  1641. width: 100,
  1642. overflow: 'scroll'
  1643. } )
  1644. .append(
  1645. $('<div/>')
  1646. .css( {
  1647. width: '100%',
  1648. height: 10
  1649. } )
  1650. )
  1651. )
  1652. .appendTo( 'body' );
  1653. var outer = n.children();
  1654. var inner = outer.children();
  1655. // Numbers below, in order, are:
  1656. // inner.offsetWidth, inner.clientWidth, outer.offsetWidth, outer.clientWidth
  1657. //
  1658. // IE6 XP: 100 100 100 83
  1659. // IE7 Vista: 100 100 100 83
  1660. // IE 8+ Windows: 83 83 100 83
  1661. // Evergreen Windows: 83 83 100 83
  1662. // Evergreen Mac with scrollbars: 85 85 100 85
  1663. // Evergreen Mac without scrollbars: 100 100 100 100
  1664. // Get scrollbar width
  1665. browser.barWidth = outer[0].offsetWidth - outer[0].clientWidth;
  1666. // IE6/7 will oversize a width 100% element inside a scrolling element, to
  1667. // include the width of the scrollbar, while other browsers ensure the inner
  1668. // element is contained without forcing scrolling
  1669. browser.bScrollOversize = inner[0].offsetWidth === 100 && outer[0].clientWidth !== 100;
  1670. // In rtl text layout, some browsers (most, but not all) will place the
  1671. // scrollbar on the left, rather than the right.
  1672. browser.bScrollbarLeft = Math.round( inner.offset().left ) !== 1;
  1673. // IE8- don't provide height and width for getBoundingClientRect
  1674. browser.bBounding = n[0].getBoundingClientRect().width ? true : false;
  1675. n.remove();
  1676. }
  1677. $.extend( settings.oBrowser, DataTable.__browser );
  1678. settings.oScroll.iBarWidth = DataTable.__browser.barWidth;
  1679. }
  1680. /**
  1681. * Array.prototype reduce[Right] method, used for browsers which don't support
  1682. * JS 1.6. Done this way to reduce code size, since we iterate either way
  1683. * @param {object} settings dataTables settings object
  1684. * @memberof DataTable#oApi
  1685. */
  1686. function _fnReduce ( that, fn, init, start, end, inc )
  1687. {
  1688. var
  1689. i = start,
  1690. value,
  1691. isSet = false;
  1692. if ( init !== undefined ) {
  1693. value = init;
  1694. isSet = true;
  1695. }
  1696. while ( i !== end ) {
  1697. if ( ! that.hasOwnProperty(i) ) {
  1698. continue;
  1699. }
  1700. value = isSet ?
  1701. fn( value, that[i], i, that ) :
  1702. that[i];
  1703. isSet = true;
  1704. i += inc;
  1705. }
  1706. return value;
  1707. }
  1708. /**
  1709. * Add a column to the list used for the table with default values
  1710. * @param {object} oSettings dataTables settings object
  1711. * @param {node} nTh The th element for this column
  1712. * @memberof DataTable#oApi
  1713. */
  1714. function _fnAddColumn( oSettings, nTh )
  1715. {
  1716. // Add column to aoColumns array
  1717. var oDefaults = DataTable.defaults.column;
  1718. var iCol = oSettings.aoColumns.length;
  1719. var oCol = $.extend( {}, DataTable.models.oColumn, oDefaults, {
  1720. "nTh": nTh ? nTh : document.createElement('th'),
  1721. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  1722. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  1723. "mData": oDefaults.mData ? oDefaults.mData : iCol,
  1724. idx: iCol
  1725. } );
  1726. oSettings.aoColumns.push( oCol );
  1727. // Add search object for column specific search. Note that the `searchCols[ iCol ]`
  1728. // passed into extend can be undefined. This allows the user to give a default
  1729. // with only some of the parameters defined, and also not give a default
  1730. var searchCols = oSettings.aoPreSearchCols;
  1731. searchCols[ iCol ] = $.extend( {}, DataTable.models.oSearch, searchCols[ iCol ] );
  1732. // Use the default column options function to initialise classes etc
  1733. _fnColumnOptions( oSettings, iCol, $(nTh).data() );
  1734. }
  1735. /**
  1736. * Apply options for a column
  1737. * @param {object} oSettings dataTables settings object
  1738. * @param {int} iCol column index to consider
  1739. * @param {object} oOptions object with sType, bVisible and bSearchable etc
  1740. * @memberof DataTable#oApi
  1741. */
  1742. function _fnColumnOptions( oSettings, iCol, oOptions )
  1743. {
  1744. var oCol = oSettings.aoColumns[ iCol ];
  1745. var oClasses = oSettings.oClasses;
  1746. var th = $(oCol.nTh);
  1747. // Try to get width information from the DOM. We can't get it from CSS
  1748. // as we'd need to parse the CSS stylesheet. `width` option can override
  1749. if ( ! oCol.sWidthOrig ) {
  1750. // Width attribute
  1751. oCol.sWidthOrig = th.attr('width') || null;
  1752. // Style attribute
  1753. var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
  1754. if ( t ) {
  1755. oCol.sWidthOrig = t[1];
  1756. }
  1757. }
  1758. /* User specified column options */
  1759. if ( oOptions !== undefined && oOptions !== null )
  1760. {
  1761. // Backwards compatibility
  1762. _fnCompatCols( oOptions );
  1763. // Map camel case parameters to their Hungarian counterparts
  1764. _fnCamelToHungarian( DataTable.defaults.column, oOptions );
  1765. /* Backwards compatibility for mDataProp */
  1766. if ( oOptions.mDataProp !== undefined && !oOptions.mData )
  1767. {
  1768. oOptions.mData = oOptions.mDataProp;
  1769. }
  1770. if ( oOptions.sType )
  1771. {
  1772. oCol._sManualType = oOptions.sType;
  1773. }
  1774. // `class` is a reserved word in Javascript, so we need to provide
  1775. // the ability to use a valid name for the camel case input
  1776. if ( oOptions.className && ! oOptions.sClass )
  1777. {
  1778. oOptions.sClass = oOptions.className;
  1779. }
  1780. if ( oOptions.sClass ) {
  1781. th.addClass( oOptions.sClass );
  1782. }
  1783. $.extend( oCol, oOptions );
  1784. _fnMap( oCol, oOptions, "sWidth", "sWidthOrig" );
  1785. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  1786. * priority if defined
  1787. */
  1788. if ( oOptions.iDataSort !== undefined )
  1789. {
  1790. oCol.aDataSort = [ oOptions.iDataSort ];
  1791. }
  1792. _fnMap( oCol, oOptions, "aDataSort" );
  1793. }
  1794. /* Cache the data get and set functions for speed */
  1795. var mDataSrc = oCol.mData;
  1796. var mData = _fnGetObjectDataFn( mDataSrc );
  1797. var mRender = oCol.mRender ? _fnGetObjectDataFn( oCol.mRender ) : null;
  1798. var attrTest = function( src ) {
  1799. return typeof src === 'string' && src.indexOf('@') !== -1;
  1800. };
  1801. oCol._bAttrSrc = $.isPlainObject( mDataSrc ) && (
  1802. attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter)
  1803. );
  1804. oCol._setter = null;
  1805. oCol.fnGetData = function (rowData, type, meta) {
  1806. var innerData = mData( rowData, type, undefined, meta );
  1807. return mRender && type ?
  1808. mRender( innerData, type, rowData, meta ) :
  1809. innerData;
  1810. };
  1811. oCol.fnSetData = function ( rowData, val, meta ) {
  1812. return _fnSetObjectDataFn( mDataSrc )( rowData, val, meta );
  1813. };
  1814. // Indicate if DataTables should read DOM data as an object or array
  1815. // Used in _fnGetRowElements
  1816. if ( typeof mDataSrc !== 'number' ) {
  1817. oSettings._rowReadObject = true;
  1818. }
  1819. /* Feature sorting overrides column specific when off */
  1820. if ( !oSettings.oFeatures.bSort )
  1821. {
  1822. oCol.bSortable = false;
  1823. th.addClass( oClasses.sSortableNone ); // Have to add class here as order event isn't called
  1824. }
  1825. /* Check that the class assignment is correct for sorting */
  1826. var bAsc = $.inArray('asc', oCol.asSorting) !== -1;
  1827. var bDesc = $.inArray('desc', oCol.asSorting) !== -1;
  1828. if ( !oCol.bSortable || (!bAsc && !bDesc) )
  1829. {
  1830. oCol.sSortingClass = oClasses.sSortableNone;
  1831. oCol.sSortingClassJUI = "";
  1832. }
  1833. else if ( bAsc && !bDesc )
  1834. {
  1835. oCol.sSortingClass = oClasses.sSortableAsc;
  1836. oCol.sSortingClassJUI = oClasses.sSortJUIAscAllowed;
  1837. }
  1838. else if ( !bAsc && bDesc )
  1839. {
  1840. oCol.sSortingClass = oClasses.sSortableDesc;
  1841. oCol.sSortingClassJUI = oClasses.sSortJUIDescAllowed;
  1842. }
  1843. else
  1844. {
  1845. oCol.sSortingClass = oClasses.sSortable;
  1846. oCol.sSortingClassJUI = oClasses.sSortJUI;
  1847. }
  1848. }
  1849. /**
  1850. * Adjust the table column widths for new data. Note: you would probably want to
  1851. * do a redraw after calling this function!
  1852. * @param {object} settings dataTables settings object
  1853. * @memberof DataTable#oApi
  1854. */
  1855. function _fnAdjustColumnSizing ( settings )
  1856. {
  1857. /* Not interested in doing column width calculation if auto-width is disabled */
  1858. if ( settings.oFeatures.bAutoWidth !== false )
  1859. {
  1860. var columns = settings.aoColumns;
  1861. _fnCalculateColumnWidths( settings );
  1862. for ( var i=0 , iLen=columns.length ; i<iLen ; i++ )
  1863. {
  1864. columns[i].nTh.style.width = columns[i].sWidth;
  1865. }
  1866. }
  1867. var scroll = settings.oScroll;
  1868. if ( scroll.sY !== '' || scroll.sX !== '')
  1869. {
  1870. _fnScrollDraw( settings );
  1871. }
  1872. _fnCallbackFire( settings, null, 'column-sizing', [settings] );
  1873. }
  1874. /**
  1875. * Covert the index of a visible column to the index in the data array (take account
  1876. * of hidden columns)
  1877. * @param {object} oSettings dataTables settings object
  1878. * @param {int} iMatch Visible column index to lookup
  1879. * @returns {int} i the data index
  1880. * @memberof DataTable#oApi
  1881. */
  1882. function _fnVisibleToColumnIndex( oSettings, iMatch )
  1883. {
  1884. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  1885. return typeof aiVis[iMatch] === 'number' ?
  1886. aiVis[iMatch] :
  1887. null;
  1888. }
  1889. /**
  1890. * Covert the index of an index in the data array and convert it to the visible
  1891. * column index (take account of hidden columns)
  1892. * @param {int} iMatch Column index to lookup
  1893. * @param {object} oSettings dataTables settings object
  1894. * @returns {int} i the data index
  1895. * @memberof DataTable#oApi
  1896. */
  1897. function _fnColumnIndexToVisible( oSettings, iMatch )
  1898. {
  1899. var aiVis = _fnGetColumns( oSettings, 'bVisible' );
  1900. var iPos = $.inArray( iMatch, aiVis );
  1901. return iPos !== -1 ? iPos : null;
  1902. }
  1903. /**
  1904. * Get the number of visible columns
  1905. * @param {object} oSettings dataTables settings object
  1906. * @returns {int} i the number of visible columns
  1907. * @memberof DataTable#oApi
  1908. */
  1909. function _fnVisbleColumns( oSettings )
  1910. {
  1911. var vis = 0;
  1912. // No reduce in IE8, use a loop for now
  1913. $.each( oSettings.aoColumns, function ( i, col ) {
  1914. if ( col.bVisible && $(col.nTh).css('display') !== 'none' ) {
  1915. vis++;
  1916. }
  1917. } );
  1918. return vis;
  1919. }
  1920. /**
  1921. * Get an array of column indexes that match a given property
  1922. * @param {object} oSettings dataTables settings object
  1923. * @param {string} sParam Parameter in aoColumns to look for - typically
  1924. * bVisible or bSearchable
  1925. * @returns {array} Array of indexes with matched properties
  1926. * @memberof DataTable#oApi
  1927. */
  1928. function _fnGetColumns( oSettings, sParam )
  1929. {
  1930. var a = [];
  1931. $.map( oSettings.aoColumns, function(val, i) {
  1932. if ( val[sParam] ) {
  1933. a.push( i );
  1934. }
  1935. } );
  1936. return a;
  1937. }
  1938. /**
  1939. * Calculate the 'type' of a column
  1940. * @param {object} settings dataTables settings object
  1941. * @memberof DataTable#oApi
  1942. */
  1943. function _fnColumnTypes ( settings )
  1944. {
  1945. var columns = settings.aoColumns;
  1946. var data = settings.aoData;
  1947. var types = DataTable.ext.type.detect;
  1948. var i, ien, j, jen, k, ken;
  1949. var col, cell, detectedType, cache;
  1950. // For each column, spin over the
  1951. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  1952. col = columns[i];
  1953. cache = [];
  1954. if ( ! col.sType && col._sManualType ) {
  1955. col.sType = col._sManualType;
  1956. }
  1957. else if ( ! col.sType ) {
  1958. for ( j=0, jen=types.length ; j<jen ; j++ ) {
  1959. for ( k=0, ken=data.length ; k<ken ; k++ ) {
  1960. // Use a cache array so we only need to get the type data
  1961. // from the formatter once (when using multiple detectors)
  1962. if ( cache[k] === undefined ) {
  1963. cache[k] = _fnGetCellData( settings, k, i, 'type' );
  1964. }
  1965. detectedType = types[j]( cache[k], settings );
  1966. // If null, then this type can't apply to this column, so
  1967. // rather than testing all cells, break out. There is an
  1968. // exception for the last type which is `html`. We need to
  1969. // scan all rows since it is possible to mix string and HTML
  1970. // types
  1971. if ( ! detectedType && j !== types.length-1 ) {
  1972. break;
  1973. }
  1974. // Only a single match is needed for html type since it is
  1975. // bottom of the pile and very similar to string
  1976. if ( detectedType === 'html' ) {
  1977. break;
  1978. }
  1979. }
  1980. // Type is valid for all data points in the column - use this
  1981. // type
  1982. if ( detectedType ) {
  1983. col.sType = detectedType;
  1984. break;
  1985. }
  1986. }
  1987. // Fall back - if no type was detected, always use string
  1988. if ( ! col.sType ) {
  1989. col.sType = 'string';
  1990. }
  1991. }
  1992. }
  1993. }
  1994. /**
  1995. * Take the column definitions and static columns arrays and calculate how
  1996. * they relate to column indexes. The callback function will then apply the
  1997. * definition found for a column to a suitable configuration object.
  1998. * @param {object} oSettings dataTables settings object
  1999. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  2000. * @param {array} aoCols The aoColumns array that defines columns individually
  2001. * @param {function} fn Callback function - takes two parameters, the calculated
  2002. * column index and the definition for that column.
  2003. * @memberof DataTable#oApi
  2004. */
  2005. function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
  2006. {
  2007. var i, iLen, j, jLen, k, kLen, def;
  2008. var columns = oSettings.aoColumns;
  2009. // Column definitions with aTargets
  2010. if ( aoColDefs )
  2011. {
  2012. /* Loop over the definitions array - loop in reverse so first instance has priority */
  2013. for ( i=aoColDefs.length-1 ; i>=0 ; i-- )
  2014. {
  2015. def = aoColDefs[i];
  2016. /* Each definition can target multiple columns, as it is an array */
  2017. var aTargets = def.targets !== undefined ?
  2018. def.targets :
  2019. def.aTargets;
  2020. if ( ! $.isArray( aTargets ) )
  2021. {
  2022. aTargets = [ aTargets ];
  2023. }
  2024. for ( j=0, jLen=aTargets.length ; j<jLen ; j++ )
  2025. {
  2026. if ( typeof aTargets[j] === 'number' && aTargets[j] >= 0 )
  2027. {
  2028. /* Add columns that we don't yet know about */
  2029. while( columns.length <= aTargets[j] )
  2030. {
  2031. _fnAddColumn( oSettings );
  2032. }
  2033. /* Integer, basic index */
  2034. fn( aTargets[j], def );
  2035. }
  2036. else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
  2037. {
  2038. /* Negative integer, right to left column counting */
  2039. fn( columns.length+aTargets[j], def );
  2040. }
  2041. else if ( typeof aTargets[j] === 'string' )
  2042. {
  2043. /* Class name matching on TH element */
  2044. for ( k=0, kLen=columns.length ; k<kLen ; k++ )
  2045. {
  2046. if ( aTargets[j] == "_all" ||
  2047. $(columns[k].nTh).hasClass( aTargets[j] ) )
  2048. {
  2049. fn( k, def );
  2050. }
  2051. }
  2052. }
  2053. }
  2054. }
  2055. }
  2056. // Statically defined columns array
  2057. if ( aoCols )
  2058. {
  2059. for ( i=0, iLen=aoCols.length ; i<iLen ; i++ )
  2060. {
  2061. fn( i, aoCols[i] );
  2062. }
  2063. }
  2064. }
  2065. /**
  2066. * Add a data array to the table, creating DOM node etc. This is the parallel to
  2067. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  2068. * DOM source.
  2069. * @param {object} oSettings dataTables settings object
  2070. * @param {array} aData data array to be added
  2071. * @param {node} [nTr] TR element to add to the table - optional. If not given,
  2072. * DataTables will create a row automatically
  2073. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2074. * if nTr is.
  2075. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  2076. * @memberof DataTable#oApi
  2077. */
  2078. function _fnAddData ( oSettings, aDataIn, nTr, anTds )
  2079. {
  2080. /* Create the object for storing information about this new row */
  2081. var iRow = oSettings.aoData.length;
  2082. var oData = $.extend( true, {}, DataTable.models.oRow, {
  2083. src: nTr ? 'dom' : 'data',
  2084. idx: iRow
  2085. } );
  2086. oData._aData = aDataIn;
  2087. oSettings.aoData.push( oData );
  2088. /* Create the cells */
  2089. var nTd, sThisType;
  2090. var columns = oSettings.aoColumns;
  2091. // Invalidate the column types as the new data needs to be revalidated
  2092. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  2093. {
  2094. columns[i].sType = null;
  2095. }
  2096. /* Add to the display array */
  2097. oSettings.aiDisplayMaster.push( iRow );
  2098. var id = oSettings.rowIdFn( aDataIn );
  2099. if ( id !== undefined ) {
  2100. oSettings.aIds[ id ] = oData;
  2101. }
  2102. /* Create the DOM information, or register it if already present */
  2103. if ( nTr || ! oSettings.oFeatures.bDeferRender )
  2104. {
  2105. _fnCreateTr( oSettings, iRow, nTr, anTds );
  2106. }
  2107. return iRow;
  2108. }
  2109. /**
  2110. * Add one or more TR elements to the table. Generally we'd expect to
  2111. * use this for reading data from a DOM sourced table, but it could be
  2112. * used for an TR element. Note that if a TR is given, it is used (i.e.
  2113. * it is not cloned).
  2114. * @param {object} settings dataTables settings object
  2115. * @param {array|node|jQuery} trs The TR element(s) to add to the table
  2116. * @returns {array} Array of indexes for the added rows
  2117. * @memberof DataTable#oApi
  2118. */
  2119. function _fnAddTr( settings, trs )
  2120. {
  2121. var row;
  2122. // Allow an individual node to be passed in
  2123. if ( ! (trs instanceof $) ) {
  2124. trs = $(trs);
  2125. }
  2126. return trs.map( function (i, el) {
  2127. row = _fnGetRowElements( settings, el );
  2128. return _fnAddData( settings, row.data, el, row.cells );
  2129. } );
  2130. }
  2131. /**
  2132. * Take a TR element and convert it to an index in aoData
  2133. * @param {object} oSettings dataTables settings object
  2134. * @param {node} n the TR element to find
  2135. * @returns {int} index if the node is found, null if not
  2136. * @memberof DataTable#oApi
  2137. */
  2138. function _fnNodeToDataIndex( oSettings, n )
  2139. {
  2140. return (n._DT_RowIndex!==undefined) ? n._DT_RowIndex : null;
  2141. }
  2142. /**
  2143. * Take a TD element and convert it into a column data index (not the visible index)
  2144. * @param {object} oSettings dataTables settings object
  2145. * @param {int} iRow The row number the TD/TH can be found in
  2146. * @param {node} n The TD/TH element to find
  2147. * @returns {int} index if the node is found, -1 if not
  2148. * @memberof DataTable#oApi
  2149. */
  2150. function _fnNodeToColumnIndex( oSettings, iRow, n )
  2151. {
  2152. return $.inArray( n, oSettings.aoData[ iRow ].anCells );
  2153. }
  2154. /**
  2155. * Get the data for a given cell from the internal cache, taking into account data mapping
  2156. * @param {object} settings dataTables settings object
  2157. * @param {int} rowIdx aoData row id
  2158. * @param {int} colIdx Column index
  2159. * @param {string} type data get type ('display', 'type' 'filter' 'sort')
  2160. * @returns {*} Cell data
  2161. * @memberof DataTable#oApi
  2162. */
  2163. function _fnGetCellData( settings, rowIdx, colIdx, type )
  2164. {
  2165. var draw = settings.iDraw;
  2166. var col = settings.aoColumns[colIdx];
  2167. var rowData = settings.aoData[rowIdx]._aData;
  2168. var defaultContent = col.sDefaultContent;
  2169. var cellData = col.fnGetData( rowData, type, {
  2170. settings: settings,
  2171. row: rowIdx,
  2172. col: colIdx
  2173. } );
  2174. if ( cellData === undefined ) {
  2175. if ( settings.iDrawError != draw && defaultContent === null ) {
  2176. _fnLog( settings, 0, "Requested unknown parameter "+
  2177. (typeof col.mData=='function' ? '{function}' : "'"+col.mData+"'")+
  2178. " for row "+rowIdx+", column "+colIdx, 4 );
  2179. settings.iDrawError = draw;
  2180. }
  2181. return defaultContent;
  2182. }
  2183. // When the data source is null and a specific data type is requested (i.e.
  2184. // not the original data), we can use default column data
  2185. if ( (cellData === rowData || cellData === null) && defaultContent !== null && type !== undefined ) {
  2186. cellData = defaultContent;
  2187. }
  2188. else if ( typeof cellData === 'function' ) {
  2189. // If the data source is a function, then we run it and use the return,
  2190. // executing in the scope of the data object (for instances)
  2191. return cellData.call( rowData );
  2192. }
  2193. if ( cellData === null && type == 'display' ) {
  2194. return '';
  2195. }
  2196. return cellData;
  2197. }
  2198. /**
  2199. * Set the value for a specific cell, into the internal data cache
  2200. * @param {object} settings dataTables settings object
  2201. * @param {int} rowIdx aoData row id
  2202. * @param {int} colIdx Column index
  2203. * @param {*} val Value to set
  2204. * @memberof DataTable#oApi
  2205. */
  2206. function _fnSetCellData( settings, rowIdx, colIdx, val )
  2207. {
  2208. var col = settings.aoColumns[colIdx];
  2209. var rowData = settings.aoData[rowIdx]._aData;
  2210. col.fnSetData( rowData, val, {
  2211. settings: settings,
  2212. row: rowIdx,
  2213. col: colIdx
  2214. } );
  2215. }
  2216. // Private variable that is used to match action syntax in the data property object
  2217. var __reArray = /\[.*?\]$/;
  2218. var __reFn = /\(\)$/;
  2219. /**
  2220. * Split string on periods, taking into account escaped periods
  2221. * @param {string} str String to split
  2222. * @return {array} Split string
  2223. */
  2224. function _fnSplitObjNotation( str )
  2225. {
  2226. return $.map( str.match(/(\\.|[^\.])+/g) || [''], function ( s ) {
  2227. return s.replace(/\\\./g, '.');
  2228. } );
  2229. }
  2230. /**
  2231. * Return a function that can be used to get data from a source object, taking
  2232. * into account the ability to use nested objects as a source
  2233. * @param {string|int|function} mSource The data source for the object
  2234. * @returns {function} Data get function
  2235. * @memberof DataTable#oApi
  2236. */
  2237. function _fnGetObjectDataFn( mSource )
  2238. {
  2239. if ( $.isPlainObject( mSource ) )
  2240. {
  2241. /* Build an object of get functions, and wrap them in a single call */
  2242. var o = {};
  2243. $.each( mSource, function (key, val) {
  2244. if ( val ) {
  2245. o[key] = _fnGetObjectDataFn( val );
  2246. }
  2247. } );
  2248. return function (data, type, row, meta) {
  2249. var t = o[type] || o._;
  2250. return t !== undefined ?
  2251. t(data, type, row, meta) :
  2252. data;
  2253. };
  2254. }
  2255. else if ( mSource === null )
  2256. {
  2257. /* Give an empty string for rendering / sorting etc */
  2258. return function (data) { // type, row and meta also passed, but not used
  2259. return data;
  2260. };
  2261. }
  2262. else if ( typeof mSource === 'function' )
  2263. {
  2264. return function (data, type, row, meta) {
  2265. return mSource( data, type, row, meta );
  2266. };
  2267. }
  2268. else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 ||
  2269. mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1) )
  2270. {
  2271. /* If there is a . in the source string then the data source is in a
  2272. * nested object so we loop over the data for each level to get the next
  2273. * level down. On each loop we test for undefined, and if found immediately
  2274. * return. This allows entire objects to be missing and sDefaultContent to
  2275. * be used if defined, rather than throwing an error
  2276. */
  2277. var fetchData = function (data, type, src) {
  2278. var arrayNotation, funcNotation, out, innerSrc;
  2279. if ( src !== "" )
  2280. {
  2281. var a = _fnSplitObjNotation( src );
  2282. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  2283. {
  2284. // Check if we are dealing with special notation
  2285. arrayNotation = a[i].match(__reArray);
  2286. funcNotation = a[i].match(__reFn);
  2287. if ( arrayNotation )
  2288. {
  2289. // Array notation
  2290. a[i] = a[i].replace(__reArray, '');
  2291. // Condition allows simply [] to be passed in
  2292. if ( a[i] !== "" ) {
  2293. data = data[ a[i] ];
  2294. }
  2295. out = [];
  2296. // Get the remainder of the nested object to get
  2297. a.splice( 0, i+1 );
  2298. innerSrc = a.join('.');
  2299. // Traverse each entry in the array getting the properties requested
  2300. if ( $.isArray( data ) ) {
  2301. for ( var j=0, jLen=data.length ; j<jLen ; j++ ) {
  2302. out.push( fetchData( data[j], type, innerSrc ) );
  2303. }
  2304. }
  2305. // If a string is given in between the array notation indicators, that
  2306. // is used to join the strings together, otherwise an array is returned
  2307. var join = arrayNotation[0].substring(1, arrayNotation[0].length-1);
  2308. data = (join==="") ? out : out.join(join);
  2309. // The inner call to fetchData has already traversed through the remainder
  2310. // of the source requested, so we exit from the loop
  2311. break;
  2312. }
  2313. else if ( funcNotation )
  2314. {
  2315. // Function call
  2316. a[i] = a[i].replace(__reFn, '');
  2317. data = data[ a[i] ]();
  2318. continue;
  2319. }
  2320. if ( data === null || data[ a[i] ] === undefined )
  2321. {
  2322. return undefined;
  2323. }
  2324. data = data[ a[i] ];
  2325. }
  2326. }
  2327. return data;
  2328. };
  2329. return function (data, type) { // row and meta also passed, but not used
  2330. return fetchData( data, type, mSource );
  2331. };
  2332. }
  2333. else
  2334. {
  2335. /* Array or flat object mapping */
  2336. return function (data, type) { // row and meta also passed, but not used
  2337. return data[mSource];
  2338. };
  2339. }
  2340. }
  2341. /**
  2342. * Return a function that can be used to set data from a source object, taking
  2343. * into account the ability to use nested objects as a source
  2344. * @param {string|int|function} mSource The data source for the object
  2345. * @returns {function} Data set function
  2346. * @memberof DataTable#oApi
  2347. */
  2348. function _fnSetObjectDataFn( mSource )
  2349. {
  2350. if ( $.isPlainObject( mSource ) )
  2351. {
  2352. /* Unlike get, only the underscore (global) option is used for for
  2353. * setting data since we don't know the type here. This is why an object
  2354. * option is not documented for `mData` (which is read/write), but it is
  2355. * for `mRender` which is read only.
  2356. */
  2357. return _fnSetObjectDataFn( mSource._ );
  2358. }
  2359. else if ( mSource === null )
  2360. {
  2361. /* Nothing to do when the data source is null */
  2362. return function () {};
  2363. }
  2364. else if ( typeof mSource === 'function' )
  2365. {
  2366. return function (data, val, meta) {
  2367. mSource( data, 'set', val, meta );
  2368. };
  2369. }
  2370. else if ( typeof mSource === 'string' && (mSource.indexOf('.') !== -1 ||
  2371. mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1) )
  2372. {
  2373. /* Like the get, we need to get data from a nested object */
  2374. var setData = function (data, val, src) {
  2375. var a = _fnSplitObjNotation( src ), b;
  2376. var aLast = a[a.length-1];
  2377. var arrayNotation, funcNotation, o, innerSrc;
  2378. for ( var i=0, iLen=a.length-1 ; i<iLen ; i++ )
  2379. {
  2380. // Check if we are dealing with an array notation request
  2381. arrayNotation = a[i].match(__reArray);
  2382. funcNotation = a[i].match(__reFn);
  2383. if ( arrayNotation )
  2384. {
  2385. a[i] = a[i].replace(__reArray, '');
  2386. data[ a[i] ] = [];
  2387. // Get the remainder of the nested object to set so we can recurse
  2388. b = a.slice();
  2389. b.splice( 0, i+1 );
  2390. innerSrc = b.join('.');
  2391. // Traverse each entry in the array setting the properties requested
  2392. if ( $.isArray( val ) )
  2393. {
  2394. for ( var j=0, jLen=val.length ; j<jLen ; j++ )
  2395. {
  2396. o = {};
  2397. setData( o, val[j], innerSrc );
  2398. data[ a[i] ].push( o );
  2399. }
  2400. }
  2401. else
  2402. {
  2403. // We've been asked to save data to an array, but it
  2404. // isn't array data to be saved. Best that can be done
  2405. // is to just save the value.
  2406. data[ a[i] ] = val;
  2407. }
  2408. // The inner call to setData has already traversed through the remainder
  2409. // of the source and has set the data, thus we can exit here
  2410. return;
  2411. }
  2412. else if ( funcNotation )
  2413. {
  2414. // Function call
  2415. a[i] = a[i].replace(__reFn, '');
  2416. data = data[ a[i] ]( val );
  2417. }
  2418. // If the nested object doesn't currently exist - since we are
  2419. // trying to set the value - create it
  2420. if ( data[ a[i] ] === null || data[ a[i] ] === undefined )
  2421. {
  2422. data[ a[i] ] = {};
  2423. }
  2424. data = data[ a[i] ];
  2425. }
  2426. // Last item in the input - i.e, the actual set
  2427. if ( aLast.match(__reFn ) )
  2428. {
  2429. // Function call
  2430. data = data[ aLast.replace(__reFn, '') ]( val );
  2431. }
  2432. else
  2433. {
  2434. // If array notation is used, we just want to strip it and use the property name
  2435. // and assign the value. If it isn't used, then we get the result we want anyway
  2436. data[ aLast.replace(__reArray, '') ] = val;
  2437. }
  2438. };
  2439. return function (data, val) { // meta is also passed in, but not used
  2440. return setData( data, val, mSource );
  2441. };
  2442. }
  2443. else
  2444. {
  2445. /* Array or flat object mapping */
  2446. return function (data, val) { // meta is also passed in, but not used
  2447. data[mSource] = val;
  2448. };
  2449. }
  2450. }
  2451. /**
  2452. * Return an array with the full table data
  2453. * @param {object} oSettings dataTables settings object
  2454. * @returns array {array} aData Master data array
  2455. * @memberof DataTable#oApi
  2456. */
  2457. function _fnGetDataMaster ( settings )
  2458. {
  2459. return _pluck( settings.aoData, '_aData' );
  2460. }
  2461. /**
  2462. * Nuke the table
  2463. * @param {object} oSettings dataTables settings object
  2464. * @memberof DataTable#oApi
  2465. */
  2466. function _fnClearTable( settings )
  2467. {
  2468. settings.aoData.length = 0;
  2469. settings.aiDisplayMaster.length = 0;
  2470. settings.aiDisplay.length = 0;
  2471. settings.aIds = {};
  2472. }
  2473. /**
  2474. * Take an array of integers (index array) and remove a target integer (value - not
  2475. * the key!)
  2476. * @param {array} a Index array to target
  2477. * @param {int} iTarget value to find
  2478. * @memberof DataTable#oApi
  2479. */
  2480. function _fnDeleteIndex( a, iTarget, splice )
  2481. {
  2482. var iTargetIndex = -1;
  2483. for ( var i=0, iLen=a.length ; i<iLen ; i++ )
  2484. {
  2485. if ( a[i] == iTarget )
  2486. {
  2487. iTargetIndex = i;
  2488. }
  2489. else if ( a[i] > iTarget )
  2490. {
  2491. a[i]--;
  2492. }
  2493. }
  2494. if ( iTargetIndex != -1 && splice === undefined )
  2495. {
  2496. a.splice( iTargetIndex, 1 );
  2497. }
  2498. }
  2499. /**
  2500. * Mark cached data as invalid such that a re-read of the data will occur when
  2501. * the cached data is next requested. Also update from the data source object.
  2502. *
  2503. * @param {object} settings DataTables settings object
  2504. * @param {int} rowIdx Row index to invalidate
  2505. * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
  2506. * or 'data'
  2507. * @param {int} [colIdx] Column index to invalidate. If undefined the whole
  2508. * row will be invalidated
  2509. * @memberof DataTable#oApi
  2510. *
  2511. * @todo For the modularisation of v1.11 this will need to become a callback, so
  2512. * the sort and filter methods can subscribe to it. That will required
  2513. * initialisation options for sorting, which is why it is not already baked in
  2514. */
  2515. function _fnInvalidate( settings, rowIdx, src, colIdx )
  2516. {
  2517. var row = settings.aoData[ rowIdx ];
  2518. var i, ien;
  2519. var cellWrite = function ( cell, col ) {
  2520. // This is very frustrating, but in IE if you just write directly
  2521. // to innerHTML, and elements that are overwritten are GC'ed,
  2522. // even if there is a reference to them elsewhere
  2523. while ( cell.childNodes.length ) {
  2524. cell.removeChild( cell.firstChild );
  2525. }
  2526. cell.innerHTML = _fnGetCellData( settings, rowIdx, col, 'display' );
  2527. };
  2528. // Are we reading last data from DOM or the data object?
  2529. if ( src === 'dom' || ((! src || src === 'auto') && row.src === 'dom') ) {
  2530. // Read the data from the DOM
  2531. row._aData = _fnGetRowElements(
  2532. settings, row, colIdx, colIdx === undefined ? undefined : row._aData
  2533. )
  2534. .data;
  2535. }
  2536. else {
  2537. // Reading from data object, update the DOM
  2538. var cells = row.anCells;
  2539. if ( cells ) {
  2540. if ( colIdx !== undefined ) {
  2541. cellWrite( cells[colIdx], colIdx );
  2542. }
  2543. else {
  2544. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2545. cellWrite( cells[i], i );
  2546. }
  2547. }
  2548. }
  2549. }
  2550. // For both row and cell invalidation, the cached data for sorting and
  2551. // filtering is nulled out
  2552. row._aSortData = null;
  2553. row._aFilterData = null;
  2554. // Invalidate the type for a specific column (if given) or all columns since
  2555. // the data might have changed
  2556. var cols = settings.aoColumns;
  2557. if ( colIdx !== undefined ) {
  2558. cols[ colIdx ].sType = null;
  2559. }
  2560. else {
  2561. for ( i=0, ien=cols.length ; i<ien ; i++ ) {
  2562. cols[i].sType = null;
  2563. }
  2564. // Update DataTables special `DT_*` attributes for the row
  2565. _fnRowAttributes( settings, row );
  2566. }
  2567. }
  2568. /**
  2569. * Build a data source object from an HTML row, reading the contents of the
  2570. * cells that are in the row.
  2571. *
  2572. * @param {object} settings DataTables settings object
  2573. * @param {node|object} TR element from which to read data or existing row
  2574. * object from which to re-read the data from the cells
  2575. * @param {int} [colIdx] Optional column index
  2576. * @param {array|object} [d] Data source object. If `colIdx` is given then this
  2577. * parameter should also be given and will be used to write the data into.
  2578. * Only the column in question will be written
  2579. * @returns {object} Object with two parameters: `data` the data read, in
  2580. * document order, and `cells` and array of nodes (they can be useful to the
  2581. * caller, so rather than needing a second traversal to get them, just return
  2582. * them from here).
  2583. * @memberof DataTable#oApi
  2584. */
  2585. function _fnGetRowElements( settings, row, colIdx, d )
  2586. {
  2587. var
  2588. tds = [],
  2589. td = row.firstChild,
  2590. name, col, o, i=0, contents,
  2591. columns = settings.aoColumns,
  2592. objectRead = settings._rowReadObject;
  2593. // Allow the data object to be passed in, or construct
  2594. d = d !== undefined ?
  2595. d :
  2596. objectRead ?
  2597. {} :
  2598. [];
  2599. var attr = function ( str, td ) {
  2600. if ( typeof str === 'string' ) {
  2601. var idx = str.indexOf('@');
  2602. if ( idx !== -1 ) {
  2603. var attr = str.substring( idx+1 );
  2604. var setter = _fnSetObjectDataFn( str );
  2605. setter( d, td.getAttribute( attr ) );
  2606. }
  2607. }
  2608. };
  2609. // Read data from a cell and store into the data object
  2610. var cellProcess = function ( cell ) {
  2611. if ( colIdx === undefined || colIdx === i ) {
  2612. col = columns[i];
  2613. contents = $.trim(cell.innerHTML);
  2614. if ( col && col._bAttrSrc ) {
  2615. var setter = _fnSetObjectDataFn( col.mData._ );
  2616. setter( d, contents );
  2617. attr( col.mData.sort, cell );
  2618. attr( col.mData.type, cell );
  2619. attr( col.mData.filter, cell );
  2620. }
  2621. else {
  2622. // Depending on the `data` option for the columns the data can
  2623. // be read to either an object or an array.
  2624. if ( objectRead ) {
  2625. if ( ! col._setter ) {
  2626. // Cache the setter function
  2627. col._setter = _fnSetObjectDataFn( col.mData );
  2628. }
  2629. col._setter( d, contents );
  2630. }
  2631. else {
  2632. d[i] = contents;
  2633. }
  2634. }
  2635. }
  2636. i++;
  2637. };
  2638. if ( td ) {
  2639. // `tr` element was passed in
  2640. while ( td ) {
  2641. name = td.nodeName.toUpperCase();
  2642. if ( name == "TD" || name == "TH" ) {
  2643. cellProcess( td );
  2644. tds.push( td );
  2645. }
  2646. td = td.nextSibling;
  2647. }
  2648. }
  2649. else {
  2650. // Existing row object passed in
  2651. tds = row.anCells;
  2652. for ( var j=0, jen=tds.length ; j<jen ; j++ ) {
  2653. cellProcess( tds[j] );
  2654. }
  2655. }
  2656. // Read the ID from the DOM if present
  2657. var rowNode = row.firstChild ? row : row.nTr;
  2658. if ( rowNode ) {
  2659. var id = rowNode.getAttribute( 'id' );
  2660. if ( id ) {
  2661. _fnSetObjectDataFn( settings.rowId )( d, id );
  2662. }
  2663. }
  2664. return {
  2665. data: d,
  2666. cells: tds
  2667. };
  2668. }
  2669. /**
  2670. * Create a new TR element (and it's TD children) for a row
  2671. * @param {object} oSettings dataTables settings object
  2672. * @param {int} iRow Row to consider
  2673. * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
  2674. * DataTables will create a row automatically
  2675. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2676. * if nTr is.
  2677. * @memberof DataTable#oApi
  2678. */
  2679. function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
  2680. {
  2681. var
  2682. row = oSettings.aoData[iRow],
  2683. rowData = row._aData,
  2684. cells = [],
  2685. nTr, nTd, oCol,
  2686. i, iLen;
  2687. if ( row.nTr === null )
  2688. {
  2689. nTr = nTrIn || document.createElement('tr');
  2690. row.nTr = nTr;
  2691. row.anCells = cells;
  2692. /* Use a private property on the node to allow reserve mapping from the node
  2693. * to the aoData array for fast look up
  2694. */
  2695. nTr._DT_RowIndex = iRow;
  2696. /* Special parameters can be given by the data source to be used on the row */
  2697. _fnRowAttributes( oSettings, row );
  2698. /* Process each column */
  2699. for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
  2700. {
  2701. oCol = oSettings.aoColumns[i];
  2702. nTd = nTrIn ? anTds[i] : document.createElement( oCol.sCellType );
  2703. nTd._DT_CellIndex = {
  2704. row: iRow,
  2705. column: i
  2706. };
  2707. cells.push( nTd );
  2708. // Need to create the HTML if new, or if a rendering function is defined
  2709. if ( (!nTrIn || oCol.mRender || oCol.mData !== i) &&
  2710. (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i+'.display')
  2711. ) {
  2712. nTd.innerHTML = _fnGetCellData( oSettings, iRow, i, 'display' );
  2713. }
  2714. /* Add user defined class */
  2715. if ( oCol.sClass )
  2716. {
  2717. nTd.className += ' '+oCol.sClass;
  2718. }
  2719. // Visibility - add or remove as required
  2720. if ( oCol.bVisible && ! nTrIn )
  2721. {
  2722. nTr.appendChild( nTd );
  2723. }
  2724. else if ( ! oCol.bVisible && nTrIn )
  2725. {
  2726. nTd.parentNode.removeChild( nTd );
  2727. }
  2728. if ( oCol.fnCreatedCell )
  2729. {
  2730. oCol.fnCreatedCell.call( oSettings.oInstance,
  2731. nTd, _fnGetCellData( oSettings, iRow, i ), rowData, iRow, i
  2732. );
  2733. }
  2734. }
  2735. _fnCallbackFire( oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow, cells] );
  2736. }
  2737. // Remove once webkit bug 131819 and Chromium bug 365619 have been resolved
  2738. // and deployed
  2739. row.nTr.setAttribute( 'role', 'row' );
  2740. }
  2741. /**
  2742. * Add attributes to a row based on the special `DT_*` parameters in a data
  2743. * source object.
  2744. * @param {object} settings DataTables settings object
  2745. * @param {object} DataTables row object for the row to be modified
  2746. * @memberof DataTable#oApi
  2747. */
  2748. function _fnRowAttributes( settings, row )
  2749. {
  2750. var tr = row.nTr;
  2751. var data = row._aData;
  2752. if ( tr ) {
  2753. var id = settings.rowIdFn( data );
  2754. if ( id ) {
  2755. tr.id = id;
  2756. }
  2757. if ( data.DT_RowClass ) {
  2758. // Remove any classes added by DT_RowClass before
  2759. var a = data.DT_RowClass.split(' ');
  2760. row.__rowc = row.__rowc ?
  2761. _unique( row.__rowc.concat( a ) ) :
  2762. a;
  2763. $(tr)
  2764. .removeClass( row.__rowc.join(' ') )
  2765. .addClass( data.DT_RowClass );
  2766. }
  2767. if ( data.DT_RowAttr ) {
  2768. $(tr).attr( data.DT_RowAttr );
  2769. }
  2770. if ( data.DT_RowData ) {
  2771. $(tr).data( data.DT_RowData );
  2772. }
  2773. }
  2774. }
  2775. /**
  2776. * Create the HTML header for the table
  2777. * @param {object} oSettings dataTables settings object
  2778. * @memberof DataTable#oApi
  2779. */
  2780. function _fnBuildHead( oSettings )
  2781. {
  2782. var i, ien, cell, row, column;
  2783. var thead = oSettings.nTHead;
  2784. var tfoot = oSettings.nTFoot;
  2785. var createHeader = $('th, td', thead).length === 0;
  2786. var classes = oSettings.oClasses;
  2787. var columns = oSettings.aoColumns;
  2788. if ( createHeader ) {
  2789. row = $('<tr/>').appendTo( thead );
  2790. }
  2791. for ( i=0, ien=columns.length ; i<ien ; i++ ) {
  2792. column = columns[i];
  2793. cell = $( column.nTh ).addClass( column.sClass );
  2794. if ( createHeader ) {
  2795. cell.appendTo( row );
  2796. }
  2797. // 1.11 move into sorting
  2798. if ( oSettings.oFeatures.bSort ) {
  2799. cell.addClass( column.sSortingClass );
  2800. if ( column.bSortable !== false ) {
  2801. cell
  2802. .attr( 'tabindex', oSettings.iTabIndex )
  2803. .attr( 'aria-controls', oSettings.sTableId );
  2804. _fnSortAttachListener( oSettings, column.nTh, i );
  2805. }
  2806. }
  2807. if ( column.sTitle != cell[0].innerHTML ) {
  2808. cell.html( column.sTitle );
  2809. }
  2810. _fnRenderer( oSettings, 'header' )(
  2811. oSettings, cell, column, classes
  2812. );
  2813. }
  2814. if ( createHeader ) {
  2815. _fnDetectHeader( oSettings.aoHeader, thead );
  2816. }
  2817. /* ARIA role for the rows */
  2818. $(thead).find('>tr').attr('role', 'row');
  2819. /* Deal with the footer - add classes if required */
  2820. $(thead).find('>tr>th, >tr>td').addClass( classes.sHeaderTH );
  2821. $(tfoot).find('>tr>th, >tr>td').addClass( classes.sFooterTH );
  2822. // Cache the footer cells. Note that we only take the cells from the first
  2823. // row in the footer. If there is more than one row the user wants to
  2824. // interact with, they need to use the table().foot() method. Note also this
  2825. // allows cells to be used for multiple columns using colspan
  2826. if ( tfoot !== null ) {
  2827. var cells = oSettings.aoFooter[0];
  2828. for ( i=0, ien=cells.length ; i<ien ; i++ ) {
  2829. column = columns[i];
  2830. column.nTf = cells[i].cell;
  2831. if ( column.sClass ) {
  2832. $(column.nTf).addClass( column.sClass );
  2833. }
  2834. }
  2835. }
  2836. }
  2837. /**
  2838. * Draw the header (or footer) element based on the column visibility states. The
  2839. * methodology here is to use the layout array from _fnDetectHeader, modified for
  2840. * the instantaneous column visibility, to construct the new layout. The grid is
  2841. * traversed over cell at a time in a rows x columns grid fashion, although each
  2842. * cell insert can cover multiple elements in the grid - which is tracks using the
  2843. * aApplied array. Cell inserts in the grid will only occur where there isn't
  2844. * already a cell in that position.
  2845. * @param {object} oSettings dataTables settings object
  2846. * @param array {objects} aoSource Layout array from _fnDetectHeader
  2847. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  2848. * @memberof DataTable#oApi
  2849. */
  2850. function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
  2851. {
  2852. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  2853. var aoLocal = [];
  2854. var aApplied = [];
  2855. var iColumns = oSettings.aoColumns.length;
  2856. var iRowspan, iColspan;
  2857. if ( ! aoSource )
  2858. {
  2859. return;
  2860. }
  2861. if ( bIncludeHidden === undefined )
  2862. {
  2863. bIncludeHidden = false;
  2864. }
  2865. /* Make a copy of the master layout array, but without the visible columns in it */
  2866. for ( i=0, iLen=aoSource.length ; i<iLen ; i++ )
  2867. {
  2868. aoLocal[i] = aoSource[i].slice();
  2869. aoLocal[i].nTr = aoSource[i].nTr;
  2870. /* Remove any columns which are currently hidden */
  2871. for ( j=iColumns-1 ; j>=0 ; j-- )
  2872. {
  2873. if ( !oSettings.aoColumns[j].bVisible && !bIncludeHidden )
  2874. {
  2875. aoLocal[i].splice( j, 1 );
  2876. }
  2877. }
  2878. /* Prep the applied array - it needs an element for each row */
  2879. aApplied.push( [] );
  2880. }
  2881. for ( i=0, iLen=aoLocal.length ; i<iLen ; i++ )
  2882. {
  2883. nLocalTr = aoLocal[i].nTr;
  2884. /* All cells are going to be replaced, so empty out the row */
  2885. if ( nLocalTr )
  2886. {
  2887. while( (n = nLocalTr.firstChild) )
  2888. {
  2889. nLocalTr.removeChild( n );
  2890. }
  2891. }
  2892. for ( j=0, jLen=aoLocal[i].length ; j<jLen ; j++ )
  2893. {
  2894. iRowspan = 1;
  2895. iColspan = 1;
  2896. /* Check to see if there is already a cell (row/colspan) covering our target
  2897. * insert point. If there is, then there is nothing to do.
  2898. */
  2899. if ( aApplied[i][j] === undefined )
  2900. {
  2901. nLocalTr.appendChild( aoLocal[i][j].cell );
  2902. aApplied[i][j] = 1;
  2903. /* Expand the cell to cover as many rows as needed */
  2904. while ( aoLocal[i+iRowspan] !== undefined &&
  2905. aoLocal[i][j].cell == aoLocal[i+iRowspan][j].cell )
  2906. {
  2907. aApplied[i+iRowspan][j] = 1;
  2908. iRowspan++;
  2909. }
  2910. /* Expand the cell to cover as many columns as needed */
  2911. while ( aoLocal[i][j+iColspan] !== undefined &&
  2912. aoLocal[i][j].cell == aoLocal[i][j+iColspan].cell )
  2913. {
  2914. /* Must update the applied array over the rows for the columns */
  2915. for ( k=0 ; k<iRowspan ; k++ )
  2916. {
  2917. aApplied[i+k][j+iColspan] = 1;
  2918. }
  2919. iColspan++;
  2920. }
  2921. /* Do the actual expansion in the DOM */
  2922. $(aoLocal[i][j].cell)
  2923. .attr('rowspan', iRowspan)
  2924. .attr('colspan', iColspan);
  2925. }
  2926. }
  2927. }
  2928. }
  2929. /**
  2930. * Insert the required TR nodes into the table for display
  2931. * @param {object} oSettings dataTables settings object
  2932. * @memberof DataTable#oApi
  2933. */
  2934. function _fnDraw( oSettings )
  2935. {
  2936. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  2937. var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
  2938. if ( $.inArray( false, aPreDraw ) !== -1 )
  2939. {
  2940. _fnProcessingDisplay( oSettings, false );
  2941. return;
  2942. }
  2943. var i, iLen, n;
  2944. var anRows = [];
  2945. var iRowCount = 0;
  2946. var asStripeClasses = oSettings.asStripeClasses;
  2947. var iStripes = asStripeClasses.length;
  2948. var iOpenRows = oSettings.aoOpenRows.length;
  2949. var oLang = oSettings.oLanguage;
  2950. var iInitDisplayStart = oSettings.iInitDisplayStart;
  2951. var bServerSide = _fnDataSource( oSettings ) == 'ssp';
  2952. var aiDisplay = oSettings.aiDisplay;
  2953. oSettings.bDrawing = true;
  2954. /* Check and see if we have an initial draw position from state saving */
  2955. if ( iInitDisplayStart !== undefined && iInitDisplayStart !== -1 )
  2956. {
  2957. oSettings._iDisplayStart = bServerSide ?
  2958. iInitDisplayStart :
  2959. iInitDisplayStart >= oSettings.fnRecordsDisplay() ?
  2960. 0 :
  2961. iInitDisplayStart;
  2962. oSettings.iInitDisplayStart = -1;
  2963. }
  2964. var iDisplayStart = oSettings._iDisplayStart;
  2965. var iDisplayEnd = oSettings.fnDisplayEnd();
  2966. /* Server-side processing draw intercept */
  2967. if ( oSettings.bDeferLoading )
  2968. {
  2969. oSettings.bDeferLoading = false;
  2970. oSettings.iDraw++;
  2971. _fnProcessingDisplay( oSettings, false );
  2972. }
  2973. else if ( !bServerSide )
  2974. {
  2975. oSettings.iDraw++;
  2976. }
  2977. else if ( !oSettings.bDestroying && !_fnAjaxUpdate( oSettings ) )
  2978. {
  2979. return;
  2980. }
  2981. if ( aiDisplay.length !== 0 )
  2982. {
  2983. var iStart = bServerSide ? 0 : iDisplayStart;
  2984. var iEnd = bServerSide ? oSettings.aoData.length : iDisplayEnd;
  2985. for ( var j=iStart ; j<iEnd ; j++ )
  2986. {
  2987. var iDataIndex = aiDisplay[j];
  2988. var aoData = oSettings.aoData[ iDataIndex ];
  2989. if ( aoData.nTr === null )
  2990. {
  2991. _fnCreateTr( oSettings, iDataIndex );
  2992. }
  2993. var nRow = aoData.nTr;
  2994. /* Remove the old striping classes and then add the new one */
  2995. if ( iStripes !== 0 )
  2996. {
  2997. var sStripe = asStripeClasses[ iRowCount % iStripes ];
  2998. if ( aoData._sRowStripe != sStripe )
  2999. {
  3000. $(nRow).removeClass( aoData._sRowStripe ).addClass( sStripe );
  3001. aoData._sRowStripe = sStripe;
  3002. }
  3003. }
  3004. // Row callback functions - might want to manipulate the row
  3005. // iRowCount and j are not currently documented. Are they at all
  3006. // useful?
  3007. _fnCallbackFire( oSettings, 'aoRowCallback', null,
  3008. [nRow, aoData._aData, iRowCount, j, iDataIndex] );
  3009. anRows.push( nRow );
  3010. iRowCount++;
  3011. }
  3012. }
  3013. else
  3014. {
  3015. /* Table is empty - create a row with an empty message in it */
  3016. var sZero = oLang.sZeroRecords;
  3017. if ( oSettings.iDraw == 1 && _fnDataSource( oSettings ) == 'ajax' )
  3018. {
  3019. sZero = oLang.sLoadingRecords;
  3020. }
  3021. else if ( oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0 )
  3022. {
  3023. sZero = oLang.sEmptyTable;
  3024. }
  3025. anRows[ 0 ] = $( '<tr/>', { 'class': iStripes ? asStripeClasses[0] : '' } )
  3026. .append( $('<td />', {
  3027. 'valign': 'top',
  3028. 'colSpan': _fnVisbleColumns( oSettings ),
  3029. 'class': oSettings.oClasses.sRowEmpty
  3030. } ).html( sZero ) )[0];
  3031. }
  3032. /* Header and footer callbacks */
  3033. _fnCallbackFire( oSettings, 'aoHeaderCallback', 'header', [ $(oSettings.nTHead).children('tr')[0],
  3034. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3035. _fnCallbackFire( oSettings, 'aoFooterCallback', 'footer', [ $(oSettings.nTFoot).children('tr')[0],
  3036. _fnGetDataMaster( oSettings ), iDisplayStart, iDisplayEnd, aiDisplay ] );
  3037. var body = $(oSettings.nTBody);
  3038. body.children().detach();
  3039. body.append( $(anRows) );
  3040. /* Call all required callback functions for the end of a draw */
  3041. _fnCallbackFire( oSettings, 'aoDrawCallback', 'draw', [oSettings] );
  3042. /* Draw is complete, sorting and filtering must be as well */
  3043. oSettings.bSorted = false;
  3044. oSettings.bFiltered = false;
  3045. oSettings.bDrawing = false;
  3046. }
  3047. /**
  3048. * Redraw the table - taking account of the various features which are enabled
  3049. * @param {object} oSettings dataTables settings object
  3050. * @param {boolean} [holdPosition] Keep the current paging position. By default
  3051. * the paging is reset to the first page
  3052. * @memberof DataTable#oApi
  3053. */
  3054. function _fnReDraw( settings, holdPosition )
  3055. {
  3056. var
  3057. features = settings.oFeatures,
  3058. sort = features.bSort,
  3059. filter = features.bFilter;
  3060. if ( sort ) {
  3061. _fnSort( settings );
  3062. }
  3063. if ( filter ) {
  3064. _fnFilterComplete( settings, settings.oPreviousSearch );
  3065. }
  3066. else {
  3067. // No filtering, so we want to just use the display master
  3068. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3069. }
  3070. if ( holdPosition !== true ) {
  3071. settings._iDisplayStart = 0;
  3072. }
  3073. // Let any modules know about the draw hold position state (used by
  3074. // scrolling internally)
  3075. settings._drawHold = holdPosition;
  3076. _fnDraw( settings );
  3077. settings._drawHold = false;
  3078. }
  3079. /**
  3080. * Add the options to the page HTML for the table
  3081. * @param {object} oSettings dataTables settings object
  3082. * @memberof DataTable#oApi
  3083. */
  3084. function _fnAddOptionsHtml ( oSettings )
  3085. {
  3086. var classes = oSettings.oClasses;
  3087. var table = $(oSettings.nTable);
  3088. var holding = $('<div/>').insertBefore( table ); // Holding element for speed
  3089. var features = oSettings.oFeatures;
  3090. // All DataTables are wrapped in a div
  3091. var insert = $('<div/>', {
  3092. id: oSettings.sTableId+'_wrapper',
  3093. 'class': classes.sWrapper + (oSettings.nTFoot ? '' : ' '+classes.sNoFooter)
  3094. } );
  3095. oSettings.nHolding = holding[0];
  3096. oSettings.nTableWrapper = insert[0];
  3097. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  3098. /* Loop over the user set positioning and place the elements as needed */
  3099. var aDom = oSettings.sDom.split('');
  3100. var featureNode, cOption, nNewNode, cNext, sAttr, j;
  3101. for ( var i=0 ; i<aDom.length ; i++ )
  3102. {
  3103. featureNode = null;
  3104. cOption = aDom[i];
  3105. if ( cOption == '<' )
  3106. {
  3107. /* New container div */
  3108. nNewNode = $('<div/>')[0];
  3109. /* Check to see if we should append an id and/or a class name to the container */
  3110. cNext = aDom[i+1];
  3111. if ( cNext == "'" || cNext == '"' )
  3112. {
  3113. sAttr = "";
  3114. j = 2;
  3115. while ( aDom[i+j] != cNext )
  3116. {
  3117. sAttr += aDom[i+j];
  3118. j++;
  3119. }
  3120. /* Replace jQuery UI constants @todo depreciated */
  3121. if ( sAttr == "H" )
  3122. {
  3123. sAttr = classes.sJUIHeader;
  3124. }
  3125. else if ( sAttr == "F" )
  3126. {
  3127. sAttr = classes.sJUIFooter;
  3128. }
  3129. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  3130. * breaks the string into parts and applies them as needed
  3131. */
  3132. if ( sAttr.indexOf('.') != -1 )
  3133. {
  3134. var aSplit = sAttr.split('.');
  3135. nNewNode.id = aSplit[0].substr(1, aSplit[0].length-1);
  3136. nNewNode.className = aSplit[1];
  3137. }
  3138. else if ( sAttr.charAt(0) == "#" )
  3139. {
  3140. nNewNode.id = sAttr.substr(1, sAttr.length-1);
  3141. }
  3142. else
  3143. {
  3144. nNewNode.className = sAttr;
  3145. }
  3146. i += j; /* Move along the position array */
  3147. }
  3148. insert.append( nNewNode );
  3149. insert = $(nNewNode);
  3150. }
  3151. else if ( cOption == '>' )
  3152. {
  3153. /* End container div */
  3154. insert = insert.parent();
  3155. }
  3156. // @todo Move options into their own plugins?
  3157. else if ( cOption == 'l' && features.bPaginate && features.bLengthChange )
  3158. {
  3159. /* Length */
  3160. featureNode = _fnFeatureHtmlLength( oSettings );
  3161. }
  3162. else if ( cOption == 'f' && features.bFilter )
  3163. {
  3164. /* Filter */
  3165. featureNode = _fnFeatureHtmlFilter( oSettings );
  3166. }
  3167. else if ( cOption == 'r' && features.bProcessing )
  3168. {
  3169. /* pRocessing */
  3170. featureNode = _fnFeatureHtmlProcessing( oSettings );
  3171. }
  3172. else if ( cOption == 't' )
  3173. {
  3174. /* Table */
  3175. featureNode = _fnFeatureHtmlTable( oSettings );
  3176. }
  3177. else if ( cOption == 'i' && features.bInfo )
  3178. {
  3179. /* Info */
  3180. featureNode = _fnFeatureHtmlInfo( oSettings );
  3181. }
  3182. else if ( cOption == 'p' && features.bPaginate )
  3183. {
  3184. /* Pagination */
  3185. featureNode = _fnFeatureHtmlPaginate( oSettings );
  3186. }
  3187. else if ( DataTable.ext.feature.length !== 0 )
  3188. {
  3189. /* Plug-in features */
  3190. var aoFeatures = DataTable.ext.feature;
  3191. for ( var k=0, kLen=aoFeatures.length ; k<kLen ; k++ )
  3192. {
  3193. if ( cOption == aoFeatures[k].cFeature )
  3194. {
  3195. featureNode = aoFeatures[k].fnInit( oSettings );
  3196. break;
  3197. }
  3198. }
  3199. }
  3200. /* Add to the 2D features array */
  3201. if ( featureNode )
  3202. {
  3203. var aanFeatures = oSettings.aanFeatures;
  3204. if ( ! aanFeatures[cOption] )
  3205. {
  3206. aanFeatures[cOption] = [];
  3207. }
  3208. aanFeatures[cOption].push( featureNode );
  3209. insert.append( featureNode );
  3210. }
  3211. }
  3212. /* Built our DOM structure - replace the holding div with what we want */
  3213. holding.replaceWith( insert );
  3214. oSettings.nHolding = null;
  3215. }
  3216. /**
  3217. * Use the DOM source to create up an array of header cells. The idea here is to
  3218. * create a layout grid (array) of rows x columns, which contains a reference
  3219. * to the cell that that point in the grid (regardless of col/rowspan), such that
  3220. * any column / row could be removed and the new grid constructed
  3221. * @param array {object} aLayout Array to store the calculated layout in
  3222. * @param {node} nThead The header/footer element for the table
  3223. * @memberof DataTable#oApi
  3224. */
  3225. function _fnDetectHeader ( aLayout, nThead )
  3226. {
  3227. var nTrs = $(nThead).children('tr');
  3228. var nTr, nCell;
  3229. var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
  3230. var bUnique;
  3231. var fnShiftCol = function ( a, i, j ) {
  3232. var k = a[i];
  3233. while ( k[j] ) {
  3234. j++;
  3235. }
  3236. return j;
  3237. };
  3238. aLayout.splice( 0, aLayout.length );
  3239. /* We know how many rows there are in the layout - so prep it */
  3240. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3241. {
  3242. aLayout.push( [] );
  3243. }
  3244. /* Calculate a layout array */
  3245. for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
  3246. {
  3247. nTr = nTrs[i];
  3248. iColumn = 0;
  3249. /* For every cell in the row... */
  3250. nCell = nTr.firstChild;
  3251. while ( nCell ) {
  3252. if ( nCell.nodeName.toUpperCase() == "TD" ||
  3253. nCell.nodeName.toUpperCase() == "TH" )
  3254. {
  3255. /* Get the col and rowspan attributes from the DOM and sanitise them */
  3256. iColspan = nCell.getAttribute('colspan') * 1;
  3257. iRowspan = nCell.getAttribute('rowspan') * 1;
  3258. iColspan = (!iColspan || iColspan===0 || iColspan===1) ? 1 : iColspan;
  3259. iRowspan = (!iRowspan || iRowspan===0 || iRowspan===1) ? 1 : iRowspan;
  3260. /* There might be colspan cells already in this row, so shift our target
  3261. * accordingly
  3262. */
  3263. iColShifted = fnShiftCol( aLayout, i, iColumn );
  3264. /* Cache calculation for unique columns */
  3265. bUnique = iColspan === 1 ? true : false;
  3266. /* If there is col / rowspan, copy the information into the layout grid */
  3267. for ( l=0 ; l<iColspan ; l++ )
  3268. {
  3269. for ( k=0 ; k<iRowspan ; k++ )
  3270. {
  3271. aLayout[i+k][iColShifted+l] = {
  3272. "cell": nCell,
  3273. "unique": bUnique
  3274. };
  3275. aLayout[i+k].nTr = nTr;
  3276. }
  3277. }
  3278. }
  3279. nCell = nCell.nextSibling;
  3280. }
  3281. }
  3282. }
  3283. /**
  3284. * Get an array of unique th elements, one for each column
  3285. * @param {object} oSettings dataTables settings object
  3286. * @param {node} nHeader automatically detect the layout from this node - optional
  3287. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  3288. * @returns array {node} aReturn list of unique th's
  3289. * @memberof DataTable#oApi
  3290. */
  3291. function _fnGetUniqueThs ( oSettings, nHeader, aLayout )
  3292. {
  3293. var aReturn = [];
  3294. if ( !aLayout )
  3295. {
  3296. aLayout = oSettings.aoHeader;
  3297. if ( nHeader )
  3298. {
  3299. aLayout = [];
  3300. _fnDetectHeader( aLayout, nHeader );
  3301. }
  3302. }
  3303. for ( var i=0, iLen=aLayout.length ; i<iLen ; i++ )
  3304. {
  3305. for ( var j=0, jLen=aLayout[i].length ; j<jLen ; j++ )
  3306. {
  3307. if ( aLayout[i][j].unique &&
  3308. (!aReturn[j] || !oSettings.bSortCellsTop) )
  3309. {
  3310. aReturn[j] = aLayout[i][j].cell;
  3311. }
  3312. }
  3313. }
  3314. return aReturn;
  3315. }
  3316. /**
  3317. * Create an Ajax call based on the table's settings, taking into account that
  3318. * parameters can have multiple forms, and backwards compatibility.
  3319. *
  3320. * @param {object} oSettings dataTables settings object
  3321. * @param {array} data Data to send to the server, required by
  3322. * DataTables - may be augmented by developer callbacks
  3323. * @param {function} fn Callback function to run when data is obtained
  3324. */
  3325. function _fnBuildAjax( oSettings, data, fn )
  3326. {
  3327. // Compatibility with 1.9-, allow fnServerData and event to manipulate
  3328. _fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [data] );
  3329. // Convert to object based for 1.10+ if using the old array scheme which can
  3330. // come from server-side processing or serverParams
  3331. if ( data && $.isArray(data) ) {
  3332. var tmp = {};
  3333. var rbracket = /(.*?)\[\]$/;
  3334. $.each( data, function (key, val) {
  3335. var match = val.name.match(rbracket);
  3336. if ( match ) {
  3337. // Support for arrays
  3338. var name = match[0];
  3339. if ( ! tmp[ name ] ) {
  3340. tmp[ name ] = [];
  3341. }
  3342. tmp[ name ].push( val.value );
  3343. }
  3344. else {
  3345. tmp[val.name] = val.value;
  3346. }
  3347. } );
  3348. data = tmp;
  3349. }
  3350. var ajaxData;
  3351. var ajax = oSettings.ajax;
  3352. var instance = oSettings.oInstance;
  3353. var callback = function ( json ) {
  3354. _fnCallbackFire( oSettings, null, 'xhr', [oSettings, json, oSettings.jqXHR] );
  3355. fn( json );
  3356. };
  3357. if ( $.isPlainObject( ajax ) && ajax.data )
  3358. {
  3359. ajaxData = ajax.data;
  3360. var newData = typeof ajaxData === 'function' ?
  3361. ajaxData( data, oSettings ) : // fn can manipulate data or return
  3362. ajaxData; // an object object or array to merge
  3363. // If the function returned something, use that alone
  3364. data = typeof ajaxData === 'function' && newData ?
  3365. newData :
  3366. $.extend( true, data, newData );
  3367. // Remove the data property as we've resolved it already and don't want
  3368. // jQuery to do it again (it is restored at the end of the function)
  3369. delete ajax.data;
  3370. }
  3371. var baseAjax = {
  3372. "data": data,
  3373. "success": function (json) {
  3374. var error = json.error || json.sError;
  3375. if ( error ) {
  3376. _fnLog( oSettings, 0, error );
  3377. }
  3378. oSettings.json = json;
  3379. callback( json );
  3380. },
  3381. "dataType": "json",
  3382. "cache": false,
  3383. "type": oSettings.sServerMethod,
  3384. "error": function (xhr, error, thrown) {
  3385. var ret = _fnCallbackFire( oSettings, null, 'xhr', [oSettings, null, oSettings.jqXHR] );
  3386. if ( $.inArray( true, ret ) === -1 ) {
  3387. if ( error == "parsererror" ) {
  3388. _fnLog( oSettings, 0, 'Invalid JSON response', 1 );
  3389. }
  3390. else if ( xhr.readyState === 4 ) {
  3391. _fnLog( oSettings, 0, 'Ajax error', 7 );
  3392. }
  3393. }
  3394. _fnProcessingDisplay( oSettings, false );
  3395. }
  3396. };
  3397. // Store the data submitted for the API
  3398. oSettings.oAjaxData = data;
  3399. // Allow plug-ins and external processes to modify the data
  3400. _fnCallbackFire( oSettings, null, 'preXhr', [oSettings, data] );
  3401. if ( oSettings.fnServerData )
  3402. {
  3403. // DataTables 1.9- compatibility
  3404. oSettings.fnServerData.call( instance,
  3405. oSettings.sAjaxSource,
  3406. $.map( data, function (val, key) { // Need to convert back to 1.9 trad format
  3407. return { name: key, value: val };
  3408. } ),
  3409. callback,
  3410. oSettings
  3411. );
  3412. }
  3413. else if ( oSettings.sAjaxSource || typeof ajax === 'string' )
  3414. {
  3415. // DataTables 1.9- compatibility
  3416. oSettings.jqXHR = $.ajax( $.extend( baseAjax, {
  3417. url: ajax || oSettings.sAjaxSource
  3418. } ) );
  3419. }
  3420. else if ( typeof ajax === 'function' )
  3421. {
  3422. // Is a function - let the caller define what needs to be done
  3423. oSettings.jqXHR = ajax.call( instance, data, callback, oSettings );
  3424. }
  3425. else
  3426. {
  3427. // Object to extend the base settings
  3428. oSettings.jqXHR = $.ajax( $.extend( baseAjax, ajax ) );
  3429. // Restore for next time around
  3430. ajax.data = ajaxData;
  3431. }
  3432. }
  3433. /**
  3434. * Update the table using an Ajax call
  3435. * @param {object} settings dataTables settings object
  3436. * @returns {boolean} Block the table drawing or not
  3437. * @memberof DataTable#oApi
  3438. */
  3439. function _fnAjaxUpdate( settings )
  3440. {
  3441. if ( settings.bAjaxDataGet ) {
  3442. settings.iDraw++;
  3443. _fnProcessingDisplay( settings, true );
  3444. _fnBuildAjax(
  3445. settings,
  3446. _fnAjaxParameters( settings ),
  3447. function(json) {
  3448. _fnAjaxUpdateDraw( settings, json );
  3449. }
  3450. );
  3451. return false;
  3452. }
  3453. return true;
  3454. }
  3455. /**
  3456. * Build up the parameters in an object needed for a server-side processing
  3457. * request. Note that this is basically done twice, is different ways - a modern
  3458. * method which is used by default in DataTables 1.10 which uses objects and
  3459. * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
  3460. * the sAjaxSource option is used in the initialisation, or the legacyAjax
  3461. * option is set.
  3462. * @param {object} oSettings dataTables settings object
  3463. * @returns {bool} block the table drawing or not
  3464. * @memberof DataTable#oApi
  3465. */
  3466. function _fnAjaxParameters( settings )
  3467. {
  3468. var
  3469. columns = settings.aoColumns,
  3470. columnCount = columns.length,
  3471. features = settings.oFeatures,
  3472. preSearch = settings.oPreviousSearch,
  3473. preColSearch = settings.aoPreSearchCols,
  3474. i, data = [], dataProp, column, columnSearch,
  3475. sort = _fnSortFlatten( settings ),
  3476. displayStart = settings._iDisplayStart,
  3477. displayLength = features.bPaginate !== false ?
  3478. settings._iDisplayLength :
  3479. -1;
  3480. var param = function ( name, value ) {
  3481. data.push( { 'name': name, 'value': value } );
  3482. };
  3483. // DataTables 1.9- compatible method
  3484. param( 'sEcho', settings.iDraw );
  3485. param( 'iColumns', columnCount );
  3486. param( 'sColumns', _pluck( columns, 'sName' ).join(',') );
  3487. param( 'iDisplayStart', displayStart );
  3488. param( 'iDisplayLength', displayLength );
  3489. // DataTables 1.10+ method
  3490. var d = {
  3491. draw: settings.iDraw,
  3492. columns: [],
  3493. order: [],
  3494. start: displayStart,
  3495. length: displayLength,
  3496. search: {
  3497. value: preSearch.sSearch,
  3498. regex: preSearch.bRegex
  3499. }
  3500. };
  3501. for ( i=0 ; i<columnCount ; i++ ) {
  3502. column = columns[i];
  3503. columnSearch = preColSearch[i];
  3504. dataProp = typeof column.mData=="function" ? 'function' : column.mData ;
  3505. d.columns.push( {
  3506. data: dataProp,
  3507. name: column.sName,
  3508. searchable: column.bSearchable,
  3509. orderable: column.bSortable,
  3510. search: {
  3511. value: columnSearch.sSearch,
  3512. regex: columnSearch.bRegex
  3513. }
  3514. } );
  3515. param( "mDataProp_"+i, dataProp );
  3516. if ( features.bFilter ) {
  3517. param( 'sSearch_'+i, columnSearch.sSearch );
  3518. param( 'bRegex_'+i, columnSearch.bRegex );
  3519. param( 'bSearchable_'+i, column.bSearchable );
  3520. }
  3521. if ( features.bSort ) {
  3522. param( 'bSortable_'+i, column.bSortable );
  3523. }
  3524. }
  3525. if ( features.bFilter ) {
  3526. param( 'sSearch', preSearch.sSearch );
  3527. param( 'bRegex', preSearch.bRegex );
  3528. }
  3529. if ( features.bSort ) {
  3530. $.each( sort, function ( i, val ) {
  3531. d.order.push( { column: val.col, dir: val.dir } );
  3532. param( 'iSortCol_'+i, val.col );
  3533. param( 'sSortDir_'+i, val.dir );
  3534. } );
  3535. param( 'iSortingCols', sort.length );
  3536. }
  3537. // If the legacy.ajax parameter is null, then we automatically decide which
  3538. // form to use, based on sAjaxSource
  3539. var legacy = DataTable.ext.legacy.ajax;
  3540. if ( legacy === null ) {
  3541. return settings.sAjaxSource ? data : d;
  3542. }
  3543. // Otherwise, if legacy has been specified then we use that to decide on the
  3544. // form
  3545. return legacy ? data : d;
  3546. }
  3547. /**
  3548. * Data the data from the server (nuking the old) and redraw the table
  3549. * @param {object} oSettings dataTables settings object
  3550. * @param {object} json json data return from the server.
  3551. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  3552. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  3553. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  3554. * @param {array} json.aaData The data to display on this page
  3555. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  3556. * @memberof DataTable#oApi
  3557. */
  3558. function _fnAjaxUpdateDraw ( settings, json )
  3559. {
  3560. // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
  3561. // Support both
  3562. var compat = function ( old, modern ) {
  3563. return json[old] !== undefined ? json[old] : json[modern];
  3564. };
  3565. var data = _fnAjaxDataSrc( settings, json );
  3566. var draw = compat( 'sEcho', 'draw' );
  3567. var recordsTotal = compat( 'iTotalRecords', 'recordsTotal' );
  3568. var recordsFiltered = compat( 'iTotalDisplayRecords', 'recordsFiltered' );
  3569. if ( draw ) {
  3570. // Protect against out of sequence returns
  3571. if ( draw*1 < settings.iDraw ) {
  3572. return;
  3573. }
  3574. settings.iDraw = draw * 1;
  3575. }
  3576. _fnClearTable( settings );
  3577. settings._iRecordsTotal = parseInt(recordsTotal, 10);
  3578. settings._iRecordsDisplay = parseInt(recordsFiltered, 10);
  3579. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  3580. _fnAddData( settings, data[i] );
  3581. }
  3582. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3583. settings.bAjaxDataGet = false;
  3584. _fnDraw( settings );
  3585. if ( ! settings._bInitComplete ) {
  3586. _fnInitComplete( settings, json );
  3587. }
  3588. settings.bAjaxDataGet = true;
  3589. _fnProcessingDisplay( settings, false );
  3590. }
  3591. /**
  3592. * Get the data from the JSON data source to use for drawing a table. Using
  3593. * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
  3594. * source object, or from a processing function.
  3595. * @param {object} oSettings dataTables settings object
  3596. * @param {object} json Data source object / array from the server
  3597. * @return {array} Array of data to use
  3598. */
  3599. function _fnAjaxDataSrc ( oSettings, json )
  3600. {
  3601. var dataSrc = $.isPlainObject( oSettings.ajax ) && oSettings.ajax.dataSrc !== undefined ?
  3602. oSettings.ajax.dataSrc :
  3603. oSettings.sAjaxDataProp; // Compatibility with 1.9-.
  3604. // Compatibility with 1.9-. In order to read from aaData, check if the
  3605. // default has been changed, if not, check for aaData
  3606. if ( dataSrc === 'data' ) {
  3607. return json.aaData || json[dataSrc];
  3608. }
  3609. return dataSrc !== "" ?
  3610. _fnGetObjectDataFn( dataSrc )( json ) :
  3611. json;
  3612. }
  3613. /**
  3614. * Generate the node required for filtering text
  3615. * @returns {node} Filter control element
  3616. * @param {object} oSettings dataTables settings object
  3617. * @memberof DataTable#oApi
  3618. */
  3619. function _fnFeatureHtmlFilter ( settings )
  3620. {
  3621. var classes = settings.oClasses;
  3622. var tableId = settings.sTableId;
  3623. var language = settings.oLanguage;
  3624. var previousSearch = settings.oPreviousSearch;
  3625. var features = settings.aanFeatures;
  3626. var input = '<input type="search" class="'+classes.sFilterInput+'"/>';
  3627. var str = language.sSearch;
  3628. str = str.match(/_INPUT_/) ?
  3629. str.replace('_INPUT_', input) :
  3630. str+input;
  3631. var filter = $('<div/>', {
  3632. 'id': ! features.f ? tableId+'_filter' : null,
  3633. 'class': classes.sFilter
  3634. } )
  3635. .append( $('<label/>' ).append( str ) );
  3636. var searchFn = function() {
  3637. /* Update all other filter input elements for the new display */
  3638. var n = features.f;
  3639. var val = !this.value ? "" : this.value; // mental IE8 fix :-(
  3640. /* Now do the filter */
  3641. if ( val != previousSearch.sSearch ) {
  3642. _fnFilterComplete( settings, {
  3643. "sSearch": val,
  3644. "bRegex": previousSearch.bRegex,
  3645. "bSmart": previousSearch.bSmart ,
  3646. "bCaseInsensitive": previousSearch.bCaseInsensitive
  3647. } );
  3648. // Need to redraw, without resorting
  3649. settings._iDisplayStart = 0;
  3650. _fnDraw( settings );
  3651. }
  3652. };
  3653. var searchDelay = settings.searchDelay !== null ?
  3654. settings.searchDelay :
  3655. _fnDataSource( settings ) === 'ssp' ?
  3656. 400 :
  3657. 0;
  3658. var jqFilter = $('input', filter)
  3659. .val( previousSearch.sSearch )
  3660. .attr( 'placeholder', language.sSearchPlaceholder )
  3661. .on(
  3662. 'keyup.DT search.DT input.DT paste.DT cut.DT',
  3663. searchDelay ?
  3664. _fnThrottle( searchFn, searchDelay ) :
  3665. searchFn
  3666. )
  3667. .on( 'keypress.DT', function(e) {
  3668. /* Prevent form submission */
  3669. if ( e.keyCode == 13 ) {
  3670. return false;
  3671. }
  3672. } )
  3673. .attr('aria-controls', tableId);
  3674. // Update the input elements whenever the table is filtered
  3675. $(settings.nTable).on( 'search.dt.DT', function ( ev, s ) {
  3676. if ( settings === s ) {
  3677. // IE9 throws an 'unknown error' if document.activeElement is used
  3678. // inside an iframe or frame...
  3679. try {
  3680. if ( jqFilter[0] !== document.activeElement ) {
  3681. jqFilter.val( previousSearch.sSearch );
  3682. }
  3683. }
  3684. catch ( e ) {}
  3685. }
  3686. } );
  3687. return filter[0];
  3688. }
  3689. /**
  3690. * Filter the table using both the global filter and column based filtering
  3691. * @param {object} oSettings dataTables settings object
  3692. * @param {object} oSearch search information
  3693. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  3694. * @memberof DataTable#oApi
  3695. */
  3696. function _fnFilterComplete ( oSettings, oInput, iForce )
  3697. {
  3698. var oPrevSearch = oSettings.oPreviousSearch;
  3699. var aoPrevSearch = oSettings.aoPreSearchCols;
  3700. var fnSaveFilter = function ( oFilter ) {
  3701. /* Save the filtering values */
  3702. oPrevSearch.sSearch = oFilter.sSearch;
  3703. oPrevSearch.bRegex = oFilter.bRegex;
  3704. oPrevSearch.bSmart = oFilter.bSmart;
  3705. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  3706. };
  3707. var fnRegex = function ( o ) {
  3708. // Backwards compatibility with the bEscapeRegex option
  3709. return o.bEscapeRegex !== undefined ? !o.bEscapeRegex : o.bRegex;
  3710. };
  3711. // Resolve any column types that are unknown due to addition or invalidation
  3712. // @todo As per sort - can this be moved into an event handler?
  3713. _fnColumnTypes( oSettings );
  3714. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  3715. if ( _fnDataSource( oSettings ) != 'ssp' )
  3716. {
  3717. /* Global filter */
  3718. _fnFilter( oSettings, oInput.sSearch, iForce, fnRegex(oInput), oInput.bSmart, oInput.bCaseInsensitive );
  3719. fnSaveFilter( oInput );
  3720. /* Now do the individual column filter */
  3721. for ( var i=0 ; i<aoPrevSearch.length ; i++ )
  3722. {
  3723. _fnFilterColumn( oSettings, aoPrevSearch[i].sSearch, i, fnRegex(aoPrevSearch[i]),
  3724. aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive );
  3725. }
  3726. /* Custom filtering */
  3727. _fnFilterCustom( oSettings );
  3728. }
  3729. else
  3730. {
  3731. fnSaveFilter( oInput );
  3732. }
  3733. /* Tell the draw function we have been filtering */
  3734. oSettings.bFiltered = true;
  3735. _fnCallbackFire( oSettings, null, 'search', [oSettings] );
  3736. }
  3737. /**
  3738. * Apply custom filtering functions
  3739. * @param {object} oSettings dataTables settings object
  3740. * @memberof DataTable#oApi
  3741. */
  3742. function _fnFilterCustom( settings )
  3743. {
  3744. var filters = DataTable.ext.search;
  3745. var displayRows = settings.aiDisplay;
  3746. var row, rowIdx;
  3747. for ( var i=0, ien=filters.length ; i<ien ; i++ ) {
  3748. var rows = [];
  3749. // Loop over each row and see if it should be included
  3750. for ( var j=0, jen=displayRows.length ; j<jen ; j++ ) {
  3751. rowIdx = displayRows[ j ];
  3752. row = settings.aoData[ rowIdx ];
  3753. if ( filters[i]( settings, row._aFilterData, rowIdx, row._aData, j ) ) {
  3754. rows.push( rowIdx );
  3755. }
  3756. }
  3757. // So the array reference doesn't break set the results into the
  3758. // existing array
  3759. displayRows.length = 0;
  3760. $.merge( displayRows, rows );
  3761. }
  3762. }
  3763. /**
  3764. * Filter the table on a per-column basis
  3765. * @param {object} oSettings dataTables settings object
  3766. * @param {string} sInput string to filter on
  3767. * @param {int} iColumn column to filter
  3768. * @param {bool} bRegex treat search string as a regular expression or not
  3769. * @param {bool} bSmart use smart filtering or not
  3770. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  3771. * @memberof DataTable#oApi
  3772. */
  3773. function _fnFilterColumn ( settings, searchStr, colIdx, regex, smart, caseInsensitive )
  3774. {
  3775. if ( searchStr === '' ) {
  3776. return;
  3777. }
  3778. var data;
  3779. var out = [];
  3780. var display = settings.aiDisplay;
  3781. var rpSearch = _fnFilterCreateSearch( searchStr, regex, smart, caseInsensitive );
  3782. for ( var i=0 ; i<display.length ; i++ ) {
  3783. data = settings.aoData[ display[i] ]._aFilterData[ colIdx ];
  3784. if ( rpSearch.test( data ) ) {
  3785. out.push( display[i] );
  3786. }
  3787. }
  3788. settings.aiDisplay = out;
  3789. }
  3790. /**
  3791. * Filter the data table based on user input and draw the table
  3792. * @param {object} settings dataTables settings object
  3793. * @param {string} input string to filter on
  3794. * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
  3795. * @param {bool} regex treat as a regular expression or not
  3796. * @param {bool} smart perform smart filtering or not
  3797. * @param {bool} caseInsensitive Do case insenstive matching or not
  3798. * @memberof DataTable#oApi
  3799. */
  3800. function _fnFilter( settings, input, force, regex, smart, caseInsensitive )
  3801. {
  3802. var rpSearch = _fnFilterCreateSearch( input, regex, smart, caseInsensitive );
  3803. var prevSearch = settings.oPreviousSearch.sSearch;
  3804. var displayMaster = settings.aiDisplayMaster;
  3805. var display, invalidated, i;
  3806. var filtered = [];
  3807. // Need to take account of custom filtering functions - always filter
  3808. if ( DataTable.ext.search.length !== 0 ) {
  3809. force = true;
  3810. }
  3811. // Check if any of the rows were invalidated
  3812. invalidated = _fnFilterData( settings );
  3813. // If the input is blank - we just want the full data set
  3814. if ( input.length <= 0 ) {
  3815. settings.aiDisplay = displayMaster.slice();
  3816. }
  3817. else {
  3818. // New search - start from the master array
  3819. if ( invalidated ||
  3820. force ||
  3821. prevSearch.length > input.length ||
  3822. input.indexOf(prevSearch) !== 0 ||
  3823. settings.bSorted // On resort, the display master needs to be
  3824. // re-filtered since indexes will have changed
  3825. ) {
  3826. settings.aiDisplay = displayMaster.slice();
  3827. }
  3828. // Search the display array
  3829. display = settings.aiDisplay;
  3830. for ( i=0 ; i<display.length ; i++ ) {
  3831. if ( rpSearch.test( settings.aoData[ display[i] ]._sFilterRow ) ) {
  3832. filtered.push( display[i] );
  3833. }
  3834. }
  3835. settings.aiDisplay = filtered;
  3836. }
  3837. }
  3838. /**
  3839. * Build a regular expression object suitable for searching a table
  3840. * @param {string} sSearch string to search for
  3841. * @param {bool} bRegex treat as a regular expression or not
  3842. * @param {bool} bSmart perform smart filtering or not
  3843. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3844. * @returns {RegExp} constructed object
  3845. * @memberof DataTable#oApi
  3846. */
  3847. function _fnFilterCreateSearch( search, regex, smart, caseInsensitive )
  3848. {
  3849. search = regex ?
  3850. search :
  3851. _fnEscapeRegex( search );
  3852. if ( smart ) {
  3853. /* For smart filtering we want to allow the search to work regardless of
  3854. * word order. We also want double quoted text to be preserved, so word
  3855. * order is important - a la google. So this is what we want to
  3856. * generate:
  3857. *
  3858. * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
  3859. */
  3860. var a = $.map( search.match( /"[^"]+"|[^ ]+/g ) || [''], function ( word ) {
  3861. if ( word.charAt(0) === '"' ) {
  3862. var m = word.match( /^"(.*)"$/ );
  3863. word = m ? m[1] : word;
  3864. }
  3865. return word.replace('"', '');
  3866. } );
  3867. search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$';
  3868. }
  3869. return new RegExp( search, caseInsensitive ? 'i' : '' );
  3870. }
  3871. /**
  3872. * Escape a string such that it can be used in a regular expression
  3873. * @param {string} sVal string to escape
  3874. * @returns {string} escaped string
  3875. * @memberof DataTable#oApi
  3876. */
  3877. var _fnEscapeRegex = DataTable.util.escapeRegex;
  3878. var __filter_div = $('<div>')[0];
  3879. var __filter_div_textContent = __filter_div.textContent !== undefined;
  3880. // Update the filtering data for each row if needed (by invalidation or first run)
  3881. function _fnFilterData ( settings )
  3882. {
  3883. var columns = settings.aoColumns;
  3884. var column;
  3885. var i, j, ien, jen, filterData, cellData, row;
  3886. var fomatters = DataTable.ext.type.search;
  3887. var wasInvalidated = false;
  3888. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  3889. row = settings.aoData[i];
  3890. if ( ! row._aFilterData ) {
  3891. filterData = [];
  3892. for ( j=0, jen=columns.length ; j<jen ; j++ ) {
  3893. column = columns[j];
  3894. if ( column.bSearchable ) {
  3895. cellData = _fnGetCellData( settings, i, j, 'filter' );
  3896. if ( fomatters[ column.sType ] ) {
  3897. cellData = fomatters[ column.sType ]( cellData );
  3898. }
  3899. // Search in DataTables 1.10 is string based. In 1.11 this
  3900. // should be altered to also allow strict type checking.
  3901. if ( cellData === null ) {
  3902. cellData = '';
  3903. }
  3904. if ( typeof cellData !== 'string' && cellData.toString ) {
  3905. cellData = cellData.toString();
  3906. }
  3907. }
  3908. else {
  3909. cellData = '';
  3910. }
  3911. // If it looks like there is an HTML entity in the string,
  3912. // attempt to decode it so sorting works as expected. Note that
  3913. // we could use a single line of jQuery to do this, but the DOM
  3914. // method used here is much faster http://jsperf.com/html-decode
  3915. if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) {
  3916. __filter_div.innerHTML = cellData;
  3917. cellData = __filter_div_textContent ?
  3918. __filter_div.textContent :
  3919. __filter_div.innerText;
  3920. }
  3921. if ( cellData.replace ) {
  3922. cellData = cellData.replace(/[\r\n]/g, '');
  3923. }
  3924. filterData.push( cellData );
  3925. }
  3926. row._aFilterData = filterData;
  3927. row._sFilterRow = filterData.join(' ');
  3928. wasInvalidated = true;
  3929. }
  3930. }
  3931. return wasInvalidated;
  3932. }
  3933. /**
  3934. * Convert from the internal Hungarian notation to camelCase for external
  3935. * interaction
  3936. * @param {object} obj Object to convert
  3937. * @returns {object} Inverted object
  3938. * @memberof DataTable#oApi
  3939. */
  3940. function _fnSearchToCamel ( obj )
  3941. {
  3942. return {
  3943. search: obj.sSearch,
  3944. smart: obj.bSmart,
  3945. regex: obj.bRegex,
  3946. caseInsensitive: obj.bCaseInsensitive
  3947. };
  3948. }
  3949. /**
  3950. * Convert from camelCase notation to the internal Hungarian. We could use the
  3951. * Hungarian convert function here, but this is cleaner
  3952. * @param {object} obj Object to convert
  3953. * @returns {object} Inverted object
  3954. * @memberof DataTable#oApi
  3955. */
  3956. function _fnSearchToHung ( obj )
  3957. {
  3958. return {
  3959. sSearch: obj.search,
  3960. bSmart: obj.smart,
  3961. bRegex: obj.regex,
  3962. bCaseInsensitive: obj.caseInsensitive
  3963. };
  3964. }
  3965. /**
  3966. * Generate the node required for the info display
  3967. * @param {object} oSettings dataTables settings object
  3968. * @returns {node} Information element
  3969. * @memberof DataTable#oApi
  3970. */
  3971. function _fnFeatureHtmlInfo ( settings )
  3972. {
  3973. var
  3974. tid = settings.sTableId,
  3975. nodes = settings.aanFeatures.i,
  3976. n = $('<div/>', {
  3977. 'class': settings.oClasses.sInfo,
  3978. 'id': ! nodes ? tid+'_info' : null
  3979. } );
  3980. if ( ! nodes ) {
  3981. // Update display on each draw
  3982. settings.aoDrawCallback.push( {
  3983. "fn": _fnUpdateInfo,
  3984. "sName": "information"
  3985. } );
  3986. n
  3987. .attr( 'role', 'status' )
  3988. .attr( 'aria-live', 'polite' );
  3989. // Table is described by our info div
  3990. $(settings.nTable).attr( 'aria-describedby', tid+'_info' );
  3991. }
  3992. return n[0];
  3993. }
  3994. /**
  3995. * Update the information elements in the display
  3996. * @param {object} settings dataTables settings object
  3997. * @memberof DataTable#oApi
  3998. */
  3999. function _fnUpdateInfo ( settings )
  4000. {
  4001. /* Show information about the table */
  4002. var nodes = settings.aanFeatures.i;
  4003. if ( nodes.length === 0 ) {
  4004. return;
  4005. }
  4006. var
  4007. lang = settings.oLanguage,
  4008. start = settings._iDisplayStart+1,
  4009. end = settings.fnDisplayEnd(),
  4010. max = settings.fnRecordsTotal(),
  4011. total = settings.fnRecordsDisplay(),
  4012. out = total ?
  4013. lang.sInfo :
  4014. lang.sInfoEmpty;
  4015. if ( total !== max ) {
  4016. /* Record set after filtering */
  4017. out += ' ' + lang.sInfoFiltered;
  4018. }
  4019. // Convert the macros
  4020. out += lang.sInfoPostFix;
  4021. out = _fnInfoMacros( settings, out );
  4022. var callback = lang.fnInfoCallback;
  4023. if ( callback !== null ) {
  4024. out = callback.call( settings.oInstance,
  4025. settings, start, end, max, total, out
  4026. );
  4027. }
  4028. $(nodes).html( out );
  4029. }
  4030. function _fnInfoMacros ( settings, str )
  4031. {
  4032. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  4033. // internally
  4034. var
  4035. formatter = settings.fnFormatNumber,
  4036. start = settings._iDisplayStart+1,
  4037. len = settings._iDisplayLength,
  4038. vis = settings.fnRecordsDisplay(),
  4039. all = len === -1;
  4040. return str.
  4041. replace(/_START_/g, formatter.call( settings, start ) ).
  4042. replace(/_END_/g, formatter.call( settings, settings.fnDisplayEnd() ) ).
  4043. replace(/_MAX_/g, formatter.call( settings, settings.fnRecordsTotal() ) ).
  4044. replace(/_TOTAL_/g, formatter.call( settings, vis ) ).
  4045. replace(/_PAGE_/g, formatter.call( settings, all ? 1 : Math.ceil( start / len ) ) ).
  4046. replace(/_PAGES_/g, formatter.call( settings, all ? 1 : Math.ceil( vis / len ) ) );
  4047. }
  4048. /**
  4049. * Draw the table for the first time, adding all required features
  4050. * @param {object} settings dataTables settings object
  4051. * @memberof DataTable#oApi
  4052. */
  4053. function _fnInitialise ( settings )
  4054. {
  4055. var i, iLen, iAjaxStart=settings.iInitDisplayStart;
  4056. var columns = settings.aoColumns, column;
  4057. var features = settings.oFeatures;
  4058. var deferLoading = settings.bDeferLoading; // value modified by the draw
  4059. /* Ensure that the table data is fully initialised */
  4060. if ( ! settings.bInitialised ) {
  4061. setTimeout( function(){ _fnInitialise( settings ); }, 200 );
  4062. return;
  4063. }
  4064. /* Show the display HTML options */
  4065. _fnAddOptionsHtml( settings );
  4066. /* Build and draw the header / footer for the table */
  4067. _fnBuildHead( settings );
  4068. _fnDrawHead( settings, settings.aoHeader );
  4069. _fnDrawHead( settings, settings.aoFooter );
  4070. /* Okay to show that something is going on now */
  4071. _fnProcessingDisplay( settings, true );
  4072. /* Calculate sizes for columns */
  4073. if ( features.bAutoWidth ) {
  4074. _fnCalculateColumnWidths( settings );
  4075. }
  4076. for ( i=0, iLen=columns.length ; i<iLen ; i++ ) {
  4077. column = columns[i];
  4078. if ( column.sWidth ) {
  4079. column.nTh.style.width = _fnStringToCss( column.sWidth );
  4080. }
  4081. }
  4082. _fnCallbackFire( settings, null, 'preInit', [settings] );
  4083. // If there is default sorting required - let's do it. The sort function
  4084. // will do the drawing for us. Otherwise we draw the table regardless of the
  4085. // Ajax source - this allows the table to look initialised for Ajax sourcing
  4086. // data (show 'loading' message possibly)
  4087. _fnReDraw( settings );
  4088. // Server-side processing init complete is done by _fnAjaxUpdateDraw
  4089. var dataSrc = _fnDataSource( settings );
  4090. if ( dataSrc != 'ssp' || deferLoading ) {
  4091. // if there is an ajax source load the data
  4092. if ( dataSrc == 'ajax' ) {
  4093. _fnBuildAjax( settings, [], function(json) {
  4094. var aData = _fnAjaxDataSrc( settings, json );
  4095. // Got the data - add it to the table
  4096. for ( i=0 ; i<aData.length ; i++ ) {
  4097. _fnAddData( settings, aData[i] );
  4098. }
  4099. // Reset the init display for cookie saving. We've already done
  4100. // a filter, and therefore cleared it before. So we need to make
  4101. // it appear 'fresh'
  4102. settings.iInitDisplayStart = iAjaxStart;
  4103. _fnReDraw( settings );
  4104. _fnProcessingDisplay( settings, false );
  4105. _fnInitComplete( settings, json );
  4106. }, settings );
  4107. }
  4108. else {
  4109. _fnProcessingDisplay( settings, false );
  4110. _fnInitComplete( settings );
  4111. }
  4112. }
  4113. }
  4114. /**
  4115. * Draw the table for the first time, adding all required features
  4116. * @param {object} oSettings dataTables settings object
  4117. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  4118. * with client-side processing (optional)
  4119. * @memberof DataTable#oApi
  4120. */
  4121. function _fnInitComplete ( settings, json )
  4122. {
  4123. settings._bInitComplete = true;
  4124. // When data was added after the initialisation (data or Ajax) we need to
  4125. // calculate the column sizing
  4126. if ( json || settings.oInit.aaData ) {
  4127. _fnAdjustColumnSizing( settings );
  4128. }
  4129. _fnCallbackFire( settings, null, 'plugin-init', [settings, json] );
  4130. _fnCallbackFire( settings, 'aoInitComplete', 'init', [settings, json] );
  4131. }
  4132. function _fnLengthChange ( settings, val )
  4133. {
  4134. var len = parseInt( val, 10 );
  4135. settings._iDisplayLength = len;
  4136. _fnLengthOverflow( settings );
  4137. // Fire length change event
  4138. _fnCallbackFire( settings, null, 'length', [settings, len] );
  4139. }
  4140. /**
  4141. * Generate the node required for user display length changing
  4142. * @param {object} settings dataTables settings object
  4143. * @returns {node} Display length feature node
  4144. * @memberof DataTable#oApi
  4145. */
  4146. function _fnFeatureHtmlLength ( settings )
  4147. {
  4148. var
  4149. classes = settings.oClasses,
  4150. tableId = settings.sTableId,
  4151. menu = settings.aLengthMenu,
  4152. d2 = $.isArray( menu[0] ),
  4153. lengths = d2 ? menu[0] : menu,
  4154. language = d2 ? menu[1] : menu;
  4155. var select = $('<select/>', {
  4156. 'name': tableId+'_length',
  4157. 'aria-controls': tableId,
  4158. 'class': classes.sLengthSelect
  4159. } );
  4160. for ( var i=0, ien=lengths.length ; i<ien ; i++ ) {
  4161. select[0][ i ] = new Option(
  4162. typeof language[i] === 'number' ?
  4163. settings.fnFormatNumber( language[i] ) :
  4164. language[i],
  4165. lengths[i]
  4166. );
  4167. }
  4168. var div = $('<div><label/></div>').addClass( classes.sLength );
  4169. if ( ! settings.aanFeatures.l ) {
  4170. div[0].id = tableId+'_length';
  4171. }
  4172. div.children().append(
  4173. settings.oLanguage.sLengthMenu.replace( '_MENU_', select[0].outerHTML )
  4174. );
  4175. // Can't use `select` variable as user might provide their own and the
  4176. // reference is broken by the use of outerHTML
  4177. $('select', div)
  4178. .val( settings._iDisplayLength )
  4179. .on( 'change.DT', function(e) {
  4180. _fnLengthChange( settings, $(this).val() );
  4181. _fnDraw( settings );
  4182. } );
  4183. // Update node value whenever anything changes the table's length
  4184. $(settings.nTable).on( 'length.dt.DT', function (e, s, len) {
  4185. if ( settings === s ) {
  4186. $('select', div).val( len );
  4187. }
  4188. } );
  4189. return div[0];
  4190. }
  4191. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4192. * Note that most of the paging logic is done in
  4193. * DataTable.ext.pager
  4194. */
  4195. /**
  4196. * Generate the node required for default pagination
  4197. * @param {object} oSettings dataTables settings object
  4198. * @returns {node} Pagination feature node
  4199. * @memberof DataTable#oApi
  4200. */
  4201. function _fnFeatureHtmlPaginate ( settings )
  4202. {
  4203. var
  4204. type = settings.sPaginationType,
  4205. plugin = DataTable.ext.pager[ type ],
  4206. modern = typeof plugin === 'function',
  4207. redraw = function( settings ) {
  4208. _fnDraw( settings );
  4209. },
  4210. node = $('<div/>').addClass( settings.oClasses.sPaging + type )[0],
  4211. features = settings.aanFeatures;
  4212. if ( ! modern ) {
  4213. plugin.fnInit( settings, node, redraw );
  4214. }
  4215. /* Add a draw callback for the pagination on first instance, to update the paging display */
  4216. if ( ! features.p )
  4217. {
  4218. node.id = settings.sTableId+'_paginate';
  4219. settings.aoDrawCallback.push( {
  4220. "fn": function( settings ) {
  4221. if ( modern ) {
  4222. var
  4223. start = settings._iDisplayStart,
  4224. len = settings._iDisplayLength,
  4225. visRecords = settings.fnRecordsDisplay(),
  4226. all = len === -1,
  4227. page = all ? 0 : Math.ceil( start / len ),
  4228. pages = all ? 1 : Math.ceil( visRecords / len ),
  4229. buttons = plugin(page, pages),
  4230. i, ien;
  4231. for ( i=0, ien=features.p.length ; i<ien ; i++ ) {
  4232. _fnRenderer( settings, 'pageButton' )(
  4233. settings, features.p[i], i, buttons, page, pages
  4234. );
  4235. }
  4236. }
  4237. else {
  4238. plugin.fnUpdate( settings, redraw );
  4239. }
  4240. },
  4241. "sName": "pagination"
  4242. } );
  4243. }
  4244. return node;
  4245. }
  4246. /**
  4247. * Alter the display settings to change the page
  4248. * @param {object} settings DataTables settings object
  4249. * @param {string|int} action Paging action to take: "first", "previous",
  4250. * "next" or "last" or page number to jump to (integer)
  4251. * @param [bool] redraw Automatically draw the update or not
  4252. * @returns {bool} true page has changed, false - no change
  4253. * @memberof DataTable#oApi
  4254. */
  4255. function _fnPageChange ( settings, action, redraw )
  4256. {
  4257. var
  4258. start = settings._iDisplayStart,
  4259. len = settings._iDisplayLength,
  4260. records = settings.fnRecordsDisplay();
  4261. if ( records === 0 || len === -1 )
  4262. {
  4263. start = 0;
  4264. }
  4265. else if ( typeof action === "number" )
  4266. {
  4267. start = action * len;
  4268. if ( start > records )
  4269. {
  4270. start = 0;
  4271. }
  4272. }
  4273. else if ( action == "first" )
  4274. {
  4275. start = 0;
  4276. }
  4277. else if ( action == "previous" )
  4278. {
  4279. start = len >= 0 ?
  4280. start - len :
  4281. 0;
  4282. if ( start < 0 )
  4283. {
  4284. start = 0;
  4285. }
  4286. }
  4287. else if ( action == "next" )
  4288. {
  4289. if ( start + len < records )
  4290. {
  4291. start += len;
  4292. }
  4293. }
  4294. else if ( action == "last" )
  4295. {
  4296. start = Math.floor( (records-1) / len) * len;
  4297. }
  4298. else
  4299. {
  4300. _fnLog( settings, 0, "Unknown paging action: "+action, 5 );
  4301. }
  4302. var changed = settings._iDisplayStart !== start;
  4303. settings._iDisplayStart = start;
  4304. if ( changed ) {
  4305. _fnCallbackFire( settings, null, 'page', [settings] );
  4306. if ( redraw ) {
  4307. _fnDraw( settings );
  4308. }
  4309. }
  4310. return changed;
  4311. }
  4312. /**
  4313. * Generate the node required for the processing node
  4314. * @param {object} settings dataTables settings object
  4315. * @returns {node} Processing element
  4316. * @memberof DataTable#oApi
  4317. */
  4318. function _fnFeatureHtmlProcessing ( settings )
  4319. {
  4320. return $('<div/>', {
  4321. 'id': ! settings.aanFeatures.r ? settings.sTableId+'_processing' : null,
  4322. 'class': settings.oClasses.sProcessing
  4323. } )
  4324. .html( settings.oLanguage.sProcessing )
  4325. .insertBefore( settings.nTable )[0];
  4326. }
  4327. /**
  4328. * Display or hide the processing indicator
  4329. * @param {object} settings dataTables settings object
  4330. * @param {bool} show Show the processing indicator (true) or not (false)
  4331. * @memberof DataTable#oApi
  4332. */
  4333. function _fnProcessingDisplay ( settings, show )
  4334. {
  4335. if ( settings.oFeatures.bProcessing ) {
  4336. $(settings.aanFeatures.r).css( 'display', show ? 'block' : 'none' );
  4337. }
  4338. _fnCallbackFire( settings, null, 'processing', [settings, show] );
  4339. }
  4340. /**
  4341. * Add any control elements for the table - specifically scrolling
  4342. * @param {object} settings dataTables settings object
  4343. * @returns {node} Node to add to the DOM
  4344. * @memberof DataTable#oApi
  4345. */
  4346. function _fnFeatureHtmlTable ( settings )
  4347. {
  4348. var table = $(settings.nTable);
  4349. // Add the ARIA grid role to the table
  4350. table.attr( 'role', 'grid' );
  4351. // Scrolling from here on in
  4352. var scroll = settings.oScroll;
  4353. if ( scroll.sX === '' && scroll.sY === '' ) {
  4354. return settings.nTable;
  4355. }
  4356. var scrollX = scroll.sX;
  4357. var scrollY = scroll.sY;
  4358. var classes = settings.oClasses;
  4359. var caption = table.children('caption');
  4360. var captionSide = caption.length ? caption[0]._captionSide : null;
  4361. var headerClone = $( table[0].cloneNode(false) );
  4362. var footerClone = $( table[0].cloneNode(false) );
  4363. var footer = table.children('tfoot');
  4364. var _div = '<div/>';
  4365. var size = function ( s ) {
  4366. return !s ? null : _fnStringToCss( s );
  4367. };
  4368. if ( ! footer.length ) {
  4369. footer = null;
  4370. }
  4371. /*
  4372. * The HTML structure that we want to generate in this function is:
  4373. * div - scroller
  4374. * div - scroll head
  4375. * div - scroll head inner
  4376. * table - scroll head table
  4377. * thead - thead
  4378. * div - scroll body
  4379. * table - table (master table)
  4380. * thead - thead clone for sizing
  4381. * tbody - tbody
  4382. * div - scroll foot
  4383. * div - scroll foot inner
  4384. * table - scroll foot table
  4385. * tfoot - tfoot
  4386. */
  4387. var scroller = $( _div, { 'class': classes.sScrollWrapper } )
  4388. .append(
  4389. $(_div, { 'class': classes.sScrollHead } )
  4390. .css( {
  4391. overflow: 'hidden',
  4392. position: 'relative',
  4393. border: 0,
  4394. width: scrollX ? size(scrollX) : '100%'
  4395. } )
  4396. .append(
  4397. $(_div, { 'class': classes.sScrollHeadInner } )
  4398. .css( {
  4399. 'box-sizing': 'content-box',
  4400. width: scroll.sXInner || '100%'
  4401. } )
  4402. .append(
  4403. headerClone
  4404. .removeAttr('id')
  4405. .css( 'margin-left', 0 )
  4406. .append( captionSide === 'top' ? caption : null )
  4407. .append(
  4408. table.children('thead')
  4409. )
  4410. )
  4411. )
  4412. )
  4413. .append(
  4414. $(_div, { 'class': classes.sScrollBody } )
  4415. .css( {
  4416. position: 'relative',
  4417. overflow: 'auto',
  4418. width: size( scrollX )
  4419. } )
  4420. .append( table )
  4421. );
  4422. if ( footer ) {
  4423. scroller.append(
  4424. $(_div, { 'class': classes.sScrollFoot } )
  4425. .css( {
  4426. overflow: 'hidden',
  4427. border: 0,
  4428. width: scrollX ? size(scrollX) : '100%'
  4429. } )
  4430. .append(
  4431. $(_div, { 'class': classes.sScrollFootInner } )
  4432. .append(
  4433. footerClone
  4434. .removeAttr('id')
  4435. .css( 'margin-left', 0 )
  4436. .append( captionSide === 'bottom' ? caption : null )
  4437. .append(
  4438. table.children('tfoot')
  4439. )
  4440. )
  4441. )
  4442. );
  4443. }
  4444. var children = scroller.children();
  4445. var scrollHead = children[0];
  4446. var scrollBody = children[1];
  4447. var scrollFoot = footer ? children[2] : null;
  4448. // When the body is scrolled, then we also want to scroll the headers
  4449. if ( scrollX ) {
  4450. $(scrollBody).on( 'scroll.DT', function (e) {
  4451. var scrollLeft = this.scrollLeft;
  4452. scrollHead.scrollLeft = scrollLeft;
  4453. if ( footer ) {
  4454. scrollFoot.scrollLeft = scrollLeft;
  4455. }
  4456. } );
  4457. }
  4458. $(scrollBody).css(
  4459. scrollY && scroll.bCollapse ? 'max-height' : 'height',
  4460. scrollY
  4461. );
  4462. settings.nScrollHead = scrollHead;
  4463. settings.nScrollBody = scrollBody;
  4464. settings.nScrollFoot = scrollFoot;
  4465. // On redraw - align columns
  4466. settings.aoDrawCallback.push( {
  4467. "fn": _fnScrollDraw,
  4468. "sName": "scrolling"
  4469. } );
  4470. return scroller[0];
  4471. }
  4472. /**
  4473. * Update the header, footer and body tables for resizing - i.e. column
  4474. * alignment.
  4475. *
  4476. * Welcome to the most horrible function DataTables. The process that this
  4477. * function follows is basically:
  4478. * 1. Re-create the table inside the scrolling div
  4479. * 2. Take live measurements from the DOM
  4480. * 3. Apply the measurements to align the columns
  4481. * 4. Clean up
  4482. *
  4483. * @param {object} settings dataTables settings object
  4484. * @memberof DataTable#oApi
  4485. */
  4486. function _fnScrollDraw ( settings )
  4487. {
  4488. // Given that this is such a monster function, a lot of variables are use
  4489. // to try and keep the minimised size as small as possible
  4490. var
  4491. scroll = settings.oScroll,
  4492. scrollX = scroll.sX,
  4493. scrollXInner = scroll.sXInner,
  4494. scrollY = scroll.sY,
  4495. barWidth = scroll.iBarWidth,
  4496. divHeader = $(settings.nScrollHead),
  4497. divHeaderStyle = divHeader[0].style,
  4498. divHeaderInner = divHeader.children('div'),
  4499. divHeaderInnerStyle = divHeaderInner[0].style,
  4500. divHeaderTable = divHeaderInner.children('table'),
  4501. divBodyEl = settings.nScrollBody,
  4502. divBody = $(divBodyEl),
  4503. divBodyStyle = divBodyEl.style,
  4504. divFooter = $(settings.nScrollFoot),
  4505. divFooterInner = divFooter.children('div'),
  4506. divFooterTable = divFooterInner.children('table'),
  4507. header = $(settings.nTHead),
  4508. table = $(settings.nTable),
  4509. tableEl = table[0],
  4510. tableStyle = tableEl.style,
  4511. footer = settings.nTFoot ? $(settings.nTFoot) : null,
  4512. browser = settings.oBrowser,
  4513. ie67 = browser.bScrollOversize,
  4514. dtHeaderCells = _pluck( settings.aoColumns, 'nTh' ),
  4515. headerTrgEls, footerTrgEls,
  4516. headerSrcEls, footerSrcEls,
  4517. headerCopy, footerCopy,
  4518. headerWidths=[], footerWidths=[],
  4519. headerContent=[], footerContent=[],
  4520. idx, correction, sanityWidth,
  4521. zeroOut = function(nSizer) {
  4522. var style = nSizer.style;
  4523. style.paddingTop = "0";
  4524. style.paddingBottom = "0";
  4525. style.borderTopWidth = "0";
  4526. style.borderBottomWidth = "0";
  4527. style.height = 0;
  4528. };
  4529. // If the scrollbar visibility has changed from the last draw, we need to
  4530. // adjust the column sizes as the table width will have changed to account
  4531. // for the scrollbar
  4532. var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
  4533. if ( settings.scrollBarVis !== scrollBarVis && settings.scrollBarVis !== undefined ) {
  4534. settings.scrollBarVis = scrollBarVis;
  4535. _fnAdjustColumnSizing( settings );
  4536. return; // adjust column sizing will call this function again
  4537. }
  4538. else {
  4539. settings.scrollBarVis = scrollBarVis;
  4540. }
  4541. /*
  4542. * 1. Re-create the table inside the scrolling div
  4543. */
  4544. // Remove the old minimised thead and tfoot elements in the inner table
  4545. table.children('thead, tfoot').remove();
  4546. if ( footer ) {
  4547. footerCopy = footer.clone().prependTo( table );
  4548. footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized
  4549. footerSrcEls = footerCopy.find('tr');
  4550. }
  4551. // Clone the current header and footer elements and then place it into the inner table
  4552. headerCopy = header.clone().prependTo( table );
  4553. headerTrgEls = header.find('tr'); // original header is in its own table
  4554. headerSrcEls = headerCopy.find('tr');
  4555. headerCopy.find('th, td').removeAttr('tabindex');
  4556. /*
  4557. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  4558. */
  4559. // Remove old sizing and apply the calculated column widths
  4560. // Get the unique column headers in the newly created (cloned) header. We want to apply the
  4561. // calculated sizes to this header
  4562. if ( ! scrollX )
  4563. {
  4564. divBodyStyle.width = '100%';
  4565. divHeader[0].style.width = '100%';
  4566. }
  4567. $.each( _fnGetUniqueThs( settings, headerCopy ), function ( i, el ) {
  4568. idx = _fnVisibleToColumnIndex( settings, i );
  4569. el.style.width = settings.aoColumns[idx].sWidth;
  4570. } );
  4571. if ( footer ) {
  4572. _fnApplyToChildren( function(n) {
  4573. n.style.width = "";
  4574. }, footerSrcEls );
  4575. }
  4576. // Size the table as a whole
  4577. sanityWidth = table.outerWidth();
  4578. if ( scrollX === "" ) {
  4579. // No x scrolling
  4580. tableStyle.width = "100%";
  4581. // IE7 will make the width of the table when 100% include the scrollbar
  4582. // - which is shouldn't. When there is a scrollbar we need to take this
  4583. // into account.
  4584. if ( ie67 && (table.find('tbody').height() > divBodyEl.offsetHeight ||
  4585. divBody.css('overflow-y') == "scroll")
  4586. ) {
  4587. tableStyle.width = _fnStringToCss( table.outerWidth() - barWidth);
  4588. }
  4589. // Recalculate the sanity width
  4590. sanityWidth = table.outerWidth();
  4591. }
  4592. else if ( scrollXInner !== "" ) {
  4593. // legacy x scroll inner has been given - use it
  4594. tableStyle.width = _fnStringToCss(scrollXInner);
  4595. // Recalculate the sanity width
  4596. sanityWidth = table.outerWidth();
  4597. }
  4598. // Hidden header should have zero height, so remove padding and borders. Then
  4599. // set the width based on the real headers
  4600. // Apply all styles in one pass
  4601. _fnApplyToChildren( zeroOut, headerSrcEls );
  4602. // Read all widths in next pass
  4603. _fnApplyToChildren( function(nSizer) {
  4604. headerContent.push( nSizer.innerHTML );
  4605. headerWidths.push( _fnStringToCss( $(nSizer).css('width') ) );
  4606. }, headerSrcEls );
  4607. // Apply all widths in final pass
  4608. _fnApplyToChildren( function(nToSize, i) {
  4609. // Only apply widths to the DataTables detected header cells - this
  4610. // prevents complex headers from having contradictory sizes applied
  4611. if ( $.inArray( nToSize, dtHeaderCells ) !== -1 ) {
  4612. nToSize.style.width = headerWidths[i];
  4613. }
  4614. }, headerTrgEls );
  4615. $(headerSrcEls).height(0);
  4616. /* Same again with the footer if we have one */
  4617. if ( footer )
  4618. {
  4619. _fnApplyToChildren( zeroOut, footerSrcEls );
  4620. _fnApplyToChildren( function(nSizer) {
  4621. footerContent.push( nSizer.innerHTML );
  4622. footerWidths.push( _fnStringToCss( $(nSizer).css('width') ) );
  4623. }, footerSrcEls );
  4624. _fnApplyToChildren( function(nToSize, i) {
  4625. nToSize.style.width = footerWidths[i];
  4626. }, footerTrgEls );
  4627. $(footerSrcEls).height(0);
  4628. }
  4629. /*
  4630. * 3. Apply the measurements
  4631. */
  4632. // "Hide" the header and footer that we used for the sizing. We need to keep
  4633. // the content of the cell so that the width applied to the header and body
  4634. // both match, but we want to hide it completely. We want to also fix their
  4635. // width to what they currently are
  4636. _fnApplyToChildren( function(nSizer, i) {
  4637. nSizer.innerHTML = '<div class="dataTables_sizing">'+headerContent[i]+'</div>';
  4638. nSizer.childNodes[0].style.height = "0";
  4639. nSizer.childNodes[0].style.overflow = "hidden";
  4640. nSizer.style.width = headerWidths[i];
  4641. }, headerSrcEls );
  4642. if ( footer )
  4643. {
  4644. _fnApplyToChildren( function(nSizer, i) {
  4645. nSizer.innerHTML = '<div class="dataTables_sizing">'+footerContent[i]+'</div>';
  4646. nSizer.childNodes[0].style.height = "0";
  4647. nSizer.childNodes[0].style.overflow = "hidden";
  4648. nSizer.style.width = footerWidths[i];
  4649. }, footerSrcEls );
  4650. }
  4651. // Sanity check that the table is of a sensible width. If not then we are going to get
  4652. // misalignment - try to prevent this by not allowing the table to shrink below its min width
  4653. if ( table.outerWidth() < sanityWidth )
  4654. {
  4655. // The min width depends upon if we have a vertical scrollbar visible or not */
  4656. correction = ((divBodyEl.scrollHeight > divBodyEl.offsetHeight ||
  4657. divBody.css('overflow-y') == "scroll")) ?
  4658. sanityWidth+barWidth :
  4659. sanityWidth;
  4660. // IE6/7 are a law unto themselves...
  4661. if ( ie67 && (divBodyEl.scrollHeight >
  4662. divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")
  4663. ) {
  4664. tableStyle.width = _fnStringToCss( correction-barWidth );
  4665. }
  4666. // And give the user a warning that we've stopped the table getting too small
  4667. if ( scrollX === "" || scrollXInner !== "" ) {
  4668. _fnLog( settings, 1, 'Possible column misalignment', 6 );
  4669. }
  4670. }
  4671. else
  4672. {
  4673. correction = '100%';
  4674. }
  4675. // Apply to the container elements
  4676. divBodyStyle.width = _fnStringToCss( correction );
  4677. divHeaderStyle.width = _fnStringToCss( correction );
  4678. if ( footer ) {
  4679. settings.nScrollFoot.style.width = _fnStringToCss( correction );
  4680. }
  4681. /*
  4682. * 4. Clean up
  4683. */
  4684. if ( ! scrollY ) {
  4685. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  4686. * the scrollbar height from the visible display, rather than adding it on. We need to
  4687. * set the height in order to sort this. Don't want to do it in any other browsers.
  4688. */
  4689. if ( ie67 ) {
  4690. divBodyStyle.height = _fnStringToCss( tableEl.offsetHeight+barWidth );
  4691. }
  4692. }
  4693. /* Finally set the width's of the header and footer tables */
  4694. var iOuterWidth = table.outerWidth();
  4695. divHeaderTable[0].style.width = _fnStringToCss( iOuterWidth );
  4696. divHeaderInnerStyle.width = _fnStringToCss( iOuterWidth );
  4697. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  4698. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  4699. var bScrolling = table.height() > divBodyEl.clientHeight || divBody.css('overflow-y') == "scroll";
  4700. var padding = 'padding' + (browser.bScrollbarLeft ? 'Left' : 'Right' );
  4701. divHeaderInnerStyle[ padding ] = bScrolling ? barWidth+"px" : "0px";
  4702. if ( footer ) {
  4703. divFooterTable[0].style.width = _fnStringToCss( iOuterWidth );
  4704. divFooterInner[0].style.width = _fnStringToCss( iOuterWidth );
  4705. divFooterInner[0].style[padding] = bScrolling ? barWidth+"px" : "0px";
  4706. }
  4707. // Correct DOM ordering for colgroup - comes before the thead
  4708. table.children('colgroup').insertBefore( table.children('thead') );
  4709. /* Adjust the position of the header in case we loose the y-scrollbar */
  4710. divBody.scroll();
  4711. // If sorting or filtering has occurred, jump the scrolling back to the top
  4712. // only if we aren't holding the position
  4713. if ( (settings.bSorted || settings.bFiltered) && ! settings._drawHold ) {
  4714. divBodyEl.scrollTop = 0;
  4715. }
  4716. }
  4717. /**
  4718. * Apply a given function to the display child nodes of an element array (typically
  4719. * TD children of TR rows
  4720. * @param {function} fn Method to apply to the objects
  4721. * @param array {nodes} an1 List of elements to look through for display children
  4722. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  4723. * @memberof DataTable#oApi
  4724. */
  4725. function _fnApplyToChildren( fn, an1, an2 )
  4726. {
  4727. var index=0, i=0, iLen=an1.length;
  4728. var nNode1, nNode2;
  4729. while ( i < iLen ) {
  4730. nNode1 = an1[i].firstChild;
  4731. nNode2 = an2 ? an2[i].firstChild : null;
  4732. while ( nNode1 ) {
  4733. if ( nNode1.nodeType === 1 ) {
  4734. if ( an2 ) {
  4735. fn( nNode1, nNode2, index );
  4736. }
  4737. else {
  4738. fn( nNode1, index );
  4739. }
  4740. index++;
  4741. }
  4742. nNode1 = nNode1.nextSibling;
  4743. nNode2 = an2 ? nNode2.nextSibling : null;
  4744. }
  4745. i++;
  4746. }
  4747. }
  4748. var __re_html_remove = /<.*?>/g;
  4749. /**
  4750. * Calculate the width of columns for the table
  4751. * @param {object} oSettings dataTables settings object
  4752. * @memberof DataTable#oApi
  4753. */
  4754. function _fnCalculateColumnWidths ( oSettings )
  4755. {
  4756. var
  4757. table = oSettings.nTable,
  4758. columns = oSettings.aoColumns,
  4759. scroll = oSettings.oScroll,
  4760. scrollY = scroll.sY,
  4761. scrollX = scroll.sX,
  4762. scrollXInner = scroll.sXInner,
  4763. columnCount = columns.length,
  4764. visibleColumns = _fnGetColumns( oSettings, 'bVisible' ),
  4765. headerCells = $('th', oSettings.nTHead),
  4766. tableWidthAttr = table.getAttribute('width'), // from DOM element
  4767. tableContainer = table.parentNode,
  4768. userInputs = false,
  4769. i, column, columnIdx, width, outerWidth,
  4770. browser = oSettings.oBrowser,
  4771. ie67 = browser.bScrollOversize;
  4772. var styleWidth = table.style.width;
  4773. if ( styleWidth && styleWidth.indexOf('%') !== -1 ) {
  4774. tableWidthAttr = styleWidth;
  4775. }
  4776. /* Convert any user input sizes into pixel sizes */
  4777. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4778. column = columns[ visibleColumns[i] ];
  4779. if ( column.sWidth !== null ) {
  4780. column.sWidth = _fnConvertToWidth( column.sWidthOrig, tableContainer );
  4781. userInputs = true;
  4782. }
  4783. }
  4784. /* If the number of columns in the DOM equals the number that we have to
  4785. * process in DataTables, then we can use the offsets that are created by
  4786. * the web- browser. No custom sizes can be set in order for this to happen,
  4787. * nor scrolling used
  4788. */
  4789. if ( ie67 || ! userInputs && ! scrollX && ! scrollY &&
  4790. columnCount == _fnVisbleColumns( oSettings ) &&
  4791. columnCount == headerCells.length
  4792. ) {
  4793. for ( i=0 ; i<columnCount ; i++ ) {
  4794. var colIdx = _fnVisibleToColumnIndex( oSettings, i );
  4795. if ( colIdx !== null ) {
  4796. columns[ colIdx ].sWidth = _fnStringToCss( headerCells.eq(i).width() );
  4797. }
  4798. }
  4799. }
  4800. else
  4801. {
  4802. // Otherwise construct a single row, worst case, table with the widest
  4803. // node in the data, assign any user defined widths, then insert it into
  4804. // the DOM and allow the browser to do all the hard work of calculating
  4805. // table widths
  4806. var tmpTable = $(table).clone() // don't use cloneNode - IE8 will remove events on the main table
  4807. .css( 'visibility', 'hidden' )
  4808. .removeAttr( 'id' );
  4809. // Clean up the table body
  4810. tmpTable.find('tbody tr').remove();
  4811. var tr = $('<tr/>').appendTo( tmpTable.find('tbody') );
  4812. // Clone the table header and footer - we can't use the header / footer
  4813. // from the cloned table, since if scrolling is active, the table's
  4814. // real header and footer are contained in different table tags
  4815. tmpTable.find('thead, tfoot').remove();
  4816. tmpTable
  4817. .append( $(oSettings.nTHead).clone() )
  4818. .append( $(oSettings.nTFoot).clone() );
  4819. // Remove any assigned widths from the footer (from scrolling)
  4820. tmpTable.find('tfoot th, tfoot td').css('width', '');
  4821. // Apply custom sizing to the cloned header
  4822. headerCells = _fnGetUniqueThs( oSettings, tmpTable.find('thead')[0] );
  4823. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4824. column = columns[ visibleColumns[i] ];
  4825. headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ?
  4826. _fnStringToCss( column.sWidthOrig ) :
  4827. '';
  4828. // For scrollX we need to force the column width otherwise the
  4829. // browser will collapse it. If this width is smaller than the
  4830. // width the column requires, then it will have no effect
  4831. if ( column.sWidthOrig && scrollX ) {
  4832. $( headerCells[i] ).append( $('<div/>').css( {
  4833. width: column.sWidthOrig,
  4834. margin: 0,
  4835. padding: 0,
  4836. border: 0,
  4837. height: 1
  4838. } ) );
  4839. }
  4840. }
  4841. // Find the widest cell for each column and put it into the table
  4842. if ( oSettings.aoData.length ) {
  4843. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4844. columnIdx = visibleColumns[i];
  4845. column = columns[ columnIdx ];
  4846. $( _fnGetWidestNode( oSettings, columnIdx ) )
  4847. .clone( false )
  4848. .append( column.sContentPadding )
  4849. .appendTo( tr );
  4850. }
  4851. }
  4852. // Tidy the temporary table - remove name attributes so there aren't
  4853. // duplicated in the dom (radio elements for example)
  4854. $('[name]', tmpTable).removeAttr('name');
  4855. // Table has been built, attach to the document so we can work with it.
  4856. // A holding element is used, positioned at the top of the container
  4857. // with minimal height, so it has no effect on if the container scrolls
  4858. // or not. Otherwise it might trigger scrolling when it actually isn't
  4859. // needed
  4860. var holder = $('<div/>').css( scrollX || scrollY ?
  4861. {
  4862. position: 'absolute',
  4863. top: 0,
  4864. left: 0,
  4865. height: 1,
  4866. right: 0,
  4867. overflow: 'hidden'
  4868. } :
  4869. {}
  4870. )
  4871. .append( tmpTable )
  4872. .appendTo( tableContainer );
  4873. // When scrolling (X or Y) we want to set the width of the table as
  4874. // appropriate. However, when not scrolling leave the table width as it
  4875. // is. This results in slightly different, but I think correct behaviour
  4876. if ( scrollX && scrollXInner ) {
  4877. tmpTable.width( scrollXInner );
  4878. }
  4879. else if ( scrollX ) {
  4880. tmpTable.css( 'width', 'auto' );
  4881. tmpTable.removeAttr('width');
  4882. // If there is no width attribute or style, then allow the table to
  4883. // collapse
  4884. if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) {
  4885. tmpTable.width( tableContainer.clientWidth );
  4886. }
  4887. }
  4888. else if ( scrollY ) {
  4889. tmpTable.width( tableContainer.clientWidth );
  4890. }
  4891. else if ( tableWidthAttr ) {
  4892. tmpTable.width( tableWidthAttr );
  4893. }
  4894. // Get the width of each column in the constructed table - we need to
  4895. // know the inner width (so it can be assigned to the other table's
  4896. // cells) and the outer width so we can calculate the full width of the
  4897. // table. This is safe since DataTables requires a unique cell for each
  4898. // column, but if ever a header can span multiple columns, this will
  4899. // need to be modified.
  4900. var total = 0;
  4901. for ( i=0 ; i<visibleColumns.length ; i++ ) {
  4902. var cell = $(headerCells[i]);
  4903. var border = cell.outerWidth() - cell.width();
  4904. // Use getBounding... where possible (not IE8-) because it can give
  4905. // sub-pixel accuracy, which we then want to round up!
  4906. var bounding = browser.bBounding ?
  4907. Math.ceil( headerCells[i].getBoundingClientRect().width ) :
  4908. cell.outerWidth();
  4909. // Total is tracked to remove any sub-pixel errors as the outerWidth
  4910. // of the table might not equal the total given here (IE!).
  4911. total += bounding;
  4912. // Width for each column to use
  4913. columns[ visibleColumns[i] ].sWidth = _fnStringToCss( bounding - border );
  4914. }
  4915. table.style.width = _fnStringToCss( total );
  4916. // Finished with the table - ditch it
  4917. holder.remove();
  4918. }
  4919. // If there is a width attr, we want to attach an event listener which
  4920. // allows the table sizing to automatically adjust when the window is
  4921. // resized. Use the width attr rather than CSS, since we can't know if the
  4922. // CSS is a relative value or absolute - DOM read is always px.
  4923. if ( tableWidthAttr ) {
  4924. table.style.width = _fnStringToCss( tableWidthAttr );
  4925. }
  4926. if ( (tableWidthAttr || scrollX) && ! oSettings._reszEvt ) {
  4927. var bindResize = function () {
  4928. $(window).on('resize.DT-'+oSettings.sInstance, _fnThrottle( function () {
  4929. _fnAdjustColumnSizing( oSettings );
  4930. } ) );
  4931. };
  4932. // IE6/7 will crash if we bind a resize event handler on page load.
  4933. // To be removed in 1.11 which drops IE6/7 support
  4934. if ( ie67 ) {
  4935. setTimeout( bindResize, 1000 );
  4936. }
  4937. else {
  4938. bindResize();
  4939. }
  4940. oSettings._reszEvt = true;
  4941. }
  4942. }
  4943. /**
  4944. * Throttle the calls to a function. Arguments and context are maintained for
  4945. * the throttled function
  4946. * @param {function} fn Function to be called
  4947. * @param {int} [freq=200] call frequency in mS
  4948. * @returns {function} wrapped function
  4949. * @memberof DataTable#oApi
  4950. */
  4951. var _fnThrottle = DataTable.util.throttle;
  4952. /**
  4953. * Convert a CSS unit width to pixels (e.g. 2em)
  4954. * @param {string} width width to be converted
  4955. * @param {node} parent parent to get the with for (required for relative widths) - optional
  4956. * @returns {int} width in pixels
  4957. * @memberof DataTable#oApi
  4958. */
  4959. function _fnConvertToWidth ( width, parent )
  4960. {
  4961. if ( ! width ) {
  4962. return 0;
  4963. }
  4964. var n = $('<div/>')
  4965. .css( 'width', _fnStringToCss( width ) )
  4966. .appendTo( parent || document.body );
  4967. var val = n[0].offsetWidth;
  4968. n.remove();
  4969. return val;
  4970. }
  4971. /**
  4972. * Get the widest node
  4973. * @param {object} settings dataTables settings object
  4974. * @param {int} colIdx column of interest
  4975. * @returns {node} widest table node
  4976. * @memberof DataTable#oApi
  4977. */
  4978. function _fnGetWidestNode( settings, colIdx )
  4979. {
  4980. var idx = _fnGetMaxLenString( settings, colIdx );
  4981. if ( idx < 0 ) {
  4982. return null;
  4983. }
  4984. var data = settings.aoData[ idx ];
  4985. return ! data.nTr ? // Might not have been created when deferred rendering
  4986. $('<td/>').html( _fnGetCellData( settings, idx, colIdx, 'display' ) )[0] :
  4987. data.anCells[ colIdx ];
  4988. }
  4989. /**
  4990. * Get the maximum strlen for each data column
  4991. * @param {object} settings dataTables settings object
  4992. * @param {int} colIdx column of interest
  4993. * @returns {string} max string length for each column
  4994. * @memberof DataTable#oApi
  4995. */
  4996. function _fnGetMaxLenString( settings, colIdx )
  4997. {
  4998. var s, max=-1, maxIdx = -1;
  4999. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5000. s = _fnGetCellData( settings, i, colIdx, 'display' )+'';
  5001. s = s.replace( __re_html_remove, '' );
  5002. s = s.replace( /&nbsp;/g, ' ' );
  5003. if ( s.length > max ) {
  5004. max = s.length;
  5005. maxIdx = i;
  5006. }
  5007. }
  5008. return maxIdx;
  5009. }
  5010. /**
  5011. * Append a CSS unit (only if required) to a string
  5012. * @param {string} value to css-ify
  5013. * @returns {string} value with css unit
  5014. * @memberof DataTable#oApi
  5015. */
  5016. function _fnStringToCss( s )
  5017. {
  5018. if ( s === null ) {
  5019. return '0px';
  5020. }
  5021. if ( typeof s == 'number' ) {
  5022. return s < 0 ?
  5023. '0px' :
  5024. s+'px';
  5025. }
  5026. // Check it has a unit character already
  5027. return s.match(/\d$/) ?
  5028. s+'px' :
  5029. s;
  5030. }
  5031. function _fnSortFlatten ( settings )
  5032. {
  5033. var
  5034. i, iLen, k, kLen,
  5035. aSort = [],
  5036. aiOrig = [],
  5037. aoColumns = settings.aoColumns,
  5038. aDataSort, iCol, sType, srcCol,
  5039. fixed = settings.aaSortingFixed,
  5040. fixedObj = $.isPlainObject( fixed ),
  5041. nestedSort = [],
  5042. add = function ( a ) {
  5043. if ( a.length && ! $.isArray( a[0] ) ) {
  5044. // 1D array
  5045. nestedSort.push( a );
  5046. }
  5047. else {
  5048. // 2D array
  5049. $.merge( nestedSort, a );
  5050. }
  5051. };
  5052. // Build the sort array, with pre-fix and post-fix options if they have been
  5053. // specified
  5054. if ( $.isArray( fixed ) ) {
  5055. add( fixed );
  5056. }
  5057. if ( fixedObj && fixed.pre ) {
  5058. add( fixed.pre );
  5059. }
  5060. add( settings.aaSorting );
  5061. if (fixedObj && fixed.post ) {
  5062. add( fixed.post );
  5063. }
  5064. for ( i=0 ; i<nestedSort.length ; i++ )
  5065. {
  5066. srcCol = nestedSort[i][0];
  5067. aDataSort = aoColumns[ srcCol ].aDataSort;
  5068. for ( k=0, kLen=aDataSort.length ; k<kLen ; k++ )
  5069. {
  5070. iCol = aDataSort[k];
  5071. sType = aoColumns[ iCol ].sType || 'string';
  5072. if ( nestedSort[i]._idx === undefined ) {
  5073. nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting );
  5074. }
  5075. aSort.push( {
  5076. src: srcCol,
  5077. col: iCol,
  5078. dir: nestedSort[i][1],
  5079. index: nestedSort[i]._idx,
  5080. type: sType,
  5081. formatter: DataTable.ext.type.order[ sType+"-pre" ]
  5082. } );
  5083. }
  5084. }
  5085. return aSort;
  5086. }
  5087. /**
  5088. * Change the order of the table
  5089. * @param {object} oSettings dataTables settings object
  5090. * @memberof DataTable#oApi
  5091. * @todo This really needs split up!
  5092. */
  5093. function _fnSort ( oSettings )
  5094. {
  5095. var
  5096. i, ien, iLen, j, jLen, k, kLen,
  5097. sDataType, nTh,
  5098. aiOrig = [],
  5099. oExtSort = DataTable.ext.type.order,
  5100. aoData = oSettings.aoData,
  5101. aoColumns = oSettings.aoColumns,
  5102. aDataSort, data, iCol, sType, oSort,
  5103. formatters = 0,
  5104. sortCol,
  5105. displayMaster = oSettings.aiDisplayMaster,
  5106. aSort;
  5107. // Resolve any column types that are unknown due to addition or invalidation
  5108. // @todo Can this be moved into a 'data-ready' handler which is called when
  5109. // data is going to be used in the table?
  5110. _fnColumnTypes( oSettings );
  5111. aSort = _fnSortFlatten( oSettings );
  5112. for ( i=0, ien=aSort.length ; i<ien ; i++ ) {
  5113. sortCol = aSort[i];
  5114. // Track if we can use the fast sort algorithm
  5115. if ( sortCol.formatter ) {
  5116. formatters++;
  5117. }
  5118. // Load the data needed for the sort, for each cell
  5119. _fnSortData( oSettings, sortCol.col );
  5120. }
  5121. /* No sorting required if server-side or no sorting array */
  5122. if ( _fnDataSource( oSettings ) != 'ssp' && aSort.length !== 0 )
  5123. {
  5124. // Create a value - key array of the current row positions such that we can use their
  5125. // current position during the sort, if values match, in order to perform stable sorting
  5126. for ( i=0, iLen=displayMaster.length ; i<iLen ; i++ ) {
  5127. aiOrig[ displayMaster[i] ] = i;
  5128. }
  5129. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  5130. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  5131. * follow on it's own, but this is what we want (example two column sorting):
  5132. * fnLocalSorting = function(a,b){
  5133. * var iTest;
  5134. * iTest = oSort['string-asc']('data11', 'data12');
  5135. * if (iTest !== 0)
  5136. * return iTest;
  5137. * iTest = oSort['numeric-desc']('data21', 'data22');
  5138. * if (iTest !== 0)
  5139. * return iTest;
  5140. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  5141. * }
  5142. * Basically we have a test for each sorting column, if the data in that column is equal,
  5143. * test the next column. If all columns match, then we use a numeric sort on the row
  5144. * positions in the original data array to provide a stable sort.
  5145. *
  5146. * Note - I know it seems excessive to have two sorting methods, but the first is around
  5147. * 15% faster, so the second is only maintained for backwards compatibility with sorting
  5148. * methods which do not have a pre-sort formatting function.
  5149. */
  5150. if ( formatters === aSort.length ) {
  5151. // All sort types have formatting functions
  5152. displayMaster.sort( function ( a, b ) {
  5153. var
  5154. x, y, k, test, sort,
  5155. len=aSort.length,
  5156. dataA = aoData[a]._aSortData,
  5157. dataB = aoData[b]._aSortData;
  5158. for ( k=0 ; k<len ; k++ ) {
  5159. sort = aSort[k];
  5160. x = dataA[ sort.col ];
  5161. y = dataB[ sort.col ];
  5162. test = x<y ? -1 : x>y ? 1 : 0;
  5163. if ( test !== 0 ) {
  5164. return sort.dir === 'asc' ? test : -test;
  5165. }
  5166. }
  5167. x = aiOrig[a];
  5168. y = aiOrig[b];
  5169. return x<y ? -1 : x>y ? 1 : 0;
  5170. } );
  5171. }
  5172. else {
  5173. // Depreciated - remove in 1.11 (providing a plug-in option)
  5174. // Not all sort types have formatting methods, so we have to call their sorting
  5175. // methods.
  5176. displayMaster.sort( function ( a, b ) {
  5177. var
  5178. x, y, k, l, test, sort, fn,
  5179. len=aSort.length,
  5180. dataA = aoData[a]._aSortData,
  5181. dataB = aoData[b]._aSortData;
  5182. for ( k=0 ; k<len ; k++ ) {
  5183. sort = aSort[k];
  5184. x = dataA[ sort.col ];
  5185. y = dataB[ sort.col ];
  5186. fn = oExtSort[ sort.type+"-"+sort.dir ] || oExtSort[ "string-"+sort.dir ];
  5187. test = fn( x, y );
  5188. if ( test !== 0 ) {
  5189. return test;
  5190. }
  5191. }
  5192. x = aiOrig[a];
  5193. y = aiOrig[b];
  5194. return x<y ? -1 : x>y ? 1 : 0;
  5195. } );
  5196. }
  5197. }
  5198. /* Tell the draw function that we have sorted the data */
  5199. oSettings.bSorted = true;
  5200. }
  5201. function _fnSortAria ( settings )
  5202. {
  5203. var label;
  5204. var nextSort;
  5205. var columns = settings.aoColumns;
  5206. var aSort = _fnSortFlatten( settings );
  5207. var oAria = settings.oLanguage.oAria;
  5208. // ARIA attributes - need to loop all columns, to update all (removing old
  5209. // attributes as needed)
  5210. for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
  5211. {
  5212. var col = columns[i];
  5213. var asSorting = col.asSorting;
  5214. var sTitle = col.sTitle.replace( /<.*?>/g, "" );
  5215. var th = col.nTh;
  5216. // IE7 is throwing an error when setting these properties with jQuery's
  5217. // attr() and removeAttr() methods...
  5218. th.removeAttribute('aria-sort');
  5219. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  5220. if ( col.bSortable ) {
  5221. if ( aSort.length > 0 && aSort[0].col == i ) {
  5222. th.setAttribute('aria-sort', aSort[0].dir=="asc" ? "ascending" : "descending" );
  5223. nextSort = asSorting[ aSort[0].index+1 ] || asSorting[0];
  5224. }
  5225. else {
  5226. nextSort = asSorting[0];
  5227. }
  5228. label = sTitle + ( nextSort === "asc" ?
  5229. oAria.sSortAscending :
  5230. oAria.sSortDescending
  5231. );
  5232. }
  5233. else {
  5234. label = sTitle;
  5235. }
  5236. th.setAttribute('aria-label', label);
  5237. }
  5238. }
  5239. /**
  5240. * Function to run on user sort request
  5241. * @param {object} settings dataTables settings object
  5242. * @param {node} attachTo node to attach the handler to
  5243. * @param {int} colIdx column sorting index
  5244. * @param {boolean} [append=false] Append the requested sort to the existing
  5245. * sort if true (i.e. multi-column sort)
  5246. * @param {function} [callback] callback function
  5247. * @memberof DataTable#oApi
  5248. */
  5249. function _fnSortListener ( settings, colIdx, append, callback )
  5250. {
  5251. var col = settings.aoColumns[ colIdx ];
  5252. var sorting = settings.aaSorting;
  5253. var asSorting = col.asSorting;
  5254. var nextSortIdx;
  5255. var next = function ( a, overflow ) {
  5256. var idx = a._idx;
  5257. if ( idx === undefined ) {
  5258. idx = $.inArray( a[1], asSorting );
  5259. }
  5260. return idx+1 < asSorting.length ?
  5261. idx+1 :
  5262. overflow ?
  5263. null :
  5264. 0;
  5265. };
  5266. // Convert to 2D array if needed
  5267. if ( typeof sorting[0] === 'number' ) {
  5268. sorting = settings.aaSorting = [ sorting ];
  5269. }
  5270. // If appending the sort then we are multi-column sorting
  5271. if ( append && settings.oFeatures.bSortMulti ) {
  5272. // Are we already doing some kind of sort on this column?
  5273. var sortIdx = $.inArray( colIdx, _pluck(sorting, '0') );
  5274. if ( sortIdx !== -1 ) {
  5275. // Yes, modify the sort
  5276. nextSortIdx = next( sorting[sortIdx], true );
  5277. if ( nextSortIdx === null && sorting.length === 1 ) {
  5278. nextSortIdx = 0; // can't remove sorting completely
  5279. }
  5280. if ( nextSortIdx === null ) {
  5281. sorting.splice( sortIdx, 1 );
  5282. }
  5283. else {
  5284. sorting[sortIdx][1] = asSorting[ nextSortIdx ];
  5285. sorting[sortIdx]._idx = nextSortIdx;
  5286. }
  5287. }
  5288. else {
  5289. // No sort on this column yet
  5290. sorting.push( [ colIdx, asSorting[0], 0 ] );
  5291. sorting[sorting.length-1]._idx = 0;
  5292. }
  5293. }
  5294. else if ( sorting.length && sorting[0][0] == colIdx ) {
  5295. // Single column - already sorting on this column, modify the sort
  5296. nextSortIdx = next( sorting[0] );
  5297. sorting.length = 1;
  5298. sorting[0][1] = asSorting[ nextSortIdx ];
  5299. sorting[0]._idx = nextSortIdx;
  5300. }
  5301. else {
  5302. // Single column - sort only on this column
  5303. sorting.length = 0;
  5304. sorting.push( [ colIdx, asSorting[0] ] );
  5305. sorting[0]._idx = 0;
  5306. }
  5307. // Run the sort by calling a full redraw
  5308. _fnReDraw( settings );
  5309. // callback used for async user interaction
  5310. if ( typeof callback == 'function' ) {
  5311. callback( settings );
  5312. }
  5313. }
  5314. /**
  5315. * Attach a sort handler (click) to a node
  5316. * @param {object} settings dataTables settings object
  5317. * @param {node} attachTo node to attach the handler to
  5318. * @param {int} colIdx column sorting index
  5319. * @param {function} [callback] callback function
  5320. * @memberof DataTable#oApi
  5321. */
  5322. function _fnSortAttachListener ( settings, attachTo, colIdx, callback )
  5323. {
  5324. var col = settings.aoColumns[ colIdx ];
  5325. _fnBindAction( attachTo, {}, function (e) {
  5326. /* If the column is not sortable - don't to anything */
  5327. if ( col.bSortable === false ) {
  5328. return;
  5329. }
  5330. // If processing is enabled use a timeout to allow the processing
  5331. // display to be shown - otherwise to it synchronously
  5332. if ( settings.oFeatures.bProcessing ) {
  5333. _fnProcessingDisplay( settings, true );
  5334. setTimeout( function() {
  5335. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5336. // In server-side processing, the draw callback will remove the
  5337. // processing display
  5338. if ( _fnDataSource( settings ) !== 'ssp' ) {
  5339. _fnProcessingDisplay( settings, false );
  5340. }
  5341. }, 0 );
  5342. }
  5343. else {
  5344. _fnSortListener( settings, colIdx, e.shiftKey, callback );
  5345. }
  5346. } );
  5347. }
  5348. /**
  5349. * Set the sorting classes on table's body, Note: it is safe to call this function
  5350. * when bSort and bSortClasses are false
  5351. * @param {object} oSettings dataTables settings object
  5352. * @memberof DataTable#oApi
  5353. */
  5354. function _fnSortingClasses( settings )
  5355. {
  5356. var oldSort = settings.aLastSort;
  5357. var sortClass = settings.oClasses.sSortColumn;
  5358. var sort = _fnSortFlatten( settings );
  5359. var features = settings.oFeatures;
  5360. var i, ien, colIdx;
  5361. if ( features.bSort && features.bSortClasses ) {
  5362. // Remove old sorting classes
  5363. for ( i=0, ien=oldSort.length ; i<ien ; i++ ) {
  5364. colIdx = oldSort[i].src;
  5365. // Remove column sorting
  5366. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5367. .removeClass( sortClass + (i<2 ? i+1 : 3) );
  5368. }
  5369. // Add new column sorting
  5370. for ( i=0, ien=sort.length ; i<ien ; i++ ) {
  5371. colIdx = sort[i].src;
  5372. $( _pluck( settings.aoData, 'anCells', colIdx ) )
  5373. .addClass( sortClass + (i<2 ? i+1 : 3) );
  5374. }
  5375. }
  5376. settings.aLastSort = sort;
  5377. }
  5378. // Get the data to sort a column, be it from cache, fresh (populating the
  5379. // cache), or from a sort formatter
  5380. function _fnSortData( settings, idx )
  5381. {
  5382. // Custom sorting function - provided by the sort data type
  5383. var column = settings.aoColumns[ idx ];
  5384. var customSort = DataTable.ext.order[ column.sSortDataType ];
  5385. var customData;
  5386. if ( customSort ) {
  5387. customData = customSort.call( settings.oInstance, settings, idx,
  5388. _fnColumnIndexToVisible( settings, idx )
  5389. );
  5390. }
  5391. // Use / populate cache
  5392. var row, cellData;
  5393. var formatter = DataTable.ext.type.order[ column.sType+"-pre" ];
  5394. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  5395. row = settings.aoData[i];
  5396. if ( ! row._aSortData ) {
  5397. row._aSortData = [];
  5398. }
  5399. if ( ! row._aSortData[idx] || customSort ) {
  5400. cellData = customSort ?
  5401. customData[i] : // If there was a custom sort function, use data from there
  5402. _fnGetCellData( settings, i, idx, 'sort' );
  5403. row._aSortData[ idx ] = formatter ?
  5404. formatter( cellData ) :
  5405. cellData;
  5406. }
  5407. }
  5408. }
  5409. /**
  5410. * Save the state of a table
  5411. * @param {object} oSettings dataTables settings object
  5412. * @memberof DataTable#oApi
  5413. */
  5414. function _fnSaveState ( settings )
  5415. {
  5416. if ( !settings.oFeatures.bStateSave || settings.bDestroying )
  5417. {
  5418. return;
  5419. }
  5420. /* Store the interesting variables */
  5421. var state = {
  5422. time: +new Date(),
  5423. start: settings._iDisplayStart,
  5424. length: settings._iDisplayLength,
  5425. order: $.extend( true, [], settings.aaSorting ),
  5426. search: _fnSearchToCamel( settings.oPreviousSearch ),
  5427. columns: $.map( settings.aoColumns, function ( col, i ) {
  5428. return {
  5429. visible: col.bVisible,
  5430. search: _fnSearchToCamel( settings.aoPreSearchCols[i] )
  5431. };
  5432. } )
  5433. };
  5434. _fnCallbackFire( settings, "aoStateSaveParams", 'stateSaveParams', [settings, state] );
  5435. settings.oSavedState = state;
  5436. settings.fnStateSaveCallback.call( settings.oInstance, settings, state );
  5437. }
  5438. /**
  5439. * Attempt to load a saved table state
  5440. * @param {object} oSettings dataTables settings object
  5441. * @param {object} oInit DataTables init object so we can override settings
  5442. * @param {function} callback Callback to execute when the state has been loaded
  5443. * @memberof DataTable#oApi
  5444. */
  5445. function _fnLoadState ( settings, oInit, callback )
  5446. {
  5447. var i, ien;
  5448. var columns = settings.aoColumns;
  5449. var loaded = function ( s ) {
  5450. if ( ! s || ! s.time ) {
  5451. callback();
  5452. return;
  5453. }
  5454. // Allow custom and plug-in manipulation functions to alter the saved data set and
  5455. // cancelling of loading by returning false
  5456. var abStateLoad = _fnCallbackFire( settings, 'aoStateLoadParams', 'stateLoadParams', [settings, s] );
  5457. if ( $.inArray( false, abStateLoad ) !== -1 ) {
  5458. callback();
  5459. return;
  5460. }
  5461. // Reject old data
  5462. var duration = settings.iStateDuration;
  5463. if ( duration > 0 && s.time < +new Date() - (duration*1000) ) {
  5464. callback();
  5465. return;
  5466. }
  5467. // Number of columns have changed - all bets are off, no restore of settings
  5468. if ( s.columns && columns.length !== s.columns.length ) {
  5469. callback();
  5470. return;
  5471. }
  5472. // Store the saved state so it might be accessed at any time
  5473. settings.oLoadedState = $.extend( true, {}, s );
  5474. // Restore key features - todo - for 1.11 this needs to be done by
  5475. // subscribed events
  5476. if ( s.start !== undefined ) {
  5477. settings._iDisplayStart = s.start;
  5478. settings.iInitDisplayStart = s.start;
  5479. }
  5480. if ( s.length !== undefined ) {
  5481. settings._iDisplayLength = s.length;
  5482. }
  5483. // Order
  5484. if ( s.order !== undefined ) {
  5485. settings.aaSorting = [];
  5486. $.each( s.order, function ( i, col ) {
  5487. settings.aaSorting.push( col[0] >= columns.length ?
  5488. [ 0, col[1] ] :
  5489. col
  5490. );
  5491. } );
  5492. }
  5493. // Search
  5494. if ( s.search !== undefined ) {
  5495. $.extend( settings.oPreviousSearch, _fnSearchToHung( s.search ) );
  5496. }
  5497. // Columns
  5498. //
  5499. if ( s.columns ) {
  5500. for ( i=0, ien=s.columns.length ; i<ien ; i++ ) {
  5501. var col = s.columns[i];
  5502. // Visibility
  5503. if ( col.visible !== undefined ) {
  5504. columns[i].bVisible = col.visible;
  5505. }
  5506. // Search
  5507. if ( col.search !== undefined ) {
  5508. $.extend( settings.aoPreSearchCols[i], _fnSearchToHung( col.search ) );
  5509. }
  5510. }
  5511. }
  5512. _fnCallbackFire( settings, 'aoStateLoaded', 'stateLoaded', [settings, s] );
  5513. callback();
  5514. }
  5515. if ( ! settings.oFeatures.bStateSave ) {
  5516. callback();
  5517. return;
  5518. }
  5519. var state = settings.fnStateLoadCallback.call( settings.oInstance, settings, loaded );
  5520. if ( state !== undefined ) {
  5521. loaded( state );
  5522. }
  5523. // otherwise, wait for the loaded callback to be executed
  5524. }
  5525. /**
  5526. * Return the settings object for a particular table
  5527. * @param {node} table table we are using as a dataTable
  5528. * @returns {object} Settings object - or null if not found
  5529. * @memberof DataTable#oApi
  5530. */
  5531. function _fnSettingsFromNode ( table )
  5532. {
  5533. var settings = DataTable.settings;
  5534. var idx = $.inArray( table, _pluck( settings, 'nTable' ) );
  5535. return idx !== -1 ?
  5536. settings[ idx ] :
  5537. null;
  5538. }
  5539. /**
  5540. * Log an error message
  5541. * @param {object} settings dataTables settings object
  5542. * @param {int} level log error messages, or display them to the user
  5543. * @param {string} msg error message
  5544. * @param {int} tn Technical note id to get more information about the error.
  5545. * @memberof DataTable#oApi
  5546. */
  5547. function _fnLog( settings, level, msg, tn )
  5548. {
  5549. msg = 'DataTables warning: '+
  5550. (settings ? 'table id='+settings.sTableId+' - ' : '')+msg;
  5551. if ( tn ) {
  5552. msg += '. For more information about this error, please see '+
  5553. 'http://datatables.net/tn/'+tn;
  5554. }
  5555. if ( ! level ) {
  5556. // Backwards compatibility pre 1.10
  5557. var ext = DataTable.ext;
  5558. var type = ext.sErrMode || ext.errMode;
  5559. if ( settings ) {
  5560. _fnCallbackFire( settings, null, 'error', [ settings, tn, msg ] );
  5561. }
  5562. if ( type == 'alert' ) {
  5563. alert( msg );
  5564. }
  5565. else if ( type == 'throw' ) {
  5566. throw new Error(msg);
  5567. }
  5568. else if ( typeof type == 'function' ) {
  5569. type( settings, tn, msg );
  5570. }
  5571. }
  5572. else if ( window.console && console.log ) {
  5573. console.log( msg );
  5574. }
  5575. }
  5576. /**
  5577. * See if a property is defined on one object, if so assign it to the other object
  5578. * @param {object} ret target object
  5579. * @param {object} src source object
  5580. * @param {string} name property
  5581. * @param {string} [mappedName] name to map too - optional, name used if not given
  5582. * @memberof DataTable#oApi
  5583. */
  5584. function _fnMap( ret, src, name, mappedName )
  5585. {
  5586. if ( $.isArray( name ) ) {
  5587. $.each( name, function (i, val) {
  5588. if ( $.isArray( val ) ) {
  5589. _fnMap( ret, src, val[0], val[1] );
  5590. }
  5591. else {
  5592. _fnMap( ret, src, val );
  5593. }
  5594. } );
  5595. return;
  5596. }
  5597. if ( mappedName === undefined ) {
  5598. mappedName = name;
  5599. }
  5600. if ( src[name] !== undefined ) {
  5601. ret[mappedName] = src[name];
  5602. }
  5603. }
  5604. /**
  5605. * Extend objects - very similar to jQuery.extend, but deep copy objects, and
  5606. * shallow copy arrays. The reason we need to do this, is that we don't want to
  5607. * deep copy array init values (such as aaSorting) since the dev wouldn't be
  5608. * able to override them, but we do want to deep copy arrays.
  5609. * @param {object} out Object to extend
  5610. * @param {object} extender Object from which the properties will be applied to
  5611. * out
  5612. * @param {boolean} breakRefs If true, then arrays will be sliced to take an
  5613. * independent copy with the exception of the `data` or `aaData` parameters
  5614. * if they are present. This is so you can pass in a collection to
  5615. * DataTables and have that used as your data source without breaking the
  5616. * references
  5617. * @returns {object} out Reference, just for convenience - out === the return.
  5618. * @memberof DataTable#oApi
  5619. * @todo This doesn't take account of arrays inside the deep copied objects.
  5620. */
  5621. function _fnExtend( out, extender, breakRefs )
  5622. {
  5623. var val;
  5624. for ( var prop in extender ) {
  5625. if ( extender.hasOwnProperty(prop) ) {
  5626. val = extender[prop];
  5627. if ( $.isPlainObject( val ) ) {
  5628. if ( ! $.isPlainObject( out[prop] ) ) {
  5629. out[prop] = {};
  5630. }
  5631. $.extend( true, out[prop], val );
  5632. }
  5633. else if ( breakRefs && prop !== 'data' && prop !== 'aaData' && $.isArray(val) ) {
  5634. out[prop] = val.slice();
  5635. }
  5636. else {
  5637. out[prop] = val;
  5638. }
  5639. }
  5640. }
  5641. return out;
  5642. }
  5643. /**
  5644. * Bind an event handers to allow a click or return key to activate the callback.
  5645. * This is good for accessibility since a return on the keyboard will have the
  5646. * same effect as a click, if the element has focus.
  5647. * @param {element} n Element to bind the action to
  5648. * @param {object} oData Data object to pass to the triggered function
  5649. * @param {function} fn Callback function for when the event is triggered
  5650. * @memberof DataTable#oApi
  5651. */
  5652. function _fnBindAction( n, oData, fn )
  5653. {
  5654. $(n)
  5655. .on( 'click.DT', oData, function (e) {
  5656. $(n).blur(); // Remove focus outline for mouse users
  5657. fn(e);
  5658. } )
  5659. .on( 'keypress.DT', oData, function (e){
  5660. if ( e.which === 13 ) {
  5661. e.preventDefault();
  5662. fn(e);
  5663. }
  5664. } )
  5665. .on( 'selectstart.DT', function () {
  5666. /* Take the brutal approach to cancelling text selection */
  5667. return false;
  5668. } );
  5669. }
  5670. /**
  5671. * Register a callback function. Easily allows a callback function to be added to
  5672. * an array store of callback functions that can then all be called together.
  5673. * @param {object} oSettings dataTables settings object
  5674. * @param {string} sStore Name of the array storage for the callbacks in oSettings
  5675. * @param {function} fn Function to be called back
  5676. * @param {string} sName Identifying name for the callback (i.e. a label)
  5677. * @memberof DataTable#oApi
  5678. */
  5679. function _fnCallbackReg( oSettings, sStore, fn, sName )
  5680. {
  5681. if ( fn )
  5682. {
  5683. oSettings[sStore].push( {
  5684. "fn": fn,
  5685. "sName": sName
  5686. } );
  5687. }
  5688. }
  5689. /**
  5690. * Fire callback functions and trigger events. Note that the loop over the
  5691. * callback array store is done backwards! Further note that you do not want to
  5692. * fire off triggers in time sensitive applications (for example cell creation)
  5693. * as its slow.
  5694. * @param {object} settings dataTables settings object
  5695. * @param {string} callbackArr Name of the array storage for the callbacks in
  5696. * oSettings
  5697. * @param {string} eventName Name of the jQuery custom event to trigger. If
  5698. * null no trigger is fired
  5699. * @param {array} args Array of arguments to pass to the callback function /
  5700. * trigger
  5701. * @memberof DataTable#oApi
  5702. */
  5703. function _fnCallbackFire( settings, callbackArr, eventName, args )
  5704. {
  5705. var ret = [];
  5706. if ( callbackArr ) {
  5707. ret = $.map( settings[callbackArr].slice().reverse(), function (val, i) {
  5708. return val.fn.apply( settings.oInstance, args );
  5709. } );
  5710. }
  5711. if ( eventName !== null ) {
  5712. var e = $.Event( eventName+'.dt' );
  5713. $(settings.nTable).trigger( e, args );
  5714. ret.push( e.result );
  5715. }
  5716. return ret;
  5717. }
  5718. function _fnLengthOverflow ( settings )
  5719. {
  5720. var
  5721. start = settings._iDisplayStart,
  5722. end = settings.fnDisplayEnd(),
  5723. len = settings._iDisplayLength;
  5724. /* If we have space to show extra rows (backing up from the end point - then do so */
  5725. if ( start >= end )
  5726. {
  5727. start = end - len;
  5728. }
  5729. // Keep the start record on the current page
  5730. start -= (start % len);
  5731. if ( len === -1 || start < 0 )
  5732. {
  5733. start = 0;
  5734. }
  5735. settings._iDisplayStart = start;
  5736. }
  5737. function _fnRenderer( settings, type )
  5738. {
  5739. var renderer = settings.renderer;
  5740. var host = DataTable.ext.renderer[type];
  5741. if ( $.isPlainObject( renderer ) && renderer[type] ) {
  5742. // Specific renderer for this type. If available use it, otherwise use
  5743. // the default.
  5744. return host[renderer[type]] || host._;
  5745. }
  5746. else if ( typeof renderer === 'string' ) {
  5747. // Common renderer - if there is one available for this type use it,
  5748. // otherwise use the default
  5749. return host[renderer] || host._;
  5750. }
  5751. // Use the default
  5752. return host._;
  5753. }
  5754. /**
  5755. * Detect the data source being used for the table. Used to simplify the code
  5756. * a little (ajax) and to make it compress a little smaller.
  5757. *
  5758. * @param {object} settings dataTables settings object
  5759. * @returns {string} Data source
  5760. * @memberof DataTable#oApi
  5761. */
  5762. function _fnDataSource ( settings )
  5763. {
  5764. if ( settings.oFeatures.bServerSide ) {
  5765. return 'ssp';
  5766. }
  5767. else if ( settings.ajax || settings.sAjaxSource ) {
  5768. return 'ajax';
  5769. }
  5770. return 'dom';
  5771. }
  5772. /**
  5773. * Computed structure of the DataTables API, defined by the options passed to
  5774. * `DataTable.Api.register()` when building the API.
  5775. *
  5776. * The structure is built in order to speed creation and extension of the Api
  5777. * objects since the extensions are effectively pre-parsed.
  5778. *
  5779. * The array is an array of objects with the following structure, where this
  5780. * base array represents the Api prototype base:
  5781. *
  5782. * [
  5783. * {
  5784. * name: 'data' -- string - Property name
  5785. * val: function () {}, -- function - Api method (or undefined if just an object
  5786. * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  5787. * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  5788. * },
  5789. * {
  5790. * name: 'row'
  5791. * val: {},
  5792. * methodExt: [ ... ],
  5793. * propExt: [
  5794. * {
  5795. * name: 'data'
  5796. * val: function () {},
  5797. * methodExt: [ ... ],
  5798. * propExt: [ ... ]
  5799. * },
  5800. * ...
  5801. * ]
  5802. * }
  5803. * ]
  5804. *
  5805. * @type {Array}
  5806. * @ignore
  5807. */
  5808. var __apiStruct = [];
  5809. /**
  5810. * `Array.prototype` reference.
  5811. *
  5812. * @type object
  5813. * @ignore
  5814. */
  5815. var __arrayProto = Array.prototype;
  5816. /**
  5817. * Abstraction for `context` parameter of the `Api` constructor to allow it to
  5818. * take several different forms for ease of use.
  5819. *
  5820. * Each of the input parameter types will be converted to a DataTables settings
  5821. * object where possible.
  5822. *
  5823. * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
  5824. * of:
  5825. *
  5826. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5827. * with be found and used.
  5828. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5829. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5830. * * `object` - DataTables settings object
  5831. * * `DataTables.Api` - API instance
  5832. * @return {array|null} Matching DataTables settings objects. `null` or
  5833. * `undefined` is returned if no matching DataTable is found.
  5834. * @ignore
  5835. */
  5836. var _toSettings = function ( mixed )
  5837. {
  5838. var idx, jq;
  5839. var settings = DataTable.settings;
  5840. var tables = $.map( settings, function (el, i) {
  5841. return el.nTable;
  5842. } );
  5843. if ( ! mixed ) {
  5844. return [];
  5845. }
  5846. else if ( mixed.nTable && mixed.oApi ) {
  5847. // DataTables settings object
  5848. return [ mixed ];
  5849. }
  5850. else if ( mixed.nodeName && mixed.nodeName.toLowerCase() === 'table' ) {
  5851. // Table node
  5852. idx = $.inArray( mixed, tables );
  5853. return idx !== -1 ? [ settings[idx] ] : null;
  5854. }
  5855. else if ( mixed && typeof mixed.settings === 'function' ) {
  5856. return mixed.settings().toArray();
  5857. }
  5858. else if ( typeof mixed === 'string' ) {
  5859. // jQuery selector
  5860. jq = $(mixed);
  5861. }
  5862. else if ( mixed instanceof $ ) {
  5863. // jQuery object (also DataTables instance)
  5864. jq = mixed;
  5865. }
  5866. if ( jq ) {
  5867. return jq.map( function(i) {
  5868. idx = $.inArray( this, tables );
  5869. return idx !== -1 ? settings[idx] : null;
  5870. } ).toArray();
  5871. }
  5872. };
  5873. /**
  5874. * DataTables API class - used to control and interface with one or more
  5875. * DataTables enhanced tables.
  5876. *
  5877. * The API class is heavily based on jQuery, presenting a chainable interface
  5878. * that you can use to interact with tables. Each instance of the API class has
  5879. * a "context" - i.e. the tables that it will operate on. This could be a single
  5880. * table, all tables on a page or a sub-set thereof.
  5881. *
  5882. * Additionally the API is designed to allow you to easily work with the data in
  5883. * the tables, retrieving and manipulating it as required. This is done by
  5884. * presenting the API class as an array like interface. The contents of the
  5885. * array depend upon the actions requested by each method (for example
  5886. * `rows().nodes()` will return an array of nodes, while `rows().data()` will
  5887. * return an array of objects or arrays depending upon your table's
  5888. * configuration). The API object has a number of array like methods (`push`,
  5889. * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
  5890. * `unique` etc) to assist your working with the data held in a table.
  5891. *
  5892. * Most methods (those which return an Api instance) are chainable, which means
  5893. * the return from a method call also has all of the methods available that the
  5894. * top level object had. For example, these two calls are equivalent:
  5895. *
  5896. * // Not chained
  5897. * api.row.add( {...} );
  5898. * api.draw();
  5899. *
  5900. * // Chained
  5901. * api.row.add( {...} ).draw();
  5902. *
  5903. * @class DataTable.Api
  5904. * @param {array|object|string|jQuery} context DataTable identifier. This is
  5905. * used to define which DataTables enhanced tables this API will operate on.
  5906. * Can be one of:
  5907. *
  5908. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5909. * with be found and used.
  5910. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5911. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5912. * * `object` - DataTables settings object
  5913. * @param {array} [data] Data to initialise the Api instance with.
  5914. *
  5915. * @example
  5916. * // Direct initialisation during DataTables construction
  5917. * var api = $('#example').DataTable();
  5918. *
  5919. * @example
  5920. * // Initialisation using a DataTables jQuery object
  5921. * var api = $('#example').dataTable().api();
  5922. *
  5923. * @example
  5924. * // Initialisation as a constructor
  5925. * var api = new $.fn.DataTable.Api( 'table.dataTable' );
  5926. */
  5927. _Api = function ( context, data )
  5928. {
  5929. if ( ! (this instanceof _Api) ) {
  5930. return new _Api( context, data );
  5931. }
  5932. var settings = [];
  5933. var ctxSettings = function ( o ) {
  5934. var a = _toSettings( o );
  5935. if ( a ) {
  5936. settings = settings.concat( a );
  5937. }
  5938. };
  5939. if ( $.isArray( context ) ) {
  5940. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  5941. ctxSettings( context[i] );
  5942. }
  5943. }
  5944. else {
  5945. ctxSettings( context );
  5946. }
  5947. // Remove duplicates
  5948. this.context = _unique( settings );
  5949. // Initial data
  5950. if ( data ) {
  5951. $.merge( this, data );
  5952. }
  5953. // selector
  5954. this.selector = {
  5955. rows: null,
  5956. cols: null,
  5957. opts: null
  5958. };
  5959. _Api.extend( this, this, __apiStruct );
  5960. };
  5961. DataTable.Api = _Api;
  5962. // Don't destroy the existing prototype, just extend it. Required for jQuery 2's
  5963. // isPlainObject.
  5964. $.extend( _Api.prototype, {
  5965. any: function ()
  5966. {
  5967. return this.count() !== 0;
  5968. },
  5969. concat: __arrayProto.concat,
  5970. context: [], // array of table settings objects
  5971. count: function ()
  5972. {
  5973. return this.flatten().length;
  5974. },
  5975. each: function ( fn )
  5976. {
  5977. for ( var i=0, ien=this.length ; i<ien; i++ ) {
  5978. fn.call( this, this[i], i, this );
  5979. }
  5980. return this;
  5981. },
  5982. eq: function ( idx )
  5983. {
  5984. var ctx = this.context;
  5985. return ctx.length > idx ?
  5986. new _Api( ctx[idx], this[idx] ) :
  5987. null;
  5988. },
  5989. filter: function ( fn )
  5990. {
  5991. var a = [];
  5992. if ( __arrayProto.filter ) {
  5993. a = __arrayProto.filter.call( this, fn, this );
  5994. }
  5995. else {
  5996. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  5997. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  5998. if ( fn.call( this, this[i], i, this ) ) {
  5999. a.push( this[i] );
  6000. }
  6001. }
  6002. }
  6003. return new _Api( this.context, a );
  6004. },
  6005. flatten: function ()
  6006. {
  6007. var a = [];
  6008. return new _Api( this.context, a.concat.apply( a, this.toArray() ) );
  6009. },
  6010. join: __arrayProto.join,
  6011. indexOf: __arrayProto.indexOf || function (obj, start)
  6012. {
  6013. for ( var i=(start || 0), ien=this.length ; i<ien ; i++ ) {
  6014. if ( this[i] === obj ) {
  6015. return i;
  6016. }
  6017. }
  6018. return -1;
  6019. },
  6020. iterator: function ( flatten, type, fn, alwaysNew ) {
  6021. var
  6022. a = [], ret,
  6023. i, ien, j, jen,
  6024. context = this.context,
  6025. rows, items, item,
  6026. selector = this.selector;
  6027. // Argument shifting
  6028. if ( typeof flatten === 'string' ) {
  6029. alwaysNew = fn;
  6030. fn = type;
  6031. type = flatten;
  6032. flatten = false;
  6033. }
  6034. for ( i=0, ien=context.length ; i<ien ; i++ ) {
  6035. var apiInst = new _Api( context[i] );
  6036. if ( type === 'table' ) {
  6037. ret = fn.call( apiInst, context[i], i );
  6038. if ( ret !== undefined ) {
  6039. a.push( ret );
  6040. }
  6041. }
  6042. else if ( type === 'columns' || type === 'rows' ) {
  6043. // this has same length as context - one entry for each table
  6044. ret = fn.call( apiInst, context[i], this[i], i );
  6045. if ( ret !== undefined ) {
  6046. a.push( ret );
  6047. }
  6048. }
  6049. else if ( type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell' ) {
  6050. // columns and rows share the same structure.
  6051. // 'this' is an array of column indexes for each context
  6052. items = this[i];
  6053. if ( type === 'column-rows' ) {
  6054. rows = _selector_row_indexes( context[i], selector.opts );
  6055. }
  6056. for ( j=0, jen=items.length ; j<jen ; j++ ) {
  6057. item = items[j];
  6058. if ( type === 'cell' ) {
  6059. ret = fn.call( apiInst, context[i], item.row, item.column, i, j );
  6060. }
  6061. else {
  6062. ret = fn.call( apiInst, context[i], item, i, j, rows );
  6063. }
  6064. if ( ret !== undefined ) {
  6065. a.push( ret );
  6066. }
  6067. }
  6068. }
  6069. }
  6070. if ( a.length || alwaysNew ) {
  6071. var api = new _Api( context, flatten ? a.concat.apply( [], a ) : a );
  6072. var apiSelector = api.selector;
  6073. apiSelector.rows = selector.rows;
  6074. apiSelector.cols = selector.cols;
  6075. apiSelector.opts = selector.opts;
  6076. return api;
  6077. }
  6078. return this;
  6079. },
  6080. lastIndexOf: __arrayProto.lastIndexOf || function (obj, start)
  6081. {
  6082. // Bit cheeky...
  6083. return this.indexOf.apply( this.toArray.reverse(), arguments );
  6084. },
  6085. length: 0,
  6086. map: function ( fn )
  6087. {
  6088. var a = [];
  6089. if ( __arrayProto.map ) {
  6090. a = __arrayProto.map.call( this, fn, this );
  6091. }
  6092. else {
  6093. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6094. for ( var i=0, ien=this.length ; i<ien ; i++ ) {
  6095. a.push( fn.call( this, this[i], i ) );
  6096. }
  6097. }
  6098. return new _Api( this.context, a );
  6099. },
  6100. pluck: function ( prop )
  6101. {
  6102. return this.map( function ( el ) {
  6103. return el[ prop ];
  6104. } );
  6105. },
  6106. pop: __arrayProto.pop,
  6107. push: __arrayProto.push,
  6108. // Does not return an API instance
  6109. reduce: __arrayProto.reduce || function ( fn, init )
  6110. {
  6111. return _fnReduce( this, fn, init, 0, this.length, 1 );
  6112. },
  6113. reduceRight: __arrayProto.reduceRight || function ( fn, init )
  6114. {
  6115. return _fnReduce( this, fn, init, this.length-1, -1, -1 );
  6116. },
  6117. reverse: __arrayProto.reverse,
  6118. // Object with rows, columns and opts
  6119. selector: null,
  6120. shift: __arrayProto.shift,
  6121. slice: function () {
  6122. return new _Api( this.context, this );
  6123. },
  6124. sort: __arrayProto.sort, // ? name - order?
  6125. splice: __arrayProto.splice,
  6126. toArray: function ()
  6127. {
  6128. return __arrayProto.slice.call( this );
  6129. },
  6130. to$: function ()
  6131. {
  6132. return $( this );
  6133. },
  6134. toJQuery: function ()
  6135. {
  6136. return $( this );
  6137. },
  6138. unique: function ()
  6139. {
  6140. return new _Api( this.context, _unique(this) );
  6141. },
  6142. unshift: __arrayProto.unshift
  6143. } );
  6144. _Api.extend = function ( scope, obj, ext )
  6145. {
  6146. // Only extend API instances and static properties of the API
  6147. if ( ! ext.length || ! obj || ( ! (obj instanceof _Api) && ! obj.__dt_wrapper ) ) {
  6148. return;
  6149. }
  6150. var
  6151. i, ien,
  6152. j, jen,
  6153. struct, inner,
  6154. methodScoping = function ( scope, fn, struc ) {
  6155. return function () {
  6156. var ret = fn.apply( scope, arguments );
  6157. // Method extension
  6158. _Api.extend( ret, ret, struc.methodExt );
  6159. return ret;
  6160. };
  6161. };
  6162. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6163. struct = ext[i];
  6164. // Value
  6165. obj[ struct.name ] = typeof struct.val === 'function' ?
  6166. methodScoping( scope, struct.val, struct ) :
  6167. $.isPlainObject( struct.val ) ?
  6168. {} :
  6169. struct.val;
  6170. obj[ struct.name ].__dt_wrapper = true;
  6171. // Property extension
  6172. _Api.extend( scope, obj[ struct.name ], struct.propExt );
  6173. }
  6174. };
  6175. // @todo - Is there need for an augment function?
  6176. // _Api.augment = function ( inst, name )
  6177. // {
  6178. // // Find src object in the structure from the name
  6179. // var parts = name.split('.');
  6180. // _Api.extend( inst, obj );
  6181. // };
  6182. // [
  6183. // {
  6184. // name: 'data' -- string - Property name
  6185. // val: function () {}, -- function - Api method (or undefined if just an object
  6186. // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  6187. // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  6188. // },
  6189. // {
  6190. // name: 'row'
  6191. // val: {},
  6192. // methodExt: [ ... ],
  6193. // propExt: [
  6194. // {
  6195. // name: 'data'
  6196. // val: function () {},
  6197. // methodExt: [ ... ],
  6198. // propExt: [ ... ]
  6199. // },
  6200. // ...
  6201. // ]
  6202. // }
  6203. // ]
  6204. _Api.register = _api_register = function ( name, val )
  6205. {
  6206. if ( $.isArray( name ) ) {
  6207. for ( var j=0, jen=name.length ; j<jen ; j++ ) {
  6208. _Api.register( name[j], val );
  6209. }
  6210. return;
  6211. }
  6212. var
  6213. i, ien,
  6214. heir = name.split('.'),
  6215. struct = __apiStruct,
  6216. key, method;
  6217. var find = function ( src, name ) {
  6218. for ( var i=0, ien=src.length ; i<ien ; i++ ) {
  6219. if ( src[i].name === name ) {
  6220. return src[i];
  6221. }
  6222. }
  6223. return null;
  6224. };
  6225. for ( i=0, ien=heir.length ; i<ien ; i++ ) {
  6226. method = heir[i].indexOf('()') !== -1;
  6227. key = method ?
  6228. heir[i].replace('()', '') :
  6229. heir[i];
  6230. var src = find( struct, key );
  6231. if ( ! src ) {
  6232. src = {
  6233. name: key,
  6234. val: {},
  6235. methodExt: [],
  6236. propExt: []
  6237. };
  6238. struct.push( src );
  6239. }
  6240. if ( i === ien-1 ) {
  6241. src.val = val;
  6242. }
  6243. else {
  6244. struct = method ?
  6245. src.methodExt :
  6246. src.propExt;
  6247. }
  6248. }
  6249. };
  6250. _Api.registerPlural = _api_registerPlural = function ( pluralName, singularName, val ) {
  6251. _Api.register( pluralName, val );
  6252. _Api.register( singularName, function () {
  6253. var ret = val.apply( this, arguments );
  6254. if ( ret === this ) {
  6255. // Returned item is the API instance that was passed in, return it
  6256. return this;
  6257. }
  6258. else if ( ret instanceof _Api ) {
  6259. // New API instance returned, want the value from the first item
  6260. // in the returned array for the singular result.
  6261. return ret.length ?
  6262. $.isArray( ret[0] ) ?
  6263. new _Api( ret.context, ret[0] ) : // Array results are 'enhanced'
  6264. ret[0] :
  6265. undefined;
  6266. }
  6267. // Non-API return - just fire it back
  6268. return ret;
  6269. } );
  6270. };
  6271. /**
  6272. * Selector for HTML tables. Apply the given selector to the give array of
  6273. * DataTables settings objects.
  6274. *
  6275. * @param {string|integer} [selector] jQuery selector string or integer
  6276. * @param {array} Array of DataTables settings objects to be filtered
  6277. * @return {array}
  6278. * @ignore
  6279. */
  6280. var __table_selector = function ( selector, a )
  6281. {
  6282. // Integer is used to pick out a table by index
  6283. if ( typeof selector === 'number' ) {
  6284. return [ a[ selector ] ];
  6285. }
  6286. // Perform a jQuery selector on the table nodes
  6287. var nodes = $.map( a, function (el, i) {
  6288. return el.nTable;
  6289. } );
  6290. return $(nodes)
  6291. .filter( selector )
  6292. .map( function (i) {
  6293. // Need to translate back from the table node to the settings
  6294. var idx = $.inArray( this, nodes );
  6295. return a[ idx ];
  6296. } )
  6297. .toArray();
  6298. };
  6299. /**
  6300. * Context selector for the API's context (i.e. the tables the API instance
  6301. * refers to.
  6302. *
  6303. * @name DataTable.Api#tables
  6304. * @param {string|integer} [selector] Selector to pick which tables the iterator
  6305. * should operate on. If not given, all tables in the current context are
  6306. * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
  6307. * select multiple tables or as an integer to select a single table.
  6308. * @returns {DataTable.Api} Returns a new API instance if a selector is given.
  6309. */
  6310. _api_register( 'tables()', function ( selector ) {
  6311. // A new instance is created if there was a selector specified
  6312. return selector ?
  6313. new _Api( __table_selector( selector, this.context ) ) :
  6314. this;
  6315. } );
  6316. _api_register( 'table()', function ( selector ) {
  6317. var tables = this.tables( selector );
  6318. var ctx = tables.context;
  6319. // Truncate to the first matched table
  6320. return ctx.length ?
  6321. new _Api( ctx[0] ) :
  6322. tables;
  6323. } );
  6324. _api_registerPlural( 'tables().nodes()', 'table().node()' , function () {
  6325. return this.iterator( 'table', function ( ctx ) {
  6326. return ctx.nTable;
  6327. }, 1 );
  6328. } );
  6329. _api_registerPlural( 'tables().body()', 'table().body()' , function () {
  6330. return this.iterator( 'table', function ( ctx ) {
  6331. return ctx.nTBody;
  6332. }, 1 );
  6333. } );
  6334. _api_registerPlural( 'tables().header()', 'table().header()' , function () {
  6335. return this.iterator( 'table', function ( ctx ) {
  6336. return ctx.nTHead;
  6337. }, 1 );
  6338. } );
  6339. _api_registerPlural( 'tables().footer()', 'table().footer()' , function () {
  6340. return this.iterator( 'table', function ( ctx ) {
  6341. return ctx.nTFoot;
  6342. }, 1 );
  6343. } );
  6344. _api_registerPlural( 'tables().containers()', 'table().container()' , function () {
  6345. return this.iterator( 'table', function ( ctx ) {
  6346. return ctx.nTableWrapper;
  6347. }, 1 );
  6348. } );
  6349. /**
  6350. * Redraw the tables in the current context.
  6351. */
  6352. _api_register( 'draw()', function ( paging ) {
  6353. return this.iterator( 'table', function ( settings ) {
  6354. if ( paging === 'page' ) {
  6355. _fnDraw( settings );
  6356. }
  6357. else {
  6358. if ( typeof paging === 'string' ) {
  6359. paging = paging === 'full-hold' ?
  6360. false :
  6361. true;
  6362. }
  6363. _fnReDraw( settings, paging===false );
  6364. }
  6365. } );
  6366. } );
  6367. /**
  6368. * Get the current page index.
  6369. *
  6370. * @return {integer} Current page index (zero based)
  6371. *//**
  6372. * Set the current page.
  6373. *
  6374. * Note that if you attempt to show a page which does not exist, DataTables will
  6375. * not throw an error, but rather reset the paging.
  6376. *
  6377. * @param {integer|string} action The paging action to take. This can be one of:
  6378. * * `integer` - The page index to jump to
  6379. * * `string` - An action to take:
  6380. * * `first` - Jump to first page.
  6381. * * `next` - Jump to the next page
  6382. * * `previous` - Jump to previous page
  6383. * * `last` - Jump to the last page.
  6384. * @returns {DataTables.Api} this
  6385. */
  6386. _api_register( 'page()', function ( action ) {
  6387. if ( action === undefined ) {
  6388. return this.page.info().page; // not an expensive call
  6389. }
  6390. // else, have an action to take on all tables
  6391. return this.iterator( 'table', function ( settings ) {
  6392. _fnPageChange( settings, action );
  6393. } );
  6394. } );
  6395. /**
  6396. * Paging information for the first table in the current context.
  6397. *
  6398. * If you require paging information for another table, use the `table()` method
  6399. * with a suitable selector.
  6400. *
  6401. * @return {object} Object with the following properties set:
  6402. * * `page` - Current page index (zero based - i.e. the first page is `0`)
  6403. * * `pages` - Total number of pages
  6404. * * `start` - Display index for the first record shown on the current page
  6405. * * `end` - Display index for the last record shown on the current page
  6406. * * `length` - Display length (number of records). Note that generally `start
  6407. * + length = end`, but this is not always true, for example if there are
  6408. * only 2 records to show on the final page, with a length of 10.
  6409. * * `recordsTotal` - Full data set length
  6410. * * `recordsDisplay` - Data set length once the current filtering criterion
  6411. * are applied.
  6412. */
  6413. _api_register( 'page.info()', function ( action ) {
  6414. if ( this.context.length === 0 ) {
  6415. return undefined;
  6416. }
  6417. var
  6418. settings = this.context[0],
  6419. start = settings._iDisplayStart,
  6420. len = settings.oFeatures.bPaginate ? settings._iDisplayLength : -1,
  6421. visRecords = settings.fnRecordsDisplay(),
  6422. all = len === -1;
  6423. return {
  6424. "page": all ? 0 : Math.floor( start / len ),
  6425. "pages": all ? 1 : Math.ceil( visRecords / len ),
  6426. "start": start,
  6427. "end": settings.fnDisplayEnd(),
  6428. "length": len,
  6429. "recordsTotal": settings.fnRecordsTotal(),
  6430. "recordsDisplay": visRecords,
  6431. "serverSide": _fnDataSource( settings ) === 'ssp'
  6432. };
  6433. } );
  6434. /**
  6435. * Get the current page length.
  6436. *
  6437. * @return {integer} Current page length. Note `-1` indicates that all records
  6438. * are to be shown.
  6439. *//**
  6440. * Set the current page length.
  6441. *
  6442. * @param {integer} Page length to set. Use `-1` to show all records.
  6443. * @returns {DataTables.Api} this
  6444. */
  6445. _api_register( 'page.len()', function ( len ) {
  6446. // Note that we can't call this function 'length()' because `length`
  6447. // is a Javascript property of functions which defines how many arguments
  6448. // the function expects.
  6449. if ( len === undefined ) {
  6450. return this.context.length !== 0 ?
  6451. this.context[0]._iDisplayLength :
  6452. undefined;
  6453. }
  6454. // else, set the page length
  6455. return this.iterator( 'table', function ( settings ) {
  6456. _fnLengthChange( settings, len );
  6457. } );
  6458. } );
  6459. var __reload = function ( settings, holdPosition, callback ) {
  6460. // Use the draw event to trigger a callback
  6461. if ( callback ) {
  6462. var api = new _Api( settings );
  6463. api.one( 'draw', function () {
  6464. callback( api.ajax.json() );
  6465. } );
  6466. }
  6467. if ( _fnDataSource( settings ) == 'ssp' ) {
  6468. _fnReDraw( settings, holdPosition );
  6469. }
  6470. else {
  6471. _fnProcessingDisplay( settings, true );
  6472. // Cancel an existing request
  6473. var xhr = settings.jqXHR;
  6474. if ( xhr && xhr.readyState !== 4 ) {
  6475. xhr.abort();
  6476. }
  6477. // Trigger xhr
  6478. _fnBuildAjax( settings, [], function( json ) {
  6479. _fnClearTable( settings );
  6480. var data = _fnAjaxDataSrc( settings, json );
  6481. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  6482. _fnAddData( settings, data[i] );
  6483. }
  6484. _fnReDraw( settings, holdPosition );
  6485. _fnProcessingDisplay( settings, false );
  6486. } );
  6487. }
  6488. };
  6489. /**
  6490. * Get the JSON response from the last Ajax request that DataTables made to the
  6491. * server. Note that this returns the JSON from the first table in the current
  6492. * context.
  6493. *
  6494. * @return {object} JSON received from the server.
  6495. */
  6496. _api_register( 'ajax.json()', function () {
  6497. var ctx = this.context;
  6498. if ( ctx.length > 0 ) {
  6499. return ctx[0].json;
  6500. }
  6501. // else return undefined;
  6502. } );
  6503. /**
  6504. * Get the data submitted in the last Ajax request
  6505. */
  6506. _api_register( 'ajax.params()', function () {
  6507. var ctx = this.context;
  6508. if ( ctx.length > 0 ) {
  6509. return ctx[0].oAjaxData;
  6510. }
  6511. // else return undefined;
  6512. } );
  6513. /**
  6514. * Reload tables from the Ajax data source. Note that this function will
  6515. * automatically re-draw the table when the remote data has been loaded.
  6516. *
  6517. * @param {boolean} [reset=true] Reset (default) or hold the current paging
  6518. * position. A full re-sort and re-filter is performed when this method is
  6519. * called, which is why the pagination reset is the default action.
  6520. * @returns {DataTables.Api} this
  6521. */
  6522. _api_register( 'ajax.reload()', function ( callback, resetPaging ) {
  6523. return this.iterator( 'table', function (settings) {
  6524. __reload( settings, resetPaging===false, callback );
  6525. } );
  6526. } );
  6527. /**
  6528. * Get the current Ajax URL. Note that this returns the URL from the first
  6529. * table in the current context.
  6530. *
  6531. * @return {string} Current Ajax source URL
  6532. *//**
  6533. * Set the Ajax URL. Note that this will set the URL for all tables in the
  6534. * current context.
  6535. *
  6536. * @param {string} url URL to set.
  6537. * @returns {DataTables.Api} this
  6538. */
  6539. _api_register( 'ajax.url()', function ( url ) {
  6540. var ctx = this.context;
  6541. if ( url === undefined ) {
  6542. // get
  6543. if ( ctx.length === 0 ) {
  6544. return undefined;
  6545. }
  6546. ctx = ctx[0];
  6547. return ctx.ajax ?
  6548. $.isPlainObject( ctx.ajax ) ?
  6549. ctx.ajax.url :
  6550. ctx.ajax :
  6551. ctx.sAjaxSource;
  6552. }
  6553. // set
  6554. return this.iterator( 'table', function ( settings ) {
  6555. if ( $.isPlainObject( settings.ajax ) ) {
  6556. settings.ajax.url = url;
  6557. }
  6558. else {
  6559. settings.ajax = url;
  6560. }
  6561. // No need to consider sAjaxSource here since DataTables gives priority
  6562. // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
  6563. // value of `sAjaxSource` redundant.
  6564. } );
  6565. } );
  6566. /**
  6567. * Load data from the newly set Ajax URL. Note that this method is only
  6568. * available when `ajax.url()` is used to set a URL. Additionally, this method
  6569. * has the same effect as calling `ajax.reload()` but is provided for
  6570. * convenience when setting a new URL. Like `ajax.reload()` it will
  6571. * automatically redraw the table once the remote data has been loaded.
  6572. *
  6573. * @returns {DataTables.Api} this
  6574. */
  6575. _api_register( 'ajax.url().load()', function ( callback, resetPaging ) {
  6576. // Same as a reload, but makes sense to present it for easy access after a
  6577. // url change
  6578. return this.iterator( 'table', function ( ctx ) {
  6579. __reload( ctx, resetPaging===false, callback );
  6580. } );
  6581. } );
  6582. var _selector_run = function ( type, selector, selectFn, settings, opts )
  6583. {
  6584. var
  6585. out = [], res,
  6586. a, i, ien, j, jen,
  6587. selectorType = typeof selector;
  6588. // Can't just check for isArray here, as an API or jQuery instance might be
  6589. // given with their array like look
  6590. if ( ! selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined ) {
  6591. selector = [ selector ];
  6592. }
  6593. for ( i=0, ien=selector.length ; i<ien ; i++ ) {
  6594. // Only split on simple strings - complex expressions will be jQuery selectors
  6595. a = selector[i] && selector[i].split && ! selector[i].match(/[\[\(:]/) ?
  6596. selector[i].split(',') :
  6597. [ selector[i] ];
  6598. for ( j=0, jen=a.length ; j<jen ; j++ ) {
  6599. res = selectFn( typeof a[j] === 'string' ? $.trim(a[j]) : a[j] );
  6600. if ( res && res.length ) {
  6601. out = out.concat( res );
  6602. }
  6603. }
  6604. }
  6605. // selector extensions
  6606. var ext = _ext.selector[ type ];
  6607. if ( ext.length ) {
  6608. for ( i=0, ien=ext.length ; i<ien ; i++ ) {
  6609. out = ext[i]( settings, opts, out );
  6610. }
  6611. }
  6612. return _unique( out );
  6613. };
  6614. var _selector_opts = function ( opts )
  6615. {
  6616. if ( ! opts ) {
  6617. opts = {};
  6618. }
  6619. // Backwards compatibility for 1.9- which used the terminology filter rather
  6620. // than search
  6621. if ( opts.filter && opts.search === undefined ) {
  6622. opts.search = opts.filter;
  6623. }
  6624. return $.extend( {
  6625. search: 'none',
  6626. order: 'current',
  6627. page: 'all'
  6628. }, opts );
  6629. };
  6630. var _selector_first = function ( inst )
  6631. {
  6632. // Reduce the API instance to the first item found
  6633. for ( var i=0, ien=inst.length ; i<ien ; i++ ) {
  6634. if ( inst[i].length > 0 ) {
  6635. // Assign the first element to the first item in the instance
  6636. // and truncate the instance and context
  6637. inst[0] = inst[i];
  6638. inst[0].length = 1;
  6639. inst.length = 1;
  6640. inst.context = [ inst.context[i] ];
  6641. return inst;
  6642. }
  6643. }
  6644. // Not found - return an empty instance
  6645. inst.length = 0;
  6646. return inst;
  6647. };
  6648. var _selector_row_indexes = function ( settings, opts )
  6649. {
  6650. var
  6651. i, ien, tmp, a=[],
  6652. displayFiltered = settings.aiDisplay,
  6653. displayMaster = settings.aiDisplayMaster;
  6654. var
  6655. search = opts.search, // none, applied, removed
  6656. order = opts.order, // applied, current, index (original - compatibility with 1.9)
  6657. page = opts.page; // all, current
  6658. if ( _fnDataSource( settings ) == 'ssp' ) {
  6659. // In server-side processing mode, most options are irrelevant since
  6660. // rows not shown don't exist and the index order is the applied order
  6661. // Removed is a special case - for consistency just return an empty
  6662. // array
  6663. return search === 'removed' ?
  6664. [] :
  6665. _range( 0, displayMaster.length );
  6666. }
  6667. else if ( page == 'current' ) {
  6668. // Current page implies that order=current and fitler=applied, since it is
  6669. // fairly senseless otherwise, regardless of what order and search actually
  6670. // are
  6671. for ( i=settings._iDisplayStart, ien=settings.fnDisplayEnd() ; i<ien ; i++ ) {
  6672. a.push( displayFiltered[i] );
  6673. }
  6674. }
  6675. else if ( order == 'current' || order == 'applied' ) {
  6676. if ( search == 'none') {
  6677. a = displayMaster.slice();
  6678. }
  6679. else if ( search == 'applied' ) {
  6680. a = displayFiltered.slice();
  6681. }
  6682. else if ( search == 'removed' ) {
  6683. // O(n+m) solution by creating a hash map
  6684. var displayFilteredMap = {};
  6685. for ( var i=0, ien=displayFiltered.length ; i<ien ; i++ ) {
  6686. displayFilteredMap[displayFiltered[i]] = null;
  6687. }
  6688. a = $.map( displayMaster, function (el) {
  6689. return ! displayFilteredMap.hasOwnProperty(el) ?
  6690. el :
  6691. null;
  6692. } );
  6693. }
  6694. }
  6695. else if ( order == 'index' || order == 'original' ) {
  6696. for ( i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  6697. if ( search == 'none' ) {
  6698. a.push( i );
  6699. }
  6700. else { // applied | removed
  6701. tmp = $.inArray( i, displayFiltered );
  6702. if ((tmp === -1 && search == 'removed') ||
  6703. (tmp >= 0 && search == 'applied') )
  6704. {
  6705. a.push( i );
  6706. }
  6707. }
  6708. }
  6709. }
  6710. return a;
  6711. };
  6712. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  6713. * Rows
  6714. *
  6715. * {} - no selector - use all available rows
  6716. * {integer} - row aoData index
  6717. * {node} - TR node
  6718. * {string} - jQuery selector to apply to the TR elements
  6719. * {array} - jQuery array of nodes, or simply an array of TR nodes
  6720. *
  6721. */
  6722. var __row_selector = function ( settings, selector, opts )
  6723. {
  6724. var rows;
  6725. var run = function ( sel ) {
  6726. var selInt = _intVal( sel );
  6727. var i, ien;
  6728. var aoData = settings.aoData;
  6729. // Short cut - selector is a number and no options provided (default is
  6730. // all records, so no need to check if the index is in there, since it
  6731. // must be - dev error if the index doesn't exist).
  6732. if ( selInt !== null && ! opts ) {
  6733. return [ selInt ];
  6734. }
  6735. if ( ! rows ) {
  6736. rows = _selector_row_indexes( settings, opts );
  6737. }
  6738. if ( selInt !== null && $.inArray( selInt, rows ) !== -1 ) {
  6739. // Selector - integer
  6740. return [ selInt ];
  6741. }
  6742. else if ( sel === null || sel === undefined || sel === '' ) {
  6743. // Selector - none
  6744. return rows;
  6745. }
  6746. // Selector - function
  6747. if ( typeof sel === 'function' ) {
  6748. return $.map( rows, function (idx) {
  6749. var row = aoData[ idx ];
  6750. return sel( idx, row._aData, row.nTr ) ? idx : null;
  6751. } );
  6752. }
  6753. // Selector - node
  6754. if ( sel.nodeName ) {
  6755. var rowIdx = sel._DT_RowIndex; // Property added by DT for fast lookup
  6756. var cellIdx = sel._DT_CellIndex;
  6757. if ( rowIdx !== undefined ) {
  6758. // Make sure that the row is actually still present in the table
  6759. return aoData[ rowIdx ] && aoData[ rowIdx ].nTr === sel ?
  6760. [ rowIdx ] :
  6761. [];
  6762. }
  6763. else if ( cellIdx ) {
  6764. return aoData[ cellIdx.row ] && aoData[ cellIdx.row ].nTr === sel ?
  6765. [ cellIdx.row ] :
  6766. [];
  6767. }
  6768. else {
  6769. var host = $(sel).closest('*[data-dt-row]');
  6770. return host.length ?
  6771. [ host.data('dt-row') ] :
  6772. [];
  6773. }
  6774. }
  6775. // ID selector. Want to always be able to select rows by id, regardless
  6776. // of if the tr element has been created or not, so can't rely upon
  6777. // jQuery here - hence a custom implementation. This does not match
  6778. // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
  6779. // but to select it using a CSS selector engine (like Sizzle or
  6780. // querySelect) it would need to need to be escaped for some characters.
  6781. // DataTables simplifies this for row selectors since you can select
  6782. // only a row. A # indicates an id any anything that follows is the id -
  6783. // unescaped.
  6784. if ( typeof sel === 'string' && sel.charAt(0) === '#' ) {
  6785. // get row index from id
  6786. var rowObj = settings.aIds[ sel.replace( /^#/, '' ) ];
  6787. if ( rowObj !== undefined ) {
  6788. return [ rowObj.idx ];
  6789. }
  6790. // need to fall through to jQuery in case there is DOM id that
  6791. // matches
  6792. }
  6793. // Get nodes in the order from the `rows` array with null values removed
  6794. var nodes = _removeEmpty(
  6795. _pluck_order( settings.aoData, rows, 'nTr' )
  6796. );
  6797. // Selector - jQuery selector string, array of nodes or jQuery object/
  6798. // As jQuery's .filter() allows jQuery objects to be passed in filter,
  6799. // it also allows arrays, so this will cope with all three options
  6800. return $(nodes)
  6801. .filter( sel )
  6802. .map( function () {
  6803. return this._DT_RowIndex;
  6804. } )
  6805. .toArray();
  6806. };
  6807. return _selector_run( 'row', selector, run, settings, opts );
  6808. };
  6809. _api_register( 'rows()', function ( selector, opts ) {
  6810. // argument shifting
  6811. if ( selector === undefined ) {
  6812. selector = '';
  6813. }
  6814. else if ( $.isPlainObject( selector ) ) {
  6815. opts = selector;
  6816. selector = '';
  6817. }
  6818. opts = _selector_opts( opts );
  6819. var inst = this.iterator( 'table', function ( settings ) {
  6820. return __row_selector( settings, selector, opts );
  6821. }, 1 );
  6822. // Want argument shifting here and in __row_selector?
  6823. inst.selector.rows = selector;
  6824. inst.selector.opts = opts;
  6825. return inst;
  6826. } );
  6827. _api_register( 'rows().nodes()', function () {
  6828. return this.iterator( 'row', function ( settings, row ) {
  6829. return settings.aoData[ row ].nTr || undefined;
  6830. }, 1 );
  6831. } );
  6832. _api_register( 'rows().data()', function () {
  6833. return this.iterator( true, 'rows', function ( settings, rows ) {
  6834. return _pluck_order( settings.aoData, rows, '_aData' );
  6835. }, 1 );
  6836. } );
  6837. _api_registerPlural( 'rows().cache()', 'row().cache()', function ( type ) {
  6838. return this.iterator( 'row', function ( settings, row ) {
  6839. var r = settings.aoData[ row ];
  6840. return type === 'search' ? r._aFilterData : r._aSortData;
  6841. }, 1 );
  6842. } );
  6843. _api_registerPlural( 'rows().invalidate()', 'row().invalidate()', function ( src ) {
  6844. return this.iterator( 'row', function ( settings, row ) {
  6845. _fnInvalidate( settings, row, src );
  6846. } );
  6847. } );
  6848. _api_registerPlural( 'rows().indexes()', 'row().index()', function () {
  6849. return this.iterator( 'row', function ( settings, row ) {
  6850. return row;
  6851. }, 1 );
  6852. } );
  6853. _api_registerPlural( 'rows().ids()', 'row().id()', function ( hash ) {
  6854. var a = [];
  6855. var context = this.context;
  6856. // `iterator` will drop undefined values, but in this case we want them
  6857. for ( var i=0, ien=context.length ; i<ien ; i++ ) {
  6858. for ( var j=0, jen=this[i].length ; j<jen ; j++ ) {
  6859. var id = context[i].rowIdFn( context[i].aoData[ this[i][j] ]._aData );
  6860. a.push( (hash === true ? '#' : '' )+ id );
  6861. }
  6862. }
  6863. return new _Api( context, a );
  6864. } );
  6865. _api_registerPlural( 'rows().remove()', 'row().remove()', function () {
  6866. var that = this;
  6867. this.iterator( 'row', function ( settings, row, thatIdx ) {
  6868. var data = settings.aoData;
  6869. var rowData = data[ row ];
  6870. var i, ien, j, jen;
  6871. var loopRow, loopCells;
  6872. data.splice( row, 1 );
  6873. // Update the cached indexes
  6874. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  6875. loopRow = data[i];
  6876. loopCells = loopRow.anCells;
  6877. // Rows
  6878. if ( loopRow.nTr !== null ) {
  6879. loopRow.nTr._DT_RowIndex = i;
  6880. }
  6881. // Cells
  6882. if ( loopCells !== null ) {
  6883. for ( j=0, jen=loopCells.length ; j<jen ; j++ ) {
  6884. loopCells[j]._DT_CellIndex.row = i;
  6885. }
  6886. }
  6887. }
  6888. // Delete from the display arrays
  6889. _fnDeleteIndex( settings.aiDisplayMaster, row );
  6890. _fnDeleteIndex( settings.aiDisplay, row );
  6891. _fnDeleteIndex( that[ thatIdx ], row, false ); // maintain local indexes
  6892. // For server-side processing tables - subtract the deleted row from the count
  6893. if ( settings._iRecordsDisplay > 0 ) {
  6894. settings._iRecordsDisplay--;
  6895. }
  6896. // Check for an 'overflow' they case for displaying the table
  6897. _fnLengthOverflow( settings );
  6898. // Remove the row's ID reference if there is one
  6899. var id = settings.rowIdFn( rowData._aData );
  6900. if ( id !== undefined ) {
  6901. delete settings.aIds[ id ];
  6902. }
  6903. } );
  6904. this.iterator( 'table', function ( settings ) {
  6905. for ( var i=0, ien=settings.aoData.length ; i<ien ; i++ ) {
  6906. settings.aoData[i].idx = i;
  6907. }
  6908. } );
  6909. return this;
  6910. } );
  6911. _api_register( 'rows.add()', function ( rows ) {
  6912. var newRows = this.iterator( 'table', function ( settings ) {
  6913. var row, i, ien;
  6914. var out = [];
  6915. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  6916. row = rows[i];
  6917. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  6918. out.push( _fnAddTr( settings, row )[0] );
  6919. }
  6920. else {
  6921. out.push( _fnAddData( settings, row ) );
  6922. }
  6923. }
  6924. return out;
  6925. }, 1 );
  6926. // Return an Api.rows() extended instance, so rows().nodes() etc can be used
  6927. var modRows = this.rows( -1 );
  6928. modRows.pop();
  6929. $.merge( modRows, newRows );
  6930. return modRows;
  6931. } );
  6932. /**
  6933. *
  6934. */
  6935. _api_register( 'row()', function ( selector, opts ) {
  6936. return _selector_first( this.rows( selector, opts ) );
  6937. } );
  6938. _api_register( 'row().data()', function ( data ) {
  6939. var ctx = this.context;
  6940. if ( data === undefined ) {
  6941. // Get
  6942. return ctx.length && this.length ?
  6943. ctx[0].aoData[ this[0] ]._aData :
  6944. undefined;
  6945. }
  6946. // Set
  6947. var row = ctx[0].aoData[ this[0] ];
  6948. row._aData = data;
  6949. // If the DOM has an id, and the data source is an array
  6950. if ( $.isArray( data ) && row.nTr.id ) {
  6951. _fnSetObjectDataFn( ctx[0].rowId )( data, row.nTr.id );
  6952. }
  6953. // Automatically invalidate
  6954. _fnInvalidate( ctx[0], this[0], 'data' );
  6955. return this;
  6956. } );
  6957. _api_register( 'row().node()', function () {
  6958. var ctx = this.context;
  6959. return ctx.length && this.length ?
  6960. ctx[0].aoData[ this[0] ].nTr || null :
  6961. null;
  6962. } );
  6963. _api_register( 'row.add()', function ( row ) {
  6964. // Allow a jQuery object to be passed in - only a single row is added from
  6965. // it though - the first element in the set
  6966. if ( row instanceof $ && row.length ) {
  6967. row = row[0];
  6968. }
  6969. var rows = this.iterator( 'table', function ( settings ) {
  6970. if ( row.nodeName && row.nodeName.toUpperCase() === 'TR' ) {
  6971. return _fnAddTr( settings, row )[0];
  6972. }
  6973. return _fnAddData( settings, row );
  6974. } );
  6975. // Return an Api.rows() extended instance, with the newly added row selected
  6976. return this.row( rows[0] );
  6977. } );
  6978. var __details_add = function ( ctx, row, data, klass )
  6979. {
  6980. // Convert to array of TR elements
  6981. var rows = [];
  6982. var addRow = function ( r, k ) {
  6983. // Recursion to allow for arrays of jQuery objects
  6984. if ( $.isArray( r ) || r instanceof $ ) {
  6985. for ( var i=0, ien=r.length ; i<ien ; i++ ) {
  6986. addRow( r[i], k );
  6987. }
  6988. return;
  6989. }
  6990. // If we get a TR element, then just add it directly - up to the dev
  6991. // to add the correct number of columns etc
  6992. if ( r.nodeName && r.nodeName.toLowerCase() === 'tr' ) {
  6993. rows.push( r );
  6994. }
  6995. else {
  6996. // Otherwise create a row with a wrapper
  6997. var created = $('<tr><td/></tr>').addClass( k );
  6998. $('td', created)
  6999. .addClass( k )
  7000. .html( r )
  7001. [0].colSpan = _fnVisbleColumns( ctx );
  7002. rows.push( created[0] );
  7003. }
  7004. };
  7005. addRow( data, klass );
  7006. if ( row._details ) {
  7007. row._details.detach();
  7008. }
  7009. row._details = $(rows);
  7010. // If the children were already shown, that state should be retained
  7011. if ( row._detailsShow ) {
  7012. row._details.insertAfter( row.nTr );
  7013. }
  7014. };
  7015. var __details_remove = function ( api, idx )
  7016. {
  7017. var ctx = api.context;
  7018. if ( ctx.length ) {
  7019. var row = ctx[0].aoData[ idx !== undefined ? idx : api[0] ];
  7020. if ( row && row._details ) {
  7021. row._details.remove();
  7022. row._detailsShow = undefined;
  7023. row._details = undefined;
  7024. }
  7025. }
  7026. };
  7027. var __details_display = function ( api, show ) {
  7028. var ctx = api.context;
  7029. if ( ctx.length && api.length ) {
  7030. var row = ctx[0].aoData[ api[0] ];
  7031. if ( row._details ) {
  7032. row._detailsShow = show;
  7033. if ( show ) {
  7034. row._details.insertAfter( row.nTr );
  7035. }
  7036. else {
  7037. row._details.detach();
  7038. }
  7039. __details_events( ctx[0] );
  7040. }
  7041. }
  7042. };
  7043. var __details_events = function ( settings )
  7044. {
  7045. var api = new _Api( settings );
  7046. var namespace = '.dt.DT_details';
  7047. var drawEvent = 'draw'+namespace;
  7048. var colvisEvent = 'column-visibility'+namespace;
  7049. var destroyEvent = 'destroy'+namespace;
  7050. var data = settings.aoData;
  7051. api.off( drawEvent +' '+ colvisEvent +' '+ destroyEvent );
  7052. if ( _pluck( data, '_details' ).length > 0 ) {
  7053. // On each draw, insert the required elements into the document
  7054. api.on( drawEvent, function ( e, ctx ) {
  7055. if ( settings !== ctx ) {
  7056. return;
  7057. }
  7058. api.rows( {page:'current'} ).eq(0).each( function (idx) {
  7059. // Internal data grab
  7060. var row = data[ idx ];
  7061. if ( row._detailsShow ) {
  7062. row._details.insertAfter( row.nTr );
  7063. }
  7064. } );
  7065. } );
  7066. // Column visibility change - update the colspan
  7067. api.on( colvisEvent, function ( e, ctx, idx, vis ) {
  7068. if ( settings !== ctx ) {
  7069. return;
  7070. }
  7071. // Update the colspan for the details rows (note, only if it already has
  7072. // a colspan)
  7073. var row, visible = _fnVisbleColumns( ctx );
  7074. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7075. row = data[i];
  7076. if ( row._details ) {
  7077. row._details.children('td[colspan]').attr('colspan', visible );
  7078. }
  7079. }
  7080. } );
  7081. // Table destroyed - nuke any child rows
  7082. api.on( destroyEvent, function ( e, ctx ) {
  7083. if ( settings !== ctx ) {
  7084. return;
  7085. }
  7086. for ( var i=0, ien=data.length ; i<ien ; i++ ) {
  7087. if ( data[i]._details ) {
  7088. __details_remove( api, i );
  7089. }
  7090. }
  7091. } );
  7092. }
  7093. };
  7094. // Strings for the method names to help minification
  7095. var _emp = '';
  7096. var _child_obj = _emp+'row().child';
  7097. var _child_mth = _child_obj+'()';
  7098. // data can be:
  7099. // tr
  7100. // string
  7101. // jQuery or array of any of the above
  7102. _api_register( _child_mth, function ( data, klass ) {
  7103. var ctx = this.context;
  7104. if ( data === undefined ) {
  7105. // get
  7106. return ctx.length && this.length ?
  7107. ctx[0].aoData[ this[0] ]._details :
  7108. undefined;
  7109. }
  7110. else if ( data === true ) {
  7111. // show
  7112. this.child.show();
  7113. }
  7114. else if ( data === false ) {
  7115. // remove
  7116. __details_remove( this );
  7117. }
  7118. else if ( ctx.length && this.length ) {
  7119. // set
  7120. __details_add( ctx[0], ctx[0].aoData[ this[0] ], data, klass );
  7121. }
  7122. return this;
  7123. } );
  7124. _api_register( [
  7125. _child_obj+'.show()',
  7126. _child_mth+'.show()' // only when `child()` was called with parameters (without
  7127. ], function ( show ) { // it returns an object and this method is not executed)
  7128. __details_display( this, true );
  7129. return this;
  7130. } );
  7131. _api_register( [
  7132. _child_obj+'.hide()',
  7133. _child_mth+'.hide()' // only when `child()` was called with parameters (without
  7134. ], function () { // it returns an object and this method is not executed)
  7135. __details_display( this, false );
  7136. return this;
  7137. } );
  7138. _api_register( [
  7139. _child_obj+'.remove()',
  7140. _child_mth+'.remove()' // only when `child()` was called with parameters (without
  7141. ], function () { // it returns an object and this method is not executed)
  7142. __details_remove( this );
  7143. return this;
  7144. } );
  7145. _api_register( _child_obj+'.isShown()', function () {
  7146. var ctx = this.context;
  7147. if ( ctx.length && this.length ) {
  7148. // _detailsShown as false or undefined will fall through to return false
  7149. return ctx[0].aoData[ this[0] ]._detailsShow || false;
  7150. }
  7151. return false;
  7152. } );
  7153. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7154. * Columns
  7155. *
  7156. * {integer} - column index (>=0 count from left, <0 count from right)
  7157. * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
  7158. * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
  7159. * "{string}:name" - column name
  7160. * "{string}" - jQuery selector on column header nodes
  7161. *
  7162. */
  7163. // can be an array of these items, comma separated list, or an array of comma
  7164. // separated lists
  7165. var __re_column_selector = /^([^:]+):(name|visIdx|visible)$/;
  7166. // r1 and r2 are redundant - but it means that the parameters match for the
  7167. // iterator callback in columns().data()
  7168. var __columnData = function ( settings, column, r1, r2, rows ) {
  7169. var a = [];
  7170. for ( var row=0, ien=rows.length ; row<ien ; row++ ) {
  7171. a.push( _fnGetCellData( settings, rows[row], column ) );
  7172. }
  7173. return a;
  7174. };
  7175. var __column_selector = function ( settings, selector, opts )
  7176. {
  7177. var
  7178. columns = settings.aoColumns,
  7179. names = _pluck( columns, 'sName' ),
  7180. nodes = _pluck( columns, 'nTh' );
  7181. var run = function ( s ) {
  7182. var selInt = _intVal( s );
  7183. // Selector - all
  7184. if ( s === '' ) {
  7185. return _range( columns.length );
  7186. }
  7187. // Selector - index
  7188. if ( selInt !== null ) {
  7189. return [ selInt >= 0 ?
  7190. selInt : // Count from left
  7191. columns.length + selInt // Count from right (+ because its a negative value)
  7192. ];
  7193. }
  7194. // Selector = function
  7195. if ( typeof s === 'function' ) {
  7196. var rows = _selector_row_indexes( settings, opts );
  7197. return $.map( columns, function (col, idx) {
  7198. return s(
  7199. idx,
  7200. __columnData( settings, idx, 0, 0, rows ),
  7201. nodes[ idx ]
  7202. ) ? idx : null;
  7203. } );
  7204. }
  7205. // jQuery or string selector
  7206. var match = typeof s === 'string' ?
  7207. s.match( __re_column_selector ) :
  7208. '';
  7209. if ( match ) {
  7210. switch( match[2] ) {
  7211. case 'visIdx':
  7212. case 'visible':
  7213. var idx = parseInt( match[1], 10 );
  7214. // Visible index given, convert to column index
  7215. if ( idx < 0 ) {
  7216. // Counting from the right
  7217. var visColumns = $.map( columns, function (col,i) {
  7218. return col.bVisible ? i : null;
  7219. } );
  7220. return [ visColumns[ visColumns.length + idx ] ];
  7221. }
  7222. // Counting from the left
  7223. return [ _fnVisibleToColumnIndex( settings, idx ) ];
  7224. case 'name':
  7225. // match by name. `names` is column index complete and in order
  7226. return $.map( names, function (name, i) {
  7227. return name === match[1] ? i : null;
  7228. } );
  7229. default:
  7230. return [];
  7231. }
  7232. }
  7233. // Cell in the table body
  7234. if ( s.nodeName && s._DT_CellIndex ) {
  7235. return [ s._DT_CellIndex.column ];
  7236. }
  7237. // jQuery selector on the TH elements for the columns
  7238. var jqResult = $( nodes )
  7239. .filter( s )
  7240. .map( function () {
  7241. return $.inArray( this, nodes ); // `nodes` is column index complete and in order
  7242. } )
  7243. .toArray();
  7244. if ( jqResult.length || ! s.nodeName ) {
  7245. return jqResult;
  7246. }
  7247. // Otherwise a node which might have a `dt-column` data attribute, or be
  7248. // a child or such an element
  7249. var host = $(s).closest('*[data-dt-column]');
  7250. return host.length ?
  7251. [ host.data('dt-column') ] :
  7252. [];
  7253. };
  7254. return _selector_run( 'column', selector, run, settings, opts );
  7255. };
  7256. var __setColumnVis = function ( settings, column, vis ) {
  7257. var
  7258. cols = settings.aoColumns,
  7259. col = cols[ column ],
  7260. data = settings.aoData,
  7261. row, cells, i, ien, tr;
  7262. // Get
  7263. if ( vis === undefined ) {
  7264. return col.bVisible;
  7265. }
  7266. // Set
  7267. // No change
  7268. if ( col.bVisible === vis ) {
  7269. return;
  7270. }
  7271. if ( vis ) {
  7272. // Insert column
  7273. // Need to decide if we should use appendChild or insertBefore
  7274. var insertBefore = $.inArray( true, _pluck(cols, 'bVisible'), column+1 );
  7275. for ( i=0, ien=data.length ; i<ien ; i++ ) {
  7276. tr = data[i].nTr;
  7277. cells = data[i].anCells;
  7278. if ( tr ) {
  7279. // insertBefore can act like appendChild if 2nd arg is null
  7280. tr.insertBefore( cells[ column ], cells[ insertBefore ] || null );
  7281. }
  7282. }
  7283. }
  7284. else {
  7285. // Remove column
  7286. $( _pluck( settings.aoData, 'anCells', column ) ).detach();
  7287. }
  7288. // Common actions
  7289. col.bVisible = vis;
  7290. _fnDrawHead( settings, settings.aoHeader );
  7291. _fnDrawHead( settings, settings.aoFooter );
  7292. // Update colspan for no records display. Child rows and extensions will use their own
  7293. // listeners to do this - only need to update the empty table item here
  7294. if ( ! settings.aiDisplay.length ) {
  7295. $(settings.nTBody).find('td[colspan]').attr('colspan', _fnVisbleColumns(settings));
  7296. }
  7297. _fnSaveState( settings );
  7298. };
  7299. _api_register( 'columns()', function ( selector, opts ) {
  7300. // argument shifting
  7301. if ( selector === undefined ) {
  7302. selector = '';
  7303. }
  7304. else if ( $.isPlainObject( selector ) ) {
  7305. opts = selector;
  7306. selector = '';
  7307. }
  7308. opts = _selector_opts( opts );
  7309. var inst = this.iterator( 'table', function ( settings ) {
  7310. return __column_selector( settings, selector, opts );
  7311. }, 1 );
  7312. // Want argument shifting here and in _row_selector?
  7313. inst.selector.cols = selector;
  7314. inst.selector.opts = opts;
  7315. return inst;
  7316. } );
  7317. _api_registerPlural( 'columns().header()', 'column().header()', function ( selector, opts ) {
  7318. return this.iterator( 'column', function ( settings, column ) {
  7319. return settings.aoColumns[column].nTh;
  7320. }, 1 );
  7321. } );
  7322. _api_registerPlural( 'columns().footer()', 'column().footer()', function ( selector, opts ) {
  7323. return this.iterator( 'column', function ( settings, column ) {
  7324. return settings.aoColumns[column].nTf;
  7325. }, 1 );
  7326. } );
  7327. _api_registerPlural( 'columns().data()', 'column().data()', function () {
  7328. return this.iterator( 'column-rows', __columnData, 1 );
  7329. } );
  7330. _api_registerPlural( 'columns().dataSrc()', 'column().dataSrc()', function () {
  7331. return this.iterator( 'column', function ( settings, column ) {
  7332. return settings.aoColumns[column].mData;
  7333. }, 1 );
  7334. } );
  7335. _api_registerPlural( 'columns().cache()', 'column().cache()', function ( type ) {
  7336. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7337. return _pluck_order( settings.aoData, rows,
  7338. type === 'search' ? '_aFilterData' : '_aSortData', column
  7339. );
  7340. }, 1 );
  7341. } );
  7342. _api_registerPlural( 'columns().nodes()', 'column().nodes()', function () {
  7343. return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) {
  7344. return _pluck_order( settings.aoData, rows, 'anCells', column ) ;
  7345. }, 1 );
  7346. } );
  7347. _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis, calc ) {
  7348. var ret = this.iterator( 'column', function ( settings, column ) {
  7349. if ( vis === undefined ) {
  7350. return settings.aoColumns[ column ].bVisible;
  7351. } // else
  7352. __setColumnVis( settings, column, vis );
  7353. } );
  7354. // Group the column visibility changes
  7355. if ( vis !== undefined ) {
  7356. // Second loop once the first is done for events
  7357. this.iterator( 'column', function ( settings, column ) {
  7358. _fnCallbackFire( settings, null, 'column-visibility', [settings, column, vis, calc] );
  7359. } );
  7360. if ( calc === undefined || calc ) {
  7361. this.columns.adjust();
  7362. }
  7363. }
  7364. return ret;
  7365. } );
  7366. _api_registerPlural( 'columns().indexes()', 'column().index()', function ( type ) {
  7367. return this.iterator( 'column', function ( settings, column ) {
  7368. return type === 'visible' ?
  7369. _fnColumnIndexToVisible( settings, column ) :
  7370. column;
  7371. }, 1 );
  7372. } );
  7373. _api_register( 'columns.adjust()', function () {
  7374. return this.iterator( 'table', function ( settings ) {
  7375. _fnAdjustColumnSizing( settings );
  7376. }, 1 );
  7377. } );
  7378. _api_register( 'column.index()', function ( type, idx ) {
  7379. if ( this.context.length !== 0 ) {
  7380. var ctx = this.context[0];
  7381. if ( type === 'fromVisible' || type === 'toData' ) {
  7382. return _fnVisibleToColumnIndex( ctx, idx );
  7383. }
  7384. else if ( type === 'fromData' || type === 'toVisible' ) {
  7385. return _fnColumnIndexToVisible( ctx, idx );
  7386. }
  7387. }
  7388. } );
  7389. _api_register( 'column()', function ( selector, opts ) {
  7390. return _selector_first( this.columns( selector, opts ) );
  7391. } );
  7392. var __cell_selector = function ( settings, selector, opts )
  7393. {
  7394. var data = settings.aoData;
  7395. var rows = _selector_row_indexes( settings, opts );
  7396. var cells = _removeEmpty( _pluck_order( data, rows, 'anCells' ) );
  7397. var allCells = $( [].concat.apply([], cells) );
  7398. var row;
  7399. var columns = settings.aoColumns.length;
  7400. var a, i, ien, j, o, host;
  7401. var run = function ( s ) {
  7402. var fnSelector = typeof s === 'function';
  7403. if ( s === null || s === undefined || fnSelector ) {
  7404. // All cells and function selectors
  7405. a = [];
  7406. for ( i=0, ien=rows.length ; i<ien ; i++ ) {
  7407. row = rows[i];
  7408. for ( j=0 ; j<columns ; j++ ) {
  7409. o = {
  7410. row: row,
  7411. column: j
  7412. };
  7413. if ( fnSelector ) {
  7414. // Selector - function
  7415. host = data[ row ];
  7416. if ( s( o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null ) ) {
  7417. a.push( o );
  7418. }
  7419. }
  7420. else {
  7421. // Selector - all
  7422. a.push( o );
  7423. }
  7424. }
  7425. }
  7426. return a;
  7427. }
  7428. // Selector - index
  7429. if ( $.isPlainObject( s ) ) {
  7430. // Valid cell index and its in the array of selectable rows
  7431. return s.column !== undefined && s.row !== undefined && $.inArray( s.row, rows ) !== -1 ?
  7432. [s] :
  7433. [];
  7434. }
  7435. // Selector - jQuery filtered cells
  7436. var jqResult = allCells
  7437. .filter( s )
  7438. .map( function (i, el) {
  7439. return { // use a new object, in case someone changes the values
  7440. row: el._DT_CellIndex.row,
  7441. column: el._DT_CellIndex.column
  7442. };
  7443. } )
  7444. .toArray();
  7445. if ( jqResult.length || ! s.nodeName ) {
  7446. return jqResult;
  7447. }
  7448. // Otherwise the selector is a node, and there is one last option - the
  7449. // element might be a child of an element which has dt-row and dt-column
  7450. // data attributes
  7451. host = $(s).closest('*[data-dt-row]');
  7452. return host.length ?
  7453. [ {
  7454. row: host.data('dt-row'),
  7455. column: host.data('dt-column')
  7456. } ] :
  7457. [];
  7458. };
  7459. return _selector_run( 'cell', selector, run, settings, opts );
  7460. };
  7461. _api_register( 'cells()', function ( rowSelector, columnSelector, opts ) {
  7462. // Argument shifting
  7463. if ( $.isPlainObject( rowSelector ) ) {
  7464. // Indexes
  7465. if ( rowSelector.row === undefined ) {
  7466. // Selector options in first parameter
  7467. opts = rowSelector;
  7468. rowSelector = null;
  7469. }
  7470. else {
  7471. // Cell index objects in first parameter
  7472. opts = columnSelector;
  7473. columnSelector = null;
  7474. }
  7475. }
  7476. if ( $.isPlainObject( columnSelector ) ) {
  7477. opts = columnSelector;
  7478. columnSelector = null;
  7479. }
  7480. // Cell selector
  7481. if ( columnSelector === null || columnSelector === undefined ) {
  7482. return this.iterator( 'table', function ( settings ) {
  7483. return __cell_selector( settings, rowSelector, _selector_opts( opts ) );
  7484. } );
  7485. }
  7486. // Row + column selector
  7487. var columns = this.columns( columnSelector );
  7488. var rows = this.rows( rowSelector );
  7489. var a, i, ien, j, jen;
  7490. this.iterator( 'table', function ( settings, idx ) {
  7491. a = [];
  7492. for ( i=0, ien=rows[idx].length ; i<ien ; i++ ) {
  7493. for ( j=0, jen=columns[idx].length ; j<jen ; j++ ) {
  7494. a.push( {
  7495. row: rows[idx][i],
  7496. column: columns[idx][j]
  7497. } );
  7498. }
  7499. }
  7500. }, 1 );
  7501. // Now pass through the cell selector for options
  7502. var cells = this.cells( a, opts );
  7503. $.extend( cells.selector, {
  7504. cols: columnSelector,
  7505. rows: rowSelector,
  7506. opts: opts
  7507. } );
  7508. return cells;
  7509. } );
  7510. _api_registerPlural( 'cells().nodes()', 'cell().node()', function () {
  7511. return this.iterator( 'cell', function ( settings, row, column ) {
  7512. var data = settings.aoData[ row ];
  7513. return data && data.anCells ?
  7514. data.anCells[ column ] :
  7515. undefined;
  7516. }, 1 );
  7517. } );
  7518. _api_register( 'cells().data()', function () {
  7519. return this.iterator( 'cell', function ( settings, row, column ) {
  7520. return _fnGetCellData( settings, row, column );
  7521. }, 1 );
  7522. } );
  7523. _api_registerPlural( 'cells().cache()', 'cell().cache()', function ( type ) {
  7524. type = type === 'search' ? '_aFilterData' : '_aSortData';
  7525. return this.iterator( 'cell', function ( settings, row, column ) {
  7526. return settings.aoData[ row ][ type ][ column ];
  7527. }, 1 );
  7528. } );
  7529. _api_registerPlural( 'cells().render()', 'cell().render()', function ( type ) {
  7530. return this.iterator( 'cell', function ( settings, row, column ) {
  7531. return _fnGetCellData( settings, row, column, type );
  7532. }, 1 );
  7533. } );
  7534. _api_registerPlural( 'cells().indexes()', 'cell().index()', function () {
  7535. return this.iterator( 'cell', function ( settings, row, column ) {
  7536. return {
  7537. row: row,
  7538. column: column,
  7539. columnVisible: _fnColumnIndexToVisible( settings, column )
  7540. };
  7541. }, 1 );
  7542. } );
  7543. _api_registerPlural( 'cells().invalidate()', 'cell().invalidate()', function ( src ) {
  7544. return this.iterator( 'cell', function ( settings, row, column ) {
  7545. _fnInvalidate( settings, row, src, column );
  7546. } );
  7547. } );
  7548. _api_register( 'cell()', function ( rowSelector, columnSelector, opts ) {
  7549. return _selector_first( this.cells( rowSelector, columnSelector, opts ) );
  7550. } );
  7551. _api_register( 'cell().data()', function ( data ) {
  7552. var ctx = this.context;
  7553. var cell = this[0];
  7554. if ( data === undefined ) {
  7555. // Get
  7556. return ctx.length && cell.length ?
  7557. _fnGetCellData( ctx[0], cell[0].row, cell[0].column ) :
  7558. undefined;
  7559. }
  7560. // Set
  7561. _fnSetCellData( ctx[0], cell[0].row, cell[0].column, data );
  7562. _fnInvalidate( ctx[0], cell[0].row, 'data', cell[0].column );
  7563. return this;
  7564. } );
  7565. /**
  7566. * Get current ordering (sorting) that has been applied to the table.
  7567. *
  7568. * @returns {array} 2D array containing the sorting information for the first
  7569. * table in the current context. Each element in the parent array represents
  7570. * a column being sorted upon (i.e. multi-sorting with two columns would have
  7571. * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
  7572. * the column index that the sorting condition applies to, the second is the
  7573. * direction of the sort (`desc` or `asc`) and, optionally, the third is the
  7574. * index of the sorting order from the `column.sorting` initialisation array.
  7575. *//**
  7576. * Set the ordering for the table.
  7577. *
  7578. * @param {integer} order Column index to sort upon.
  7579. * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
  7580. * @returns {DataTables.Api} this
  7581. *//**
  7582. * Set the ordering for the table.
  7583. *
  7584. * @param {array} order 1D array of sorting information to be applied.
  7585. * @param {array} [...] Optional additional sorting conditions
  7586. * @returns {DataTables.Api} this
  7587. *//**
  7588. * Set the ordering for the table.
  7589. *
  7590. * @param {array} order 2D array of sorting information to be applied.
  7591. * @returns {DataTables.Api} this
  7592. */
  7593. _api_register( 'order()', function ( order, dir ) {
  7594. var ctx = this.context;
  7595. if ( order === undefined ) {
  7596. // get
  7597. return ctx.length !== 0 ?
  7598. ctx[0].aaSorting :
  7599. undefined;
  7600. }
  7601. // set
  7602. if ( typeof order === 'number' ) {
  7603. // Simple column / direction passed in
  7604. order = [ [ order, dir ] ];
  7605. }
  7606. else if ( order.length && ! $.isArray( order[0] ) ) {
  7607. // Arguments passed in (list of 1D arrays)
  7608. order = Array.prototype.slice.call( arguments );
  7609. }
  7610. // otherwise a 2D array was passed in
  7611. return this.iterator( 'table', function ( settings ) {
  7612. settings.aaSorting = order.slice();
  7613. } );
  7614. } );
  7615. /**
  7616. * Attach a sort listener to an element for a given column
  7617. *
  7618. * @param {node|jQuery|string} node Identifier for the element(s) to attach the
  7619. * listener to. This can take the form of a single DOM node, a jQuery
  7620. * collection of nodes or a jQuery selector which will identify the node(s).
  7621. * @param {integer} column the column that a click on this node will sort on
  7622. * @param {function} [callback] callback function when sort is run
  7623. * @returns {DataTables.Api} this
  7624. */
  7625. _api_register( 'order.listener()', function ( node, column, callback ) {
  7626. return this.iterator( 'table', function ( settings ) {
  7627. _fnSortAttachListener( settings, node, column, callback );
  7628. } );
  7629. } );
  7630. _api_register( 'order.fixed()', function ( set ) {
  7631. if ( ! set ) {
  7632. var ctx = this.context;
  7633. var fixed = ctx.length ?
  7634. ctx[0].aaSortingFixed :
  7635. undefined;
  7636. return $.isArray( fixed ) ?
  7637. { pre: fixed } :
  7638. fixed;
  7639. }
  7640. return this.iterator( 'table', function ( settings ) {
  7641. settings.aaSortingFixed = $.extend( true, {}, set );
  7642. } );
  7643. } );
  7644. // Order by the selected column(s)
  7645. _api_register( [
  7646. 'columns().order()',
  7647. 'column().order()'
  7648. ], function ( dir ) {
  7649. var that = this;
  7650. return this.iterator( 'table', function ( settings, i ) {
  7651. var sort = [];
  7652. $.each( that[i], function (j, col) {
  7653. sort.push( [ col, dir ] );
  7654. } );
  7655. settings.aaSorting = sort;
  7656. } );
  7657. } );
  7658. _api_register( 'search()', function ( input, regex, smart, caseInsen ) {
  7659. var ctx = this.context;
  7660. if ( input === undefined ) {
  7661. // get
  7662. return ctx.length !== 0 ?
  7663. ctx[0].oPreviousSearch.sSearch :
  7664. undefined;
  7665. }
  7666. // set
  7667. return this.iterator( 'table', function ( settings ) {
  7668. if ( ! settings.oFeatures.bFilter ) {
  7669. return;
  7670. }
  7671. _fnFilterComplete( settings, $.extend( {}, settings.oPreviousSearch, {
  7672. "sSearch": input+"",
  7673. "bRegex": regex === null ? false : regex,
  7674. "bSmart": smart === null ? true : smart,
  7675. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7676. } ), 1 );
  7677. } );
  7678. } );
  7679. _api_registerPlural(
  7680. 'columns().search()',
  7681. 'column().search()',
  7682. function ( input, regex, smart, caseInsen ) {
  7683. return this.iterator( 'column', function ( settings, column ) {
  7684. var preSearch = settings.aoPreSearchCols;
  7685. if ( input === undefined ) {
  7686. // get
  7687. return preSearch[ column ].sSearch;
  7688. }
  7689. // set
  7690. if ( ! settings.oFeatures.bFilter ) {
  7691. return;
  7692. }
  7693. $.extend( preSearch[ column ], {
  7694. "sSearch": input+"",
  7695. "bRegex": regex === null ? false : regex,
  7696. "bSmart": smart === null ? true : smart,
  7697. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7698. } );
  7699. _fnFilterComplete( settings, settings.oPreviousSearch, 1 );
  7700. } );
  7701. }
  7702. );
  7703. /*
  7704. * State API methods
  7705. */
  7706. _api_register( 'state()', function () {
  7707. return this.context.length ?
  7708. this.context[0].oSavedState :
  7709. null;
  7710. } );
  7711. _api_register( 'state.clear()', function () {
  7712. return this.iterator( 'table', function ( settings ) {
  7713. // Save an empty object
  7714. settings.fnStateSaveCallback.call( settings.oInstance, settings, {} );
  7715. } );
  7716. } );
  7717. _api_register( 'state.loaded()', function () {
  7718. return this.context.length ?
  7719. this.context[0].oLoadedState :
  7720. null;
  7721. } );
  7722. _api_register( 'state.save()', function () {
  7723. return this.iterator( 'table', function ( settings ) {
  7724. _fnSaveState( settings );
  7725. } );
  7726. } );
  7727. /**
  7728. * Provide a common method for plug-ins to check the version of DataTables being
  7729. * used, in order to ensure compatibility.
  7730. *
  7731. * @param {string} version Version string to check for, in the format "X.Y.Z".
  7732. * Note that the formats "X" and "X.Y" are also acceptable.
  7733. * @returns {boolean} true if this version of DataTables is greater or equal to
  7734. * the required version, or false if this version of DataTales is not
  7735. * suitable
  7736. * @static
  7737. * @dtopt API-Static
  7738. *
  7739. * @example
  7740. * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
  7741. */
  7742. DataTable.versionCheck = DataTable.fnVersionCheck = function( version )
  7743. {
  7744. var aThis = DataTable.version.split('.');
  7745. var aThat = version.split('.');
  7746. var iThis, iThat;
  7747. for ( var i=0, iLen=aThat.length ; i<iLen ; i++ ) {
  7748. iThis = parseInt( aThis[i], 10 ) || 0;
  7749. iThat = parseInt( aThat[i], 10 ) || 0;
  7750. // Parts are the same, keep comparing
  7751. if (iThis === iThat) {
  7752. continue;
  7753. }
  7754. // Parts are different, return immediately
  7755. return iThis > iThat;
  7756. }
  7757. return true;
  7758. };
  7759. /**
  7760. * Check if a `<table>` node is a DataTable table already or not.
  7761. *
  7762. * @param {node|jquery|string} table Table node, jQuery object or jQuery
  7763. * selector for the table to test. Note that if more than more than one
  7764. * table is passed on, only the first will be checked
  7765. * @returns {boolean} true the table given is a DataTable, or false otherwise
  7766. * @static
  7767. * @dtopt API-Static
  7768. *
  7769. * @example
  7770. * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
  7771. * $('#example').dataTable();
  7772. * }
  7773. */
  7774. DataTable.isDataTable = DataTable.fnIsDataTable = function ( table )
  7775. {
  7776. var t = $(table).get(0);
  7777. var is = false;
  7778. if ( table instanceof DataTable.Api ) {
  7779. return true;
  7780. }
  7781. $.each( DataTable.settings, function (i, o) {
  7782. var head = o.nScrollHead ? $('table', o.nScrollHead)[0] : null;
  7783. var foot = o.nScrollFoot ? $('table', o.nScrollFoot)[0] : null;
  7784. if ( o.nTable === t || head === t || foot === t ) {
  7785. is = true;
  7786. }
  7787. } );
  7788. return is;
  7789. };
  7790. /**
  7791. * Get all DataTable tables that have been initialised - optionally you can
  7792. * select to get only currently visible tables.
  7793. *
  7794. * @param {boolean} [visible=false] Flag to indicate if you want all (default)
  7795. * or visible tables only.
  7796. * @returns {array} Array of `table` nodes (not DataTable instances) which are
  7797. * DataTables
  7798. * @static
  7799. * @dtopt API-Static
  7800. *
  7801. * @example
  7802. * $.each( $.fn.dataTable.tables(true), function () {
  7803. * $(table).DataTable().columns.adjust();
  7804. * } );
  7805. */
  7806. DataTable.tables = DataTable.fnTables = function ( visible )
  7807. {
  7808. var api = false;
  7809. if ( $.isPlainObject( visible ) ) {
  7810. api = visible.api;
  7811. visible = visible.visible;
  7812. }
  7813. var a = $.map( DataTable.settings, function (o) {
  7814. if ( !visible || (visible && $(o.nTable).is(':visible')) ) {
  7815. return o.nTable;
  7816. }
  7817. } );
  7818. return api ?
  7819. new _Api( a ) :
  7820. a;
  7821. };
  7822. /**
  7823. * Convert from camel case parameters to Hungarian notation. This is made public
  7824. * for the extensions to provide the same ability as DataTables core to accept
  7825. * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
  7826. * parameters.
  7827. *
  7828. * @param {object} src The model object which holds all parameters that can be
  7829. * mapped.
  7830. * @param {object} user The object to convert from camel case to Hungarian.
  7831. * @param {boolean} force When set to `true`, properties which already have a
  7832. * Hungarian value in the `user` object will be overwritten. Otherwise they
  7833. * won't be.
  7834. */
  7835. DataTable.camelToHungarian = _fnCamelToHungarian;
  7836. /**
  7837. *
  7838. */
  7839. _api_register( '$()', function ( selector, opts ) {
  7840. var
  7841. rows = this.rows( opts ).nodes(), // Get all rows
  7842. jqRows = $(rows);
  7843. return $( [].concat(
  7844. jqRows.filter( selector ).toArray(),
  7845. jqRows.find( selector ).toArray()
  7846. ) );
  7847. } );
  7848. // jQuery functions to operate on the tables
  7849. $.each( [ 'on', 'one', 'off' ], function (i, key) {
  7850. _api_register( key+'()', function ( /* event, handler */ ) {
  7851. var args = Array.prototype.slice.call(arguments);
  7852. // Add the `dt` namespace automatically if it isn't already present
  7853. args[0] = $.map( args[0].split( /\s/ ), function ( e ) {
  7854. return ! e.match(/\.dt\b/) ?
  7855. e+'.dt' :
  7856. e;
  7857. } ).join( ' ' );
  7858. var inst = $( this.tables().nodes() );
  7859. inst[key].apply( inst, args );
  7860. return this;
  7861. } );
  7862. } );
  7863. _api_register( 'clear()', function () {
  7864. return this.iterator( 'table', function ( settings ) {
  7865. _fnClearTable( settings );
  7866. } );
  7867. } );
  7868. _api_register( 'settings()', function () {
  7869. return new _Api( this.context, this.context );
  7870. } );
  7871. _api_register( 'init()', function () {
  7872. var ctx = this.context;
  7873. return ctx.length ? ctx[0].oInit : null;
  7874. } );
  7875. _api_register( 'data()', function () {
  7876. return this.iterator( 'table', function ( settings ) {
  7877. return _pluck( settings.aoData, '_aData' );
  7878. } ).flatten();
  7879. } );
  7880. _api_register( 'destroy()', function ( remove ) {
  7881. remove = remove || false;
  7882. return this.iterator( 'table', function ( settings ) {
  7883. var orig = settings.nTableWrapper.parentNode;
  7884. var classes = settings.oClasses;
  7885. var table = settings.nTable;
  7886. var tbody = settings.nTBody;
  7887. var thead = settings.nTHead;
  7888. var tfoot = settings.nTFoot;
  7889. var jqTable = $(table);
  7890. var jqTbody = $(tbody);
  7891. var jqWrapper = $(settings.nTableWrapper);
  7892. var rows = $.map( settings.aoData, function (r) { return r.nTr; } );
  7893. var i, ien;
  7894. // Flag to note that the table is currently being destroyed - no action
  7895. // should be taken
  7896. settings.bDestroying = true;
  7897. // Fire off the destroy callbacks for plug-ins etc
  7898. _fnCallbackFire( settings, "aoDestroyCallback", "destroy", [settings] );
  7899. // If not being removed from the document, make all columns visible
  7900. if ( ! remove ) {
  7901. new _Api( settings ).columns().visible( true );
  7902. }
  7903. // Blitz all `DT` namespaced events (these are internal events, the
  7904. // lowercase, `dt` events are user subscribed and they are responsible
  7905. // for removing them
  7906. jqWrapper.off('.DT').find(':not(tbody *)').off('.DT');
  7907. $(window).off('.DT-'+settings.sInstance);
  7908. // When scrolling we had to break the table up - restore it
  7909. if ( table != thead.parentNode ) {
  7910. jqTable.children('thead').detach();
  7911. jqTable.append( thead );
  7912. }
  7913. if ( tfoot && table != tfoot.parentNode ) {
  7914. jqTable.children('tfoot').detach();
  7915. jqTable.append( tfoot );
  7916. }
  7917. settings.aaSorting = [];
  7918. settings.aaSortingFixed = [];
  7919. _fnSortingClasses( settings );
  7920. $( rows ).removeClass( settings.asStripeClasses.join(' ') );
  7921. $('th, td', thead).removeClass( classes.sSortable+' '+
  7922. classes.sSortableAsc+' '+classes.sSortableDesc+' '+classes.sSortableNone
  7923. );
  7924. // Add the TR elements back into the table in their original order
  7925. jqTbody.children().detach();
  7926. jqTbody.append( rows );
  7927. // Remove the DataTables generated nodes, events and classes
  7928. var removedMethod = remove ? 'remove' : 'detach';
  7929. jqTable[ removedMethod ]();
  7930. jqWrapper[ removedMethod ]();
  7931. // If we need to reattach the table to the document
  7932. if ( ! remove && orig ) {
  7933. // insertBefore acts like appendChild if !arg[1]
  7934. orig.insertBefore( table, settings.nTableReinsertBefore );
  7935. // Restore the width of the original table - was read from the style property,
  7936. // so we can restore directly to that
  7937. jqTable
  7938. .css( 'width', settings.sDestroyWidth )
  7939. .removeClass( classes.sTable );
  7940. // If the were originally stripe classes - then we add them back here.
  7941. // Note this is not fool proof (for example if not all rows had stripe
  7942. // classes - but it's a good effort without getting carried away
  7943. ien = settings.asDestroyStripes.length;
  7944. if ( ien ) {
  7945. jqTbody.children().each( function (i) {
  7946. $(this).addClass( settings.asDestroyStripes[i % ien] );
  7947. } );
  7948. }
  7949. }
  7950. /* Remove the settings object from the settings array */
  7951. var idx = $.inArray( settings, DataTable.settings );
  7952. if ( idx !== -1 ) {
  7953. DataTable.settings.splice( idx, 1 );
  7954. }
  7955. } );
  7956. } );
  7957. // Add the `every()` method for rows, columns and cells in a compact form
  7958. $.each( [ 'column', 'row', 'cell' ], function ( i, type ) {
  7959. _api_register( type+'s().every()', function ( fn ) {
  7960. var opts = this.selector.opts;
  7961. var api = this;
  7962. return this.iterator( type, function ( settings, arg1, arg2, arg3, arg4 ) {
  7963. // Rows and columns:
  7964. // arg1 - index
  7965. // arg2 - table counter
  7966. // arg3 - loop counter
  7967. // arg4 - undefined
  7968. // Cells:
  7969. // arg1 - row index
  7970. // arg2 - column index
  7971. // arg3 - table counter
  7972. // arg4 - loop counter
  7973. fn.call(
  7974. api[ type ](
  7975. arg1,
  7976. type==='cell' ? arg2 : opts,
  7977. type==='cell' ? opts : undefined
  7978. ),
  7979. arg1, arg2, arg3, arg4
  7980. );
  7981. } );
  7982. } );
  7983. } );
  7984. // i18n method for extensions to be able to use the language object from the
  7985. // DataTable
  7986. _api_register( 'i18n()', function ( token, def, plural ) {
  7987. var ctx = this.context[0];
  7988. var resolved = _fnGetObjectDataFn( token )( ctx.oLanguage );
  7989. if ( resolved === undefined ) {
  7990. resolved = def;
  7991. }
  7992. if ( plural !== undefined && $.isPlainObject( resolved ) ) {
  7993. resolved = resolved[ plural ] !== undefined ?
  7994. resolved[ plural ] :
  7995. resolved._;
  7996. }
  7997. return resolved.replace( '%d', plural ); // nb: plural might be undefined,
  7998. } );
  7999. /**
  8000. * Version string for plug-ins to check compatibility. Allowed format is
  8001. * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
  8002. * only for non-release builds. See http://semver.org/ for more information.
  8003. * @member
  8004. * @type string
  8005. * @default Version number
  8006. */
  8007. DataTable.version = "1.10.18";
  8008. /**
  8009. * Private data store, containing all of the settings objects that are
  8010. * created for the tables on a given page.
  8011. *
  8012. * Note that the `DataTable.settings` object is aliased to
  8013. * `jQuery.fn.dataTableExt` through which it may be accessed and
  8014. * manipulated, or `jQuery.fn.dataTable.settings`.
  8015. * @member
  8016. * @type array
  8017. * @default []
  8018. * @private
  8019. */
  8020. DataTable.settings = [];
  8021. /**
  8022. * Object models container, for the various models that DataTables has
  8023. * available to it. These models define the objects that are used to hold
  8024. * the active state and configuration of the table.
  8025. * @namespace
  8026. */
  8027. DataTable.models = {};
  8028. /**
  8029. * Template object for the way in which DataTables holds information about
  8030. * search information for the global filter and individual column filters.
  8031. * @namespace
  8032. */
  8033. DataTable.models.oSearch = {
  8034. /**
  8035. * Flag to indicate if the filtering should be case insensitive or not
  8036. * @type boolean
  8037. * @default true
  8038. */
  8039. "bCaseInsensitive": true,
  8040. /**
  8041. * Applied search term
  8042. * @type string
  8043. * @default <i>Empty string</i>
  8044. */
  8045. "sSearch": "",
  8046. /**
  8047. * Flag to indicate if the search term should be interpreted as a
  8048. * regular expression (true) or not (false) and therefore and special
  8049. * regex characters escaped.
  8050. * @type boolean
  8051. * @default false
  8052. */
  8053. "bRegex": false,
  8054. /**
  8055. * Flag to indicate if DataTables is to use its smart filtering or not.
  8056. * @type boolean
  8057. * @default true
  8058. */
  8059. "bSmart": true
  8060. };
  8061. /**
  8062. * Template object for the way in which DataTables holds information about
  8063. * each individual row. This is the object format used for the settings
  8064. * aoData array.
  8065. * @namespace
  8066. */
  8067. DataTable.models.oRow = {
  8068. /**
  8069. * TR element for the row
  8070. * @type node
  8071. * @default null
  8072. */
  8073. "nTr": null,
  8074. /**
  8075. * Array of TD elements for each row. This is null until the row has been
  8076. * created.
  8077. * @type array nodes
  8078. * @default []
  8079. */
  8080. "anCells": null,
  8081. /**
  8082. * Data object from the original data source for the row. This is either
  8083. * an array if using the traditional form of DataTables, or an object if
  8084. * using mData options. The exact type will depend on the passed in
  8085. * data from the data source, or will be an array if using DOM a data
  8086. * source.
  8087. * @type array|object
  8088. * @default []
  8089. */
  8090. "_aData": [],
  8091. /**
  8092. * Sorting data cache - this array is ostensibly the same length as the
  8093. * number of columns (although each index is generated only as it is
  8094. * needed), and holds the data that is used for sorting each column in the
  8095. * row. We do this cache generation at the start of the sort in order that
  8096. * the formatting of the sort data need be done only once for each cell
  8097. * per sort. This array should not be read from or written to by anything
  8098. * other than the master sorting methods.
  8099. * @type array
  8100. * @default null
  8101. * @private
  8102. */
  8103. "_aSortData": null,
  8104. /**
  8105. * Per cell filtering data cache. As per the sort data cache, used to
  8106. * increase the performance of the filtering in DataTables
  8107. * @type array
  8108. * @default null
  8109. * @private
  8110. */
  8111. "_aFilterData": null,
  8112. /**
  8113. * Filtering data cache. This is the same as the cell filtering cache, but
  8114. * in this case a string rather than an array. This is easily computed with
  8115. * a join on `_aFilterData`, but is provided as a cache so the join isn't
  8116. * needed on every search (memory traded for performance)
  8117. * @type array
  8118. * @default null
  8119. * @private
  8120. */
  8121. "_sFilterRow": null,
  8122. /**
  8123. * Cache of the class name that DataTables has applied to the row, so we
  8124. * can quickly look at this variable rather than needing to do a DOM check
  8125. * on className for the nTr property.
  8126. * @type string
  8127. * @default <i>Empty string</i>
  8128. * @private
  8129. */
  8130. "_sRowStripe": "",
  8131. /**
  8132. * Denote if the original data source was from the DOM, or the data source
  8133. * object. This is used for invalidating data, so DataTables can
  8134. * automatically read data from the original source, unless uninstructed
  8135. * otherwise.
  8136. * @type string
  8137. * @default null
  8138. * @private
  8139. */
  8140. "src": null,
  8141. /**
  8142. * Index in the aoData array. This saves an indexOf lookup when we have the
  8143. * object, but want to know the index
  8144. * @type integer
  8145. * @default -1
  8146. * @private
  8147. */
  8148. "idx": -1
  8149. };
  8150. /**
  8151. * Template object for the column information object in DataTables. This object
  8152. * is held in the settings aoColumns array and contains all the information that
  8153. * DataTables needs about each individual column.
  8154. *
  8155. * Note that this object is related to {@link DataTable.defaults.column}
  8156. * but this one is the internal data store for DataTables's cache of columns.
  8157. * It should NOT be manipulated outside of DataTables. Any configuration should
  8158. * be done through the initialisation options.
  8159. * @namespace
  8160. */
  8161. DataTable.models.oColumn = {
  8162. /**
  8163. * Column index. This could be worked out on-the-fly with $.inArray, but it
  8164. * is faster to just hold it as a variable
  8165. * @type integer
  8166. * @default null
  8167. */
  8168. "idx": null,
  8169. /**
  8170. * A list of the columns that sorting should occur on when this column
  8171. * is sorted. That this property is an array allows multi-column sorting
  8172. * to be defined for a column (for example first name / last name columns
  8173. * would benefit from this). The values are integers pointing to the
  8174. * columns to be sorted on (typically it will be a single integer pointing
  8175. * at itself, but that doesn't need to be the case).
  8176. * @type array
  8177. */
  8178. "aDataSort": null,
  8179. /**
  8180. * Define the sorting directions that are applied to the column, in sequence
  8181. * as the column is repeatedly sorted upon - i.e. the first value is used
  8182. * as the sorting direction when the column if first sorted (clicked on).
  8183. * Sort it again (click again) and it will move on to the next index.
  8184. * Repeat until loop.
  8185. * @type array
  8186. */
  8187. "asSorting": null,
  8188. /**
  8189. * Flag to indicate if the column is searchable, and thus should be included
  8190. * in the filtering or not.
  8191. * @type boolean
  8192. */
  8193. "bSearchable": null,
  8194. /**
  8195. * Flag to indicate if the column is sortable or not.
  8196. * @type boolean
  8197. */
  8198. "bSortable": null,
  8199. /**
  8200. * Flag to indicate if the column is currently visible in the table or not
  8201. * @type boolean
  8202. */
  8203. "bVisible": null,
  8204. /**
  8205. * Store for manual type assignment using the `column.type` option. This
  8206. * is held in store so we can manipulate the column's `sType` property.
  8207. * @type string
  8208. * @default null
  8209. * @private
  8210. */
  8211. "_sManualType": null,
  8212. /**
  8213. * Flag to indicate if HTML5 data attributes should be used as the data
  8214. * source for filtering or sorting. True is either are.
  8215. * @type boolean
  8216. * @default false
  8217. * @private
  8218. */
  8219. "_bAttrSrc": false,
  8220. /**
  8221. * Developer definable function that is called whenever a cell is created (Ajax source,
  8222. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  8223. * allowing you to modify the DOM element (add background colour for example) when the
  8224. * element is available.
  8225. * @type function
  8226. * @param {element} nTd The TD node that has been created
  8227. * @param {*} sData The Data for the cell
  8228. * @param {array|object} oData The data for the whole row
  8229. * @param {int} iRow The row index for the aoData data store
  8230. * @default null
  8231. */
  8232. "fnCreatedCell": null,
  8233. /**
  8234. * Function to get data from a cell in a column. You should <b>never</b>
  8235. * access data directly through _aData internally in DataTables - always use
  8236. * the method attached to this property. It allows mData to function as
  8237. * required. This function is automatically assigned by the column
  8238. * initialisation method
  8239. * @type function
  8240. * @param {array|object} oData The data array/object for the array
  8241. * (i.e. aoData[]._aData)
  8242. * @param {string} sSpecific The specific data type you want to get -
  8243. * 'display', 'type' 'filter' 'sort'
  8244. * @returns {*} The data for the cell from the given row's data
  8245. * @default null
  8246. */
  8247. "fnGetData": null,
  8248. /**
  8249. * Function to set data for a cell in the column. You should <b>never</b>
  8250. * set the data directly to _aData internally in DataTables - always use
  8251. * this method. It allows mData to function as required. This function
  8252. * is automatically assigned by the column initialisation method
  8253. * @type function
  8254. * @param {array|object} oData The data array/object for the array
  8255. * (i.e. aoData[]._aData)
  8256. * @param {*} sValue Value to set
  8257. * @default null
  8258. */
  8259. "fnSetData": null,
  8260. /**
  8261. * Property to read the value for the cells in the column from the data
  8262. * source array / object. If null, then the default content is used, if a
  8263. * function is given then the return from the function is used.
  8264. * @type function|int|string|null
  8265. * @default null
  8266. */
  8267. "mData": null,
  8268. /**
  8269. * Partner property to mData which is used (only when defined) to get
  8270. * the data - i.e. it is basically the same as mData, but without the
  8271. * 'set' option, and also the data fed to it is the result from mData.
  8272. * This is the rendering method to match the data method of mData.
  8273. * @type function|int|string|null
  8274. * @default null
  8275. */
  8276. "mRender": null,
  8277. /**
  8278. * Unique header TH/TD element for this column - this is what the sorting
  8279. * listener is attached to (if sorting is enabled.)
  8280. * @type node
  8281. * @default null
  8282. */
  8283. "nTh": null,
  8284. /**
  8285. * Unique footer TH/TD element for this column (if there is one). Not used
  8286. * in DataTables as such, but can be used for plug-ins to reference the
  8287. * footer for each column.
  8288. * @type node
  8289. * @default null
  8290. */
  8291. "nTf": null,
  8292. /**
  8293. * The class to apply to all TD elements in the table's TBODY for the column
  8294. * @type string
  8295. * @default null
  8296. */
  8297. "sClass": null,
  8298. /**
  8299. * When DataTables calculates the column widths to assign to each column,
  8300. * it finds the longest string in each column and then constructs a
  8301. * temporary table and reads the widths from that. The problem with this
  8302. * is that "mmm" is much wider then "iiii", but the latter is a longer
  8303. * string - thus the calculation can go wrong (doing it properly and putting
  8304. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  8305. * a "work around" we provide this option. It will append its value to the
  8306. * text that is found to be the longest string for the column - i.e. padding.
  8307. * @type string
  8308. */
  8309. "sContentPadding": null,
  8310. /**
  8311. * Allows a default value to be given for a column's data, and will be used
  8312. * whenever a null data source is encountered (this can be because mData
  8313. * is set to null, or because the data source itself is null).
  8314. * @type string
  8315. * @default null
  8316. */
  8317. "sDefaultContent": null,
  8318. /**
  8319. * Name for the column, allowing reference to the column by name as well as
  8320. * by index (needs a lookup to work by name).
  8321. * @type string
  8322. */
  8323. "sName": null,
  8324. /**
  8325. * Custom sorting data type - defines which of the available plug-ins in
  8326. * afnSortData the custom sorting will use - if any is defined.
  8327. * @type string
  8328. * @default std
  8329. */
  8330. "sSortDataType": 'std',
  8331. /**
  8332. * Class to be applied to the header element when sorting on this column
  8333. * @type string
  8334. * @default null
  8335. */
  8336. "sSortingClass": null,
  8337. /**
  8338. * Class to be applied to the header element when sorting on this column -
  8339. * when jQuery UI theming is used.
  8340. * @type string
  8341. * @default null
  8342. */
  8343. "sSortingClassJUI": null,
  8344. /**
  8345. * Title of the column - what is seen in the TH element (nTh).
  8346. * @type string
  8347. */
  8348. "sTitle": null,
  8349. /**
  8350. * Column sorting and filtering type
  8351. * @type string
  8352. * @default null
  8353. */
  8354. "sType": null,
  8355. /**
  8356. * Width of the column
  8357. * @type string
  8358. * @default null
  8359. */
  8360. "sWidth": null,
  8361. /**
  8362. * Width of the column when it was first "encountered"
  8363. * @type string
  8364. * @default null
  8365. */
  8366. "sWidthOrig": null
  8367. };
  8368. /*
  8369. * Developer note: The properties of the object below are given in Hungarian
  8370. * notation, that was used as the interface for DataTables prior to v1.10, however
  8371. * from v1.10 onwards the primary interface is camel case. In order to avoid
  8372. * breaking backwards compatibility utterly with this change, the Hungarian
  8373. * version is still, internally the primary interface, but is is not documented
  8374. * - hence the @name tags in each doc comment. This allows a Javascript function
  8375. * to create a map from Hungarian notation to camel case (going the other direction
  8376. * would require each property to be listed, which would at around 3K to the size
  8377. * of DataTables, while this method is about a 0.5K hit.
  8378. *
  8379. * Ultimately this does pave the way for Hungarian notation to be dropped
  8380. * completely, but that is a massive amount of work and will break current
  8381. * installs (therefore is on-hold until v2).
  8382. */
  8383. /**
  8384. * Initialisation options that can be given to DataTables at initialisation
  8385. * time.
  8386. * @namespace
  8387. */
  8388. DataTable.defaults = {
  8389. /**
  8390. * An array of data to use for the table, passed in at initialisation which
  8391. * will be used in preference to any data which is already in the DOM. This is
  8392. * particularly useful for constructing tables purely in Javascript, for
  8393. * example with a custom Ajax call.
  8394. * @type array
  8395. * @default null
  8396. *
  8397. * @dtopt Option
  8398. * @name DataTable.defaults.data
  8399. *
  8400. * @example
  8401. * // Using a 2D array data source
  8402. * $(document).ready( function () {
  8403. * $('#example').dataTable( {
  8404. * "data": [
  8405. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  8406. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  8407. * ],
  8408. * "columns": [
  8409. * { "title": "Engine" },
  8410. * { "title": "Browser" },
  8411. * { "title": "Platform" },
  8412. * { "title": "Version" },
  8413. * { "title": "Grade" }
  8414. * ]
  8415. * } );
  8416. * } );
  8417. *
  8418. * @example
  8419. * // Using an array of objects as a data source (`data`)
  8420. * $(document).ready( function () {
  8421. * $('#example').dataTable( {
  8422. * "data": [
  8423. * {
  8424. * "engine": "Trident",
  8425. * "browser": "Internet Explorer 4.0",
  8426. * "platform": "Win 95+",
  8427. * "version": 4,
  8428. * "grade": "X"
  8429. * },
  8430. * {
  8431. * "engine": "Trident",
  8432. * "browser": "Internet Explorer 5.0",
  8433. * "platform": "Win 95+",
  8434. * "version": 5,
  8435. * "grade": "C"
  8436. * }
  8437. * ],
  8438. * "columns": [
  8439. * { "title": "Engine", "data": "engine" },
  8440. * { "title": "Browser", "data": "browser" },
  8441. * { "title": "Platform", "data": "platform" },
  8442. * { "title": "Version", "data": "version" },
  8443. * { "title": "Grade", "data": "grade" }
  8444. * ]
  8445. * } );
  8446. * } );
  8447. */
  8448. "aaData": null,
  8449. /**
  8450. * If ordering is enabled, then DataTables will perform a first pass sort on
  8451. * initialisation. You can define which column(s) the sort is performed
  8452. * upon, and the sorting direction, with this variable. The `sorting` array
  8453. * should contain an array for each column to be sorted initially containing
  8454. * the column's index and a direction string ('asc' or 'desc').
  8455. * @type array
  8456. * @default [[0,'asc']]
  8457. *
  8458. * @dtopt Option
  8459. * @name DataTable.defaults.order
  8460. *
  8461. * @example
  8462. * // Sort by 3rd column first, and then 4th column
  8463. * $(document).ready( function() {
  8464. * $('#example').dataTable( {
  8465. * "order": [[2,'asc'], [3,'desc']]
  8466. * } );
  8467. * } );
  8468. *
  8469. * // No initial sorting
  8470. * $(document).ready( function() {
  8471. * $('#example').dataTable( {
  8472. * "order": []
  8473. * } );
  8474. * } );
  8475. */
  8476. "aaSorting": [[0,'asc']],
  8477. /**
  8478. * This parameter is basically identical to the `sorting` parameter, but
  8479. * cannot be overridden by user interaction with the table. What this means
  8480. * is that you could have a column (visible or hidden) which the sorting
  8481. * will always be forced on first - any sorting after that (from the user)
  8482. * will then be performed as required. This can be useful for grouping rows
  8483. * together.
  8484. * @type array
  8485. * @default null
  8486. *
  8487. * @dtopt Option
  8488. * @name DataTable.defaults.orderFixed
  8489. *
  8490. * @example
  8491. * $(document).ready( function() {
  8492. * $('#example').dataTable( {
  8493. * "orderFixed": [[0,'asc']]
  8494. * } );
  8495. * } )
  8496. */
  8497. "aaSortingFixed": [],
  8498. /**
  8499. * DataTables can be instructed to load data to display in the table from a
  8500. * Ajax source. This option defines how that Ajax call is made and where to.
  8501. *
  8502. * The `ajax` property has three different modes of operation, depending on
  8503. * how it is defined. These are:
  8504. *
  8505. * * `string` - Set the URL from where the data should be loaded from.
  8506. * * `object` - Define properties for `jQuery.ajax`.
  8507. * * `function` - Custom data get function
  8508. *
  8509. * `string`
  8510. * --------
  8511. *
  8512. * As a string, the `ajax` property simply defines the URL from which
  8513. * DataTables will load data.
  8514. *
  8515. * `object`
  8516. * --------
  8517. *
  8518. * As an object, the parameters in the object are passed to
  8519. * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
  8520. * of the Ajax request. DataTables has a number of default parameters which
  8521. * you can override using this option. Please refer to the jQuery
  8522. * documentation for a full description of the options available, although
  8523. * the following parameters provide additional options in DataTables or
  8524. * require special consideration:
  8525. *
  8526. * * `data` - As with jQuery, `data` can be provided as an object, but it
  8527. * can also be used as a function to manipulate the data DataTables sends
  8528. * to the server. The function takes a single parameter, an object of
  8529. * parameters with the values that DataTables has readied for sending. An
  8530. * object may be returned which will be merged into the DataTables
  8531. * defaults, or you can add the items to the object that was passed in and
  8532. * not return anything from the function. This supersedes `fnServerParams`
  8533. * from DataTables 1.9-.
  8534. *
  8535. * * `dataSrc` - By default DataTables will look for the property `data` (or
  8536. * `aaData` for compatibility with DataTables 1.9-) when obtaining data
  8537. * from an Ajax source or for server-side processing - this parameter
  8538. * allows that property to be changed. You can use Javascript dotted
  8539. * object notation to get a data source for multiple levels of nesting, or
  8540. * it my be used as a function. As a function it takes a single parameter,
  8541. * the JSON returned from the server, which can be manipulated as
  8542. * required, with the returned value being that used by DataTables as the
  8543. * data source for the table. This supersedes `sAjaxDataProp` from
  8544. * DataTables 1.9-.
  8545. *
  8546. * * `success` - Should not be overridden it is used internally in
  8547. * DataTables. To manipulate / transform the data returned by the server
  8548. * use `ajax.dataSrc`, or use `ajax` as a function (see below).
  8549. *
  8550. * `function`
  8551. * ----------
  8552. *
  8553. * As a function, making the Ajax call is left up to yourself allowing
  8554. * complete control of the Ajax request. Indeed, if desired, a method other
  8555. * than Ajax could be used to obtain the required data, such as Web storage
  8556. * or an AIR database.
  8557. *
  8558. * The function is given four parameters and no return is required. The
  8559. * parameters are:
  8560. *
  8561. * 1. _object_ - Data to send to the server
  8562. * 2. _function_ - Callback function that must be executed when the required
  8563. * data has been obtained. That data should be passed into the callback
  8564. * as the only parameter
  8565. * 3. _object_ - DataTables settings object for the table
  8566. *
  8567. * Note that this supersedes `fnServerData` from DataTables 1.9-.
  8568. *
  8569. * @type string|object|function
  8570. * @default null
  8571. *
  8572. * @dtopt Option
  8573. * @name DataTable.defaults.ajax
  8574. * @since 1.10.0
  8575. *
  8576. * @example
  8577. * // Get JSON data from a file via Ajax.
  8578. * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
  8579. * $('#example').dataTable( {
  8580. * "ajax": "data.json"
  8581. * } );
  8582. *
  8583. * @example
  8584. * // Get JSON data from a file via Ajax, using `dataSrc` to change
  8585. * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
  8586. * $('#example').dataTable( {
  8587. * "ajax": {
  8588. * "url": "data.json",
  8589. * "dataSrc": "tableData"
  8590. * }
  8591. * } );
  8592. *
  8593. * @example
  8594. * // Get JSON data from a file via Ajax, using `dataSrc` to read data
  8595. * // from a plain array rather than an array in an object
  8596. * $('#example').dataTable( {
  8597. * "ajax": {
  8598. * "url": "data.json",
  8599. * "dataSrc": ""
  8600. * }
  8601. * } );
  8602. *
  8603. * @example
  8604. * // Manipulate the data returned from the server - add a link to data
  8605. * // (note this can, should, be done using `render` for the column - this
  8606. * // is just a simple example of how the data can be manipulated).
  8607. * $('#example').dataTable( {
  8608. * "ajax": {
  8609. * "url": "data.json",
  8610. * "dataSrc": function ( json ) {
  8611. * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
  8612. * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
  8613. * }
  8614. * return json;
  8615. * }
  8616. * }
  8617. * } );
  8618. *
  8619. * @example
  8620. * // Add data to the request
  8621. * $('#example').dataTable( {
  8622. * "ajax": {
  8623. * "url": "data.json",
  8624. * "data": function ( d ) {
  8625. * return {
  8626. * "extra_search": $('#extra').val()
  8627. * };
  8628. * }
  8629. * }
  8630. * } );
  8631. *
  8632. * @example
  8633. * // Send request as POST
  8634. * $('#example').dataTable( {
  8635. * "ajax": {
  8636. * "url": "data.json",
  8637. * "type": "POST"
  8638. * }
  8639. * } );
  8640. *
  8641. * @example
  8642. * // Get the data from localStorage (could interface with a form for
  8643. * // adding, editing and removing rows).
  8644. * $('#example').dataTable( {
  8645. * "ajax": function (data, callback, settings) {
  8646. * callback(
  8647. * JSON.parse( localStorage.getItem('dataTablesData') )
  8648. * );
  8649. * }
  8650. * } );
  8651. */
  8652. "ajax": null,
  8653. /**
  8654. * This parameter allows you to readily specify the entries in the length drop
  8655. * down menu that DataTables shows when pagination is enabled. It can be
  8656. * either a 1D array of options which will be used for both the displayed
  8657. * option and the value, or a 2D array which will use the array in the first
  8658. * position as the value, and the array in the second position as the
  8659. * displayed options (useful for language strings such as 'All').
  8660. *
  8661. * Note that the `pageLength` property will be automatically set to the
  8662. * first value given in this array, unless `pageLength` is also provided.
  8663. * @type array
  8664. * @default [ 10, 25, 50, 100 ]
  8665. *
  8666. * @dtopt Option
  8667. * @name DataTable.defaults.lengthMenu
  8668. *
  8669. * @example
  8670. * $(document).ready( function() {
  8671. * $('#example').dataTable( {
  8672. * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  8673. * } );
  8674. * } );
  8675. */
  8676. "aLengthMenu": [ 10, 25, 50, 100 ],
  8677. /**
  8678. * The `columns` option in the initialisation parameter allows you to define
  8679. * details about the way individual columns behave. For a full list of
  8680. * column options that can be set, please see
  8681. * {@link DataTable.defaults.column}. Note that if you use `columns` to
  8682. * define your columns, you must have an entry in the array for every single
  8683. * column that you have in your table (these can be null if you don't which
  8684. * to specify any options).
  8685. * @member
  8686. *
  8687. * @name DataTable.defaults.column
  8688. */
  8689. "aoColumns": null,
  8690. /**
  8691. * Very similar to `columns`, `columnDefs` allows you to target a specific
  8692. * column, multiple columns, or all columns, using the `targets` property of
  8693. * each object in the array. This allows great flexibility when creating
  8694. * tables, as the `columnDefs` arrays can be of any length, targeting the
  8695. * columns you specifically want. `columnDefs` may use any of the column
  8696. * options available: {@link DataTable.defaults.column}, but it _must_
  8697. * have `targets` defined in each object in the array. Values in the `targets`
  8698. * array may be:
  8699. * <ul>
  8700. * <li>a string - class name will be matched on the TH for the column</li>
  8701. * <li>0 or a positive integer - column index counting from the left</li>
  8702. * <li>a negative integer - column index counting from the right</li>
  8703. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  8704. * </ul>
  8705. * @member
  8706. *
  8707. * @name DataTable.defaults.columnDefs
  8708. */
  8709. "aoColumnDefs": null,
  8710. /**
  8711. * Basically the same as `search`, this parameter defines the individual column
  8712. * filtering state at initialisation time. The array must be of the same size
  8713. * as the number of columns, and each element be an object with the parameters
  8714. * `search` and `escapeRegex` (the latter is optional). 'null' is also
  8715. * accepted and the default will be used.
  8716. * @type array
  8717. * @default []
  8718. *
  8719. * @dtopt Option
  8720. * @name DataTable.defaults.searchCols
  8721. *
  8722. * @example
  8723. * $(document).ready( function() {
  8724. * $('#example').dataTable( {
  8725. * "searchCols": [
  8726. * null,
  8727. * { "search": "My filter" },
  8728. * null,
  8729. * { "search": "^[0-9]", "escapeRegex": false }
  8730. * ]
  8731. * } );
  8732. * } )
  8733. */
  8734. "aoSearchCols": [],
  8735. /**
  8736. * An array of CSS classes that should be applied to displayed rows. This
  8737. * array may be of any length, and DataTables will apply each class
  8738. * sequentially, looping when required.
  8739. * @type array
  8740. * @default null <i>Will take the values determined by the `oClasses.stripe*`
  8741. * options</i>
  8742. *
  8743. * @dtopt Option
  8744. * @name DataTable.defaults.stripeClasses
  8745. *
  8746. * @example
  8747. * $(document).ready( function() {
  8748. * $('#example').dataTable( {
  8749. * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  8750. * } );
  8751. * } )
  8752. */
  8753. "asStripeClasses": null,
  8754. /**
  8755. * Enable or disable automatic column width calculation. This can be disabled
  8756. * as an optimisation (it takes some time to calculate the widths) if the
  8757. * tables widths are passed in using `columns`.
  8758. * @type boolean
  8759. * @default true
  8760. *
  8761. * @dtopt Features
  8762. * @name DataTable.defaults.autoWidth
  8763. *
  8764. * @example
  8765. * $(document).ready( function () {
  8766. * $('#example').dataTable( {
  8767. * "autoWidth": false
  8768. * } );
  8769. * } );
  8770. */
  8771. "bAutoWidth": true,
  8772. /**
  8773. * Deferred rendering can provide DataTables with a huge speed boost when you
  8774. * are using an Ajax or JS data source for the table. This option, when set to
  8775. * true, will cause DataTables to defer the creation of the table elements for
  8776. * each row until they are needed for a draw - saving a significant amount of
  8777. * time.
  8778. * @type boolean
  8779. * @default false
  8780. *
  8781. * @dtopt Features
  8782. * @name DataTable.defaults.deferRender
  8783. *
  8784. * @example
  8785. * $(document).ready( function() {
  8786. * $('#example').dataTable( {
  8787. * "ajax": "sources/arrays.txt",
  8788. * "deferRender": true
  8789. * } );
  8790. * } );
  8791. */
  8792. "bDeferRender": false,
  8793. /**
  8794. * Replace a DataTable which matches the given selector and replace it with
  8795. * one which has the properties of the new initialisation object passed. If no
  8796. * table matches the selector, then the new DataTable will be constructed as
  8797. * per normal.
  8798. * @type boolean
  8799. * @default false
  8800. *
  8801. * @dtopt Options
  8802. * @name DataTable.defaults.destroy
  8803. *
  8804. * @example
  8805. * $(document).ready( function() {
  8806. * $('#example').dataTable( {
  8807. * "srollY": "200px",
  8808. * "paginate": false
  8809. * } );
  8810. *
  8811. * // Some time later....
  8812. * $('#example').dataTable( {
  8813. * "filter": false,
  8814. * "destroy": true
  8815. * } );
  8816. * } );
  8817. */
  8818. "bDestroy": false,
  8819. /**
  8820. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  8821. * that it allows the end user to input multiple words (space separated) and
  8822. * will match a row containing those words, even if not in the order that was
  8823. * specified (this allow matching across multiple columns). Note that if you
  8824. * wish to use filtering in DataTables this must remain 'true' - to remove the
  8825. * default filtering input box and retain filtering abilities, please use
  8826. * {@link DataTable.defaults.dom}.
  8827. * @type boolean
  8828. * @default true
  8829. *
  8830. * @dtopt Features
  8831. * @name DataTable.defaults.searching
  8832. *
  8833. * @example
  8834. * $(document).ready( function () {
  8835. * $('#example').dataTable( {
  8836. * "searching": false
  8837. * } );
  8838. * } );
  8839. */
  8840. "bFilter": true,
  8841. /**
  8842. * Enable or disable the table information display. This shows information
  8843. * about the data that is currently visible on the page, including information
  8844. * about filtered data if that action is being performed.
  8845. * @type boolean
  8846. * @default true
  8847. *
  8848. * @dtopt Features
  8849. * @name DataTable.defaults.info
  8850. *
  8851. * @example
  8852. * $(document).ready( function () {
  8853. * $('#example').dataTable( {
  8854. * "info": false
  8855. * } );
  8856. * } );
  8857. */
  8858. "bInfo": true,
  8859. /**
  8860. * Allows the end user to select the size of a formatted page from a select
  8861. * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
  8862. * @type boolean
  8863. * @default true
  8864. *
  8865. * @dtopt Features
  8866. * @name DataTable.defaults.lengthChange
  8867. *
  8868. * @example
  8869. * $(document).ready( function () {
  8870. * $('#example').dataTable( {
  8871. * "lengthChange": false
  8872. * } );
  8873. * } );
  8874. */
  8875. "bLengthChange": true,
  8876. /**
  8877. * Enable or disable pagination.
  8878. * @type boolean
  8879. * @default true
  8880. *
  8881. * @dtopt Features
  8882. * @name DataTable.defaults.paging
  8883. *
  8884. * @example
  8885. * $(document).ready( function () {
  8886. * $('#example').dataTable( {
  8887. * "paging": false
  8888. * } );
  8889. * } );
  8890. */
  8891. "bPaginate": true,
  8892. /**
  8893. * Enable or disable the display of a 'processing' indicator when the table is
  8894. * being processed (e.g. a sort). This is particularly useful for tables with
  8895. * large amounts of data where it can take a noticeable amount of time to sort
  8896. * the entries.
  8897. * @type boolean
  8898. * @default false
  8899. *
  8900. * @dtopt Features
  8901. * @name DataTable.defaults.processing
  8902. *
  8903. * @example
  8904. * $(document).ready( function () {
  8905. * $('#example').dataTable( {
  8906. * "processing": true
  8907. * } );
  8908. * } );
  8909. */
  8910. "bProcessing": false,
  8911. /**
  8912. * Retrieve the DataTables object for the given selector. Note that if the
  8913. * table has already been initialised, this parameter will cause DataTables
  8914. * to simply return the object that has already been set up - it will not take
  8915. * account of any changes you might have made to the initialisation object
  8916. * passed to DataTables (setting this parameter to true is an acknowledgement
  8917. * that you understand this). `destroy` can be used to reinitialise a table if
  8918. * you need.
  8919. * @type boolean
  8920. * @default false
  8921. *
  8922. * @dtopt Options
  8923. * @name DataTable.defaults.retrieve
  8924. *
  8925. * @example
  8926. * $(document).ready( function() {
  8927. * initTable();
  8928. * tableActions();
  8929. * } );
  8930. *
  8931. * function initTable ()
  8932. * {
  8933. * return $('#example').dataTable( {
  8934. * "scrollY": "200px",
  8935. * "paginate": false,
  8936. * "retrieve": true
  8937. * } );
  8938. * }
  8939. *
  8940. * function tableActions ()
  8941. * {
  8942. * var table = initTable();
  8943. * // perform API operations with oTable
  8944. * }
  8945. */
  8946. "bRetrieve": false,
  8947. /**
  8948. * When vertical (y) scrolling is enabled, DataTables will force the height of
  8949. * the table's viewport to the given height at all times (useful for layout).
  8950. * However, this can look odd when filtering data down to a small data set,
  8951. * and the footer is left "floating" further down. This parameter (when
  8952. * enabled) will cause DataTables to collapse the table's viewport down when
  8953. * the result set will fit within the given Y height.
  8954. * @type boolean
  8955. * @default false
  8956. *
  8957. * @dtopt Options
  8958. * @name DataTable.defaults.scrollCollapse
  8959. *
  8960. * @example
  8961. * $(document).ready( function() {
  8962. * $('#example').dataTable( {
  8963. * "scrollY": "200",
  8964. * "scrollCollapse": true
  8965. * } );
  8966. * } );
  8967. */
  8968. "bScrollCollapse": false,
  8969. /**
  8970. * Configure DataTables to use server-side processing. Note that the
  8971. * `ajax` parameter must also be given in order to give DataTables a
  8972. * source to obtain the required data for each draw.
  8973. * @type boolean
  8974. * @default false
  8975. *
  8976. * @dtopt Features
  8977. * @dtopt Server-side
  8978. * @name DataTable.defaults.serverSide
  8979. *
  8980. * @example
  8981. * $(document).ready( function () {
  8982. * $('#example').dataTable( {
  8983. * "serverSide": true,
  8984. * "ajax": "xhr.php"
  8985. * } );
  8986. * } );
  8987. */
  8988. "bServerSide": false,
  8989. /**
  8990. * Enable or disable sorting of columns. Sorting of individual columns can be
  8991. * disabled by the `sortable` option for each column.
  8992. * @type boolean
  8993. * @default true
  8994. *
  8995. * @dtopt Features
  8996. * @name DataTable.defaults.ordering
  8997. *
  8998. * @example
  8999. * $(document).ready( function () {
  9000. * $('#example').dataTable( {
  9001. * "ordering": false
  9002. * } );
  9003. * } );
  9004. */
  9005. "bSort": true,
  9006. /**
  9007. * Enable or display DataTables' ability to sort multiple columns at the
  9008. * same time (activated by shift-click by the user).
  9009. * @type boolean
  9010. * @default true
  9011. *
  9012. * @dtopt Options
  9013. * @name DataTable.defaults.orderMulti
  9014. *
  9015. * @example
  9016. * // Disable multiple column sorting ability
  9017. * $(document).ready( function () {
  9018. * $('#example').dataTable( {
  9019. * "orderMulti": false
  9020. * } );
  9021. * } );
  9022. */
  9023. "bSortMulti": true,
  9024. /**
  9025. * Allows control over whether DataTables should use the top (true) unique
  9026. * cell that is found for a single column, or the bottom (false - default).
  9027. * This is useful when using complex headers.
  9028. * @type boolean
  9029. * @default false
  9030. *
  9031. * @dtopt Options
  9032. * @name DataTable.defaults.orderCellsTop
  9033. *
  9034. * @example
  9035. * $(document).ready( function() {
  9036. * $('#example').dataTable( {
  9037. * "orderCellsTop": true
  9038. * } );
  9039. * } );
  9040. */
  9041. "bSortCellsTop": false,
  9042. /**
  9043. * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
  9044. * `sorting\_3` to the columns which are currently being sorted on. This is
  9045. * presented as a feature switch as it can increase processing time (while
  9046. * classes are removed and added) so for large data sets you might want to
  9047. * turn this off.
  9048. * @type boolean
  9049. * @default true
  9050. *
  9051. * @dtopt Features
  9052. * @name DataTable.defaults.orderClasses
  9053. *
  9054. * @example
  9055. * $(document).ready( function () {
  9056. * $('#example').dataTable( {
  9057. * "orderClasses": false
  9058. * } );
  9059. * } );
  9060. */
  9061. "bSortClasses": true,
  9062. /**
  9063. * Enable or disable state saving. When enabled HTML5 `localStorage` will be
  9064. * used to save table display information such as pagination information,
  9065. * display length, filtering and sorting. As such when the end user reloads
  9066. * the page the display display will match what thy had previously set up.
  9067. *
  9068. * Due to the use of `localStorage` the default state saving is not supported
  9069. * in IE6 or 7. If state saving is required in those browsers, use
  9070. * `stateSaveCallback` to provide a storage solution such as cookies.
  9071. * @type boolean
  9072. * @default false
  9073. *
  9074. * @dtopt Features
  9075. * @name DataTable.defaults.stateSave
  9076. *
  9077. * @example
  9078. * $(document).ready( function () {
  9079. * $('#example').dataTable( {
  9080. * "stateSave": true
  9081. * } );
  9082. * } );
  9083. */
  9084. "bStateSave": false,
  9085. /**
  9086. * This function is called when a TR element is created (and all TD child
  9087. * elements have been inserted), or registered if using a DOM source, allowing
  9088. * manipulation of the TR element (adding classes etc).
  9089. * @type function
  9090. * @param {node} row "TR" element for the current row
  9091. * @param {array} data Raw data array for this row
  9092. * @param {int} dataIndex The index of this row in the internal aoData array
  9093. *
  9094. * @dtopt Callbacks
  9095. * @name DataTable.defaults.createdRow
  9096. *
  9097. * @example
  9098. * $(document).ready( function() {
  9099. * $('#example').dataTable( {
  9100. * "createdRow": function( row, data, dataIndex ) {
  9101. * // Bold the grade for all 'A' grade browsers
  9102. * if ( data[4] == "A" )
  9103. * {
  9104. * $('td:eq(4)', row).html( '<b>A</b>' );
  9105. * }
  9106. * }
  9107. * } );
  9108. * } );
  9109. */
  9110. "fnCreatedRow": null,
  9111. /**
  9112. * This function is called on every 'draw' event, and allows you to
  9113. * dynamically modify any aspect you want about the created DOM.
  9114. * @type function
  9115. * @param {object} settings DataTables settings object
  9116. *
  9117. * @dtopt Callbacks
  9118. * @name DataTable.defaults.drawCallback
  9119. *
  9120. * @example
  9121. * $(document).ready( function() {
  9122. * $('#example').dataTable( {
  9123. * "drawCallback": function( settings ) {
  9124. * alert( 'DataTables has redrawn the table' );
  9125. * }
  9126. * } );
  9127. * } );
  9128. */
  9129. "fnDrawCallback": null,
  9130. /**
  9131. * Identical to fnHeaderCallback() but for the table footer this function
  9132. * allows you to modify the table footer on every 'draw' event.
  9133. * @type function
  9134. * @param {node} foot "TR" element for the footer
  9135. * @param {array} data Full table data (as derived from the original HTML)
  9136. * @param {int} start Index for the current display starting point in the
  9137. * display array
  9138. * @param {int} end Index for the current display ending point in the
  9139. * display array
  9140. * @param {array int} display Index array to translate the visual position
  9141. * to the full data array
  9142. *
  9143. * @dtopt Callbacks
  9144. * @name DataTable.defaults.footerCallback
  9145. *
  9146. * @example
  9147. * $(document).ready( function() {
  9148. * $('#example').dataTable( {
  9149. * "footerCallback": function( tfoot, data, start, end, display ) {
  9150. * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
  9151. * }
  9152. * } );
  9153. * } )
  9154. */
  9155. "fnFooterCallback": null,
  9156. /**
  9157. * When rendering large numbers in the information element for the table
  9158. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  9159. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  9160. * rendered as "1,000,000") to help readability for the end user. This
  9161. * function will override the default method DataTables uses.
  9162. * @type function
  9163. * @member
  9164. * @param {int} toFormat number to be formatted
  9165. * @returns {string} formatted string for DataTables to show the number
  9166. *
  9167. * @dtopt Callbacks
  9168. * @name DataTable.defaults.formatNumber
  9169. *
  9170. * @example
  9171. * // Format a number using a single quote for the separator (note that
  9172. * // this can also be done with the language.thousands option)
  9173. * $(document).ready( function() {
  9174. * $('#example').dataTable( {
  9175. * "formatNumber": function ( toFormat ) {
  9176. * return toFormat.toString().replace(
  9177. * /\B(?=(\d{3})+(?!\d))/g, "'"
  9178. * );
  9179. * };
  9180. * } );
  9181. * } );
  9182. */
  9183. "fnFormatNumber": function ( toFormat ) {
  9184. return toFormat.toString().replace(
  9185. /\B(?=(\d{3})+(?!\d))/g,
  9186. this.oLanguage.sThousands
  9187. );
  9188. },
  9189. /**
  9190. * This function is called on every 'draw' event, and allows you to
  9191. * dynamically modify the header row. This can be used to calculate and
  9192. * display useful information about the table.
  9193. * @type function
  9194. * @param {node} head "TR" element for the header
  9195. * @param {array} data Full table data (as derived from the original HTML)
  9196. * @param {int} start Index for the current display starting point in the
  9197. * display array
  9198. * @param {int} end Index for the current display ending point in the
  9199. * display array
  9200. * @param {array int} display Index array to translate the visual position
  9201. * to the full data array
  9202. *
  9203. * @dtopt Callbacks
  9204. * @name DataTable.defaults.headerCallback
  9205. *
  9206. * @example
  9207. * $(document).ready( function() {
  9208. * $('#example').dataTable( {
  9209. * "fheaderCallback": function( head, data, start, end, display ) {
  9210. * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
  9211. * }
  9212. * } );
  9213. * } )
  9214. */
  9215. "fnHeaderCallback": null,
  9216. /**
  9217. * The information element can be used to convey information about the current
  9218. * state of the table. Although the internationalisation options presented by
  9219. * DataTables are quite capable of dealing with most customisations, there may
  9220. * be times where you wish to customise the string further. This callback
  9221. * allows you to do exactly that.
  9222. * @type function
  9223. * @param {object} oSettings DataTables settings object
  9224. * @param {int} start Starting position in data for the draw
  9225. * @param {int} end End position in data for the draw
  9226. * @param {int} max Total number of rows in the table (regardless of
  9227. * filtering)
  9228. * @param {int} total Total number of rows in the data set, after filtering
  9229. * @param {string} pre The string that DataTables has formatted using it's
  9230. * own rules
  9231. * @returns {string} The string to be displayed in the information element.
  9232. *
  9233. * @dtopt Callbacks
  9234. * @name DataTable.defaults.infoCallback
  9235. *
  9236. * @example
  9237. * $('#example').dataTable( {
  9238. * "infoCallback": function( settings, start, end, max, total, pre ) {
  9239. * return start +" to "+ end;
  9240. * }
  9241. * } );
  9242. */
  9243. "fnInfoCallback": null,
  9244. /**
  9245. * Called when the table has been initialised. Normally DataTables will
  9246. * initialise sequentially and there will be no need for this function,
  9247. * however, this does not hold true when using external language information
  9248. * since that is obtained using an async XHR call.
  9249. * @type function
  9250. * @param {object} settings DataTables settings object
  9251. * @param {object} json The JSON object request from the server - only
  9252. * present if client-side Ajax sourced data is used
  9253. *
  9254. * @dtopt Callbacks
  9255. * @name DataTable.defaults.initComplete
  9256. *
  9257. * @example
  9258. * $(document).ready( function() {
  9259. * $('#example').dataTable( {
  9260. * "initComplete": function(settings, json) {
  9261. * alert( 'DataTables has finished its initialisation.' );
  9262. * }
  9263. * } );
  9264. * } )
  9265. */
  9266. "fnInitComplete": null,
  9267. /**
  9268. * Called at the very start of each table draw and can be used to cancel the
  9269. * draw by returning false, any other return (including undefined) results in
  9270. * the full draw occurring).
  9271. * @type function
  9272. * @param {object} settings DataTables settings object
  9273. * @returns {boolean} False will cancel the draw, anything else (including no
  9274. * return) will allow it to complete.
  9275. *
  9276. * @dtopt Callbacks
  9277. * @name DataTable.defaults.preDrawCallback
  9278. *
  9279. * @example
  9280. * $(document).ready( function() {
  9281. * $('#example').dataTable( {
  9282. * "preDrawCallback": function( settings ) {
  9283. * if ( $('#test').val() == 1 ) {
  9284. * return false;
  9285. * }
  9286. * }
  9287. * } );
  9288. * } );
  9289. */
  9290. "fnPreDrawCallback": null,
  9291. /**
  9292. * This function allows you to 'post process' each row after it have been
  9293. * generated for each table draw, but before it is rendered on screen. This
  9294. * function might be used for setting the row class name etc.
  9295. * @type function
  9296. * @param {node} row "TR" element for the current row
  9297. * @param {array} data Raw data array for this row
  9298. * @param {int} displayIndex The display index for the current table draw
  9299. * @param {int} displayIndexFull The index of the data in the full list of
  9300. * rows (after filtering)
  9301. *
  9302. * @dtopt Callbacks
  9303. * @name DataTable.defaults.rowCallback
  9304. *
  9305. * @example
  9306. * $(document).ready( function() {
  9307. * $('#example').dataTable( {
  9308. * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
  9309. * // Bold the grade for all 'A' grade browsers
  9310. * if ( data[4] == "A" ) {
  9311. * $('td:eq(4)', row).html( '<b>A</b>' );
  9312. * }
  9313. * }
  9314. * } );
  9315. * } );
  9316. */
  9317. "fnRowCallback": null,
  9318. /**
  9319. * __Deprecated__ The functionality provided by this parameter has now been
  9320. * superseded by that provided through `ajax`, which should be used instead.
  9321. *
  9322. * This parameter allows you to override the default function which obtains
  9323. * the data from the server so something more suitable for your application.
  9324. * For example you could use POST data, or pull information from a Gears or
  9325. * AIR database.
  9326. * @type function
  9327. * @member
  9328. * @param {string} source HTTP source to obtain the data from (`ajax`)
  9329. * @param {array} data A key/value pair object containing the data to send
  9330. * to the server
  9331. * @param {function} callback to be called on completion of the data get
  9332. * process that will draw the data on the page.
  9333. * @param {object} settings DataTables settings object
  9334. *
  9335. * @dtopt Callbacks
  9336. * @dtopt Server-side
  9337. * @name DataTable.defaults.serverData
  9338. *
  9339. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9340. */
  9341. "fnServerData": null,
  9342. /**
  9343. * __Deprecated__ The functionality provided by this parameter has now been
  9344. * superseded by that provided through `ajax`, which should be used instead.
  9345. *
  9346. * It is often useful to send extra data to the server when making an Ajax
  9347. * request - for example custom filtering information, and this callback
  9348. * function makes it trivial to send extra information to the server. The
  9349. * passed in parameter is the data set that has been constructed by
  9350. * DataTables, and you can add to this or modify it as you require.
  9351. * @type function
  9352. * @param {array} data Data array (array of objects which are name/value
  9353. * pairs) that has been constructed by DataTables and will be sent to the
  9354. * server. In the case of Ajax sourced data with server-side processing
  9355. * this will be an empty array, for server-side processing there will be a
  9356. * significant number of parameters!
  9357. * @returns {undefined} Ensure that you modify the data array passed in,
  9358. * as this is passed by reference.
  9359. *
  9360. * @dtopt Callbacks
  9361. * @dtopt Server-side
  9362. * @name DataTable.defaults.serverParams
  9363. *
  9364. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9365. */
  9366. "fnServerParams": null,
  9367. /**
  9368. * Load the table state. With this function you can define from where, and how, the
  9369. * state of a table is loaded. By default DataTables will load from `localStorage`
  9370. * but you might wish to use a server-side database or cookies.
  9371. * @type function
  9372. * @member
  9373. * @param {object} settings DataTables settings object
  9374. * @param {object} callback Callback that can be executed when done. It
  9375. * should be passed the loaded state object.
  9376. * @return {object} The DataTables state object to be loaded
  9377. *
  9378. * @dtopt Callbacks
  9379. * @name DataTable.defaults.stateLoadCallback
  9380. *
  9381. * @example
  9382. * $(document).ready( function() {
  9383. * $('#example').dataTable( {
  9384. * "stateSave": true,
  9385. * "stateLoadCallback": function (settings, callback) {
  9386. * $.ajax( {
  9387. * "url": "/state_load",
  9388. * "dataType": "json",
  9389. * "success": function (json) {
  9390. * callback( json );
  9391. * }
  9392. * } );
  9393. * }
  9394. * } );
  9395. * } );
  9396. */
  9397. "fnStateLoadCallback": function ( settings ) {
  9398. try {
  9399. return JSON.parse(
  9400. (settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
  9401. 'DataTables_'+settings.sInstance+'_'+location.pathname
  9402. )
  9403. );
  9404. } catch (e) {}
  9405. },
  9406. /**
  9407. * Callback which allows modification of the saved state prior to loading that state.
  9408. * This callback is called when the table is loading state from the stored data, but
  9409. * prior to the settings object being modified by the saved state. Note that for
  9410. * plug-in authors, you should use the `stateLoadParams` event to load parameters for
  9411. * a plug-in.
  9412. * @type function
  9413. * @param {object} settings DataTables settings object
  9414. * @param {object} data The state object that is to be loaded
  9415. *
  9416. * @dtopt Callbacks
  9417. * @name DataTable.defaults.stateLoadParams
  9418. *
  9419. * @example
  9420. * // Remove a saved filter, so filtering is never loaded
  9421. * $(document).ready( function() {
  9422. * $('#example').dataTable( {
  9423. * "stateSave": true,
  9424. * "stateLoadParams": function (settings, data) {
  9425. * data.oSearch.sSearch = "";
  9426. * }
  9427. * } );
  9428. * } );
  9429. *
  9430. * @example
  9431. * // Disallow state loading by returning false
  9432. * $(document).ready( function() {
  9433. * $('#example').dataTable( {
  9434. * "stateSave": true,
  9435. * "stateLoadParams": function (settings, data) {
  9436. * return false;
  9437. * }
  9438. * } );
  9439. * } );
  9440. */
  9441. "fnStateLoadParams": null,
  9442. /**
  9443. * Callback that is called when the state has been loaded from the state saving method
  9444. * and the DataTables settings object has been modified as a result of the loaded state.
  9445. * @type function
  9446. * @param {object} settings DataTables settings object
  9447. * @param {object} data The state object that was loaded
  9448. *
  9449. * @dtopt Callbacks
  9450. * @name DataTable.defaults.stateLoaded
  9451. *
  9452. * @example
  9453. * // Show an alert with the filtering value that was saved
  9454. * $(document).ready( function() {
  9455. * $('#example').dataTable( {
  9456. * "stateSave": true,
  9457. * "stateLoaded": function (settings, data) {
  9458. * alert( 'Saved filter was: '+data.oSearch.sSearch );
  9459. * }
  9460. * } );
  9461. * } );
  9462. */
  9463. "fnStateLoaded": null,
  9464. /**
  9465. * Save the table state. This function allows you to define where and how the state
  9466. * information for the table is stored By default DataTables will use `localStorage`
  9467. * but you might wish to use a server-side database or cookies.
  9468. * @type function
  9469. * @member
  9470. * @param {object} settings DataTables settings object
  9471. * @param {object} data The state object to be saved
  9472. *
  9473. * @dtopt Callbacks
  9474. * @name DataTable.defaults.stateSaveCallback
  9475. *
  9476. * @example
  9477. * $(document).ready( function() {
  9478. * $('#example').dataTable( {
  9479. * "stateSave": true,
  9480. * "stateSaveCallback": function (settings, data) {
  9481. * // Send an Ajax request to the server with the state object
  9482. * $.ajax( {
  9483. * "url": "/state_save",
  9484. * "data": data,
  9485. * "dataType": "json",
  9486. * "method": "POST"
  9487. * "success": function () {}
  9488. * } );
  9489. * }
  9490. * } );
  9491. * } );
  9492. */
  9493. "fnStateSaveCallback": function ( settings, data ) {
  9494. try {
  9495. (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
  9496. 'DataTables_'+settings.sInstance+'_'+location.pathname,
  9497. JSON.stringify( data )
  9498. );
  9499. } catch (e) {}
  9500. },
  9501. /**
  9502. * Callback which allows modification of the state to be saved. Called when the table
  9503. * has changed state a new state save is required. This method allows modification of
  9504. * the state saving object prior to actually doing the save, including addition or
  9505. * other state properties or modification. Note that for plug-in authors, you should
  9506. * use the `stateSaveParams` event to save parameters for a plug-in.
  9507. * @type function
  9508. * @param {object} settings DataTables settings object
  9509. * @param {object} data The state object to be saved
  9510. *
  9511. * @dtopt Callbacks
  9512. * @name DataTable.defaults.stateSaveParams
  9513. *
  9514. * @example
  9515. * // Remove a saved filter, so filtering is never saved
  9516. * $(document).ready( function() {
  9517. * $('#example').dataTable( {
  9518. * "stateSave": true,
  9519. * "stateSaveParams": function (settings, data) {
  9520. * data.oSearch.sSearch = "";
  9521. * }
  9522. * } );
  9523. * } );
  9524. */
  9525. "fnStateSaveParams": null,
  9526. /**
  9527. * Duration for which the saved state information is considered valid. After this period
  9528. * has elapsed the state will be returned to the default.
  9529. * Value is given in seconds.
  9530. * @type int
  9531. * @default 7200 <i>(2 hours)</i>
  9532. *
  9533. * @dtopt Options
  9534. * @name DataTable.defaults.stateDuration
  9535. *
  9536. * @example
  9537. * $(document).ready( function() {
  9538. * $('#example').dataTable( {
  9539. * "stateDuration": 60*60*24; // 1 day
  9540. * } );
  9541. * } )
  9542. */
  9543. "iStateDuration": 7200,
  9544. /**
  9545. * When enabled DataTables will not make a request to the server for the first
  9546. * page draw - rather it will use the data already on the page (no sorting etc
  9547. * will be applied to it), thus saving on an XHR at load time. `deferLoading`
  9548. * is used to indicate that deferred loading is required, but it is also used
  9549. * to tell DataTables how many records there are in the full table (allowing
  9550. * the information element and pagination to be displayed correctly). In the case
  9551. * where a filtering is applied to the table on initial load, this can be
  9552. * indicated by giving the parameter as an array, where the first element is
  9553. * the number of records available after filtering and the second element is the
  9554. * number of records without filtering (allowing the table information element
  9555. * to be shown correctly).
  9556. * @type int | array
  9557. * @default null
  9558. *
  9559. * @dtopt Options
  9560. * @name DataTable.defaults.deferLoading
  9561. *
  9562. * @example
  9563. * // 57 records available in the table, no filtering applied
  9564. * $(document).ready( function() {
  9565. * $('#example').dataTable( {
  9566. * "serverSide": true,
  9567. * "ajax": "scripts/server_processing.php",
  9568. * "deferLoading": 57
  9569. * } );
  9570. * } );
  9571. *
  9572. * @example
  9573. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  9574. * $(document).ready( function() {
  9575. * $('#example').dataTable( {
  9576. * "serverSide": true,
  9577. * "ajax": "scripts/server_processing.php",
  9578. * "deferLoading": [ 57, 100 ],
  9579. * "search": {
  9580. * "search": "my_filter"
  9581. * }
  9582. * } );
  9583. * } );
  9584. */
  9585. "iDeferLoading": null,
  9586. /**
  9587. * Number of rows to display on a single page when using pagination. If
  9588. * feature enabled (`lengthChange`) then the end user will be able to override
  9589. * this to a custom setting using a pop-up menu.
  9590. * @type int
  9591. * @default 10
  9592. *
  9593. * @dtopt Options
  9594. * @name DataTable.defaults.pageLength
  9595. *
  9596. * @example
  9597. * $(document).ready( function() {
  9598. * $('#example').dataTable( {
  9599. * "pageLength": 50
  9600. * } );
  9601. * } )
  9602. */
  9603. "iDisplayLength": 10,
  9604. /**
  9605. * Define the starting point for data display when using DataTables with
  9606. * pagination. Note that this parameter is the number of records, rather than
  9607. * the page number, so if you have 10 records per page and want to start on
  9608. * the third page, it should be "20".
  9609. * @type int
  9610. * @default 0
  9611. *
  9612. * @dtopt Options
  9613. * @name DataTable.defaults.displayStart
  9614. *
  9615. * @example
  9616. * $(document).ready( function() {
  9617. * $('#example').dataTable( {
  9618. * "displayStart": 20
  9619. * } );
  9620. * } )
  9621. */
  9622. "iDisplayStart": 0,
  9623. /**
  9624. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  9625. * and filtering) by adding a `tabindex` attribute to the required elements. This
  9626. * allows you to tab through the controls and press the enter key to activate them.
  9627. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  9628. * You can overrule this using this parameter if you wish. Use a value of -1 to
  9629. * disable built-in keyboard navigation.
  9630. * @type int
  9631. * @default 0
  9632. *
  9633. * @dtopt Options
  9634. * @name DataTable.defaults.tabIndex
  9635. *
  9636. * @example
  9637. * $(document).ready( function() {
  9638. * $('#example').dataTable( {
  9639. * "tabIndex": 1
  9640. * } );
  9641. * } );
  9642. */
  9643. "iTabIndex": 0,
  9644. /**
  9645. * Classes that DataTables assigns to the various components and features
  9646. * that it adds to the HTML table. This allows classes to be configured
  9647. * during initialisation in addition to through the static
  9648. * {@link DataTable.ext.oStdClasses} object).
  9649. * @namespace
  9650. * @name DataTable.defaults.classes
  9651. */
  9652. "oClasses": {},
  9653. /**
  9654. * All strings that DataTables uses in the user interface that it creates
  9655. * are defined in this object, allowing you to modified them individually or
  9656. * completely replace them all as required.
  9657. * @namespace
  9658. * @name DataTable.defaults.language
  9659. */
  9660. "oLanguage": {
  9661. /**
  9662. * Strings that are used for WAI-ARIA labels and controls only (these are not
  9663. * actually visible on the page, but will be read by screenreaders, and thus
  9664. * must be internationalised as well).
  9665. * @namespace
  9666. * @name DataTable.defaults.language.aria
  9667. */
  9668. "oAria": {
  9669. /**
  9670. * ARIA label that is added to the table headers when the column may be
  9671. * sorted ascending by activing the column (click or return when focused).
  9672. * Note that the column header is prefixed to this string.
  9673. * @type string
  9674. * @default : activate to sort column ascending
  9675. *
  9676. * @dtopt Language
  9677. * @name DataTable.defaults.language.aria.sortAscending
  9678. *
  9679. * @example
  9680. * $(document).ready( function() {
  9681. * $('#example').dataTable( {
  9682. * "language": {
  9683. * "aria": {
  9684. * "sortAscending": " - click/return to sort ascending"
  9685. * }
  9686. * }
  9687. * } );
  9688. * } );
  9689. */
  9690. "sSortAscending": ": activate to sort column ascending",
  9691. /**
  9692. * ARIA label that is added to the table headers when the column may be
  9693. * sorted descending by activing the column (click or return when focused).
  9694. * Note that the column header is prefixed to this string.
  9695. * @type string
  9696. * @default : activate to sort column ascending
  9697. *
  9698. * @dtopt Language
  9699. * @name DataTable.defaults.language.aria.sortDescending
  9700. *
  9701. * @example
  9702. * $(document).ready( function() {
  9703. * $('#example').dataTable( {
  9704. * "language": {
  9705. * "aria": {
  9706. * "sortDescending": " - click/return to sort descending"
  9707. * }
  9708. * }
  9709. * } );
  9710. * } );
  9711. */
  9712. "sSortDescending": ": activate to sort column descending"
  9713. },
  9714. /**
  9715. * Pagination string used by DataTables for the built-in pagination
  9716. * control types.
  9717. * @namespace
  9718. * @name DataTable.defaults.language.paginate
  9719. */
  9720. "oPaginate": {
  9721. /**
  9722. * Text to use when using the 'full_numbers' type of pagination for the
  9723. * button to take the user to the first page.
  9724. * @type string
  9725. * @default First
  9726. *
  9727. * @dtopt Language
  9728. * @name DataTable.defaults.language.paginate.first
  9729. *
  9730. * @example
  9731. * $(document).ready( function() {
  9732. * $('#example').dataTable( {
  9733. * "language": {
  9734. * "paginate": {
  9735. * "first": "First page"
  9736. * }
  9737. * }
  9738. * } );
  9739. * } );
  9740. */
  9741. "sFirst": "First",
  9742. /**
  9743. * Text to use when using the 'full_numbers' type of pagination for the
  9744. * button to take the user to the last page.
  9745. * @type string
  9746. * @default Last
  9747. *
  9748. * @dtopt Language
  9749. * @name DataTable.defaults.language.paginate.last
  9750. *
  9751. * @example
  9752. * $(document).ready( function() {
  9753. * $('#example').dataTable( {
  9754. * "language": {
  9755. * "paginate": {
  9756. * "last": "Last page"
  9757. * }
  9758. * }
  9759. * } );
  9760. * } );
  9761. */
  9762. "sLast": "Last",
  9763. /**
  9764. * Text to use for the 'next' pagination button (to take the user to the
  9765. * next page).
  9766. * @type string
  9767. * @default Next
  9768. *
  9769. * @dtopt Language
  9770. * @name DataTable.defaults.language.paginate.next
  9771. *
  9772. * @example
  9773. * $(document).ready( function() {
  9774. * $('#example').dataTable( {
  9775. * "language": {
  9776. * "paginate": {
  9777. * "next": "Next page"
  9778. * }
  9779. * }
  9780. * } );
  9781. * } );
  9782. */
  9783. "sNext": "Next",
  9784. /**
  9785. * Text to use for the 'previous' pagination button (to take the user to
  9786. * the previous page).
  9787. * @type string
  9788. * @default Previous
  9789. *
  9790. * @dtopt Language
  9791. * @name DataTable.defaults.language.paginate.previous
  9792. *
  9793. * @example
  9794. * $(document).ready( function() {
  9795. * $('#example').dataTable( {
  9796. * "language": {
  9797. * "paginate": {
  9798. * "previous": "Previous page"
  9799. * }
  9800. * }
  9801. * } );
  9802. * } );
  9803. */
  9804. "sPrevious": "Previous"
  9805. },
  9806. /**
  9807. * This string is shown in preference to `zeroRecords` when the table is
  9808. * empty of data (regardless of filtering). Note that this is an optional
  9809. * parameter - if it is not given, the value of `zeroRecords` will be used
  9810. * instead (either the default or given value).
  9811. * @type string
  9812. * @default No data available in table
  9813. *
  9814. * @dtopt Language
  9815. * @name DataTable.defaults.language.emptyTable
  9816. *
  9817. * @example
  9818. * $(document).ready( function() {
  9819. * $('#example').dataTable( {
  9820. * "language": {
  9821. * "emptyTable": "No data available in table"
  9822. * }
  9823. * } );
  9824. * } );
  9825. */
  9826. "sEmptyTable": "No data available in table",
  9827. /**
  9828. * This string gives information to the end user about the information
  9829. * that is current on display on the page. The following tokens can be
  9830. * used in the string and will be dynamically replaced as the table
  9831. * display updates. This tokens can be placed anywhere in the string, or
  9832. * removed as needed by the language requires:
  9833. *
  9834. * * `\_START\_` - Display index of the first record on the current page
  9835. * * `\_END\_` - Display index of the last record on the current page
  9836. * * `\_TOTAL\_` - Number of records in the table after filtering
  9837. * * `\_MAX\_` - Number of records in the table without filtering
  9838. * * `\_PAGE\_` - Current page number
  9839. * * `\_PAGES\_` - Total number of pages of data in the table
  9840. *
  9841. * @type string
  9842. * @default Showing _START_ to _END_ of _TOTAL_ entries
  9843. *
  9844. * @dtopt Language
  9845. * @name DataTable.defaults.language.info
  9846. *
  9847. * @example
  9848. * $(document).ready( function() {
  9849. * $('#example').dataTable( {
  9850. * "language": {
  9851. * "info": "Showing page _PAGE_ of _PAGES_"
  9852. * }
  9853. * } );
  9854. * } );
  9855. */
  9856. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  9857. /**
  9858. * Display information string for when the table is empty. Typically the
  9859. * format of this string should match `info`.
  9860. * @type string
  9861. * @default Showing 0 to 0 of 0 entries
  9862. *
  9863. * @dtopt Language
  9864. * @name DataTable.defaults.language.infoEmpty
  9865. *
  9866. * @example
  9867. * $(document).ready( function() {
  9868. * $('#example').dataTable( {
  9869. * "language": {
  9870. * "infoEmpty": "No entries to show"
  9871. * }
  9872. * } );
  9873. * } );
  9874. */
  9875. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  9876. /**
  9877. * When a user filters the information in a table, this string is appended
  9878. * to the information (`info`) to give an idea of how strong the filtering
  9879. * is. The variable _MAX_ is dynamically updated.
  9880. * @type string
  9881. * @default (filtered from _MAX_ total entries)
  9882. *
  9883. * @dtopt Language
  9884. * @name DataTable.defaults.language.infoFiltered
  9885. *
  9886. * @example
  9887. * $(document).ready( function() {
  9888. * $('#example').dataTable( {
  9889. * "language": {
  9890. * "infoFiltered": " - filtering from _MAX_ records"
  9891. * }
  9892. * } );
  9893. * } );
  9894. */
  9895. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  9896. /**
  9897. * If can be useful to append extra information to the info string at times,
  9898. * and this variable does exactly that. This information will be appended to
  9899. * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
  9900. * being used) at all times.
  9901. * @type string
  9902. * @default <i>Empty string</i>
  9903. *
  9904. * @dtopt Language
  9905. * @name DataTable.defaults.language.infoPostFix
  9906. *
  9907. * @example
  9908. * $(document).ready( function() {
  9909. * $('#example').dataTable( {
  9910. * "language": {
  9911. * "infoPostFix": "All records shown are derived from real information."
  9912. * }
  9913. * } );
  9914. * } );
  9915. */
  9916. "sInfoPostFix": "",
  9917. /**
  9918. * This decimal place operator is a little different from the other
  9919. * language options since DataTables doesn't output floating point
  9920. * numbers, so it won't ever use this for display of a number. Rather,
  9921. * what this parameter does is modify the sort methods of the table so
  9922. * that numbers which are in a format which has a character other than
  9923. * a period (`.`) as a decimal place will be sorted numerically.
  9924. *
  9925. * Note that numbers with different decimal places cannot be shown in
  9926. * the same table and still be sortable, the table must be consistent.
  9927. * However, multiple different tables on the page can use different
  9928. * decimal place characters.
  9929. * @type string
  9930. * @default
  9931. *
  9932. * @dtopt Language
  9933. * @name DataTable.defaults.language.decimal
  9934. *
  9935. * @example
  9936. * $(document).ready( function() {
  9937. * $('#example').dataTable( {
  9938. * "language": {
  9939. * "decimal": ","
  9940. * "thousands": "."
  9941. * }
  9942. * } );
  9943. * } );
  9944. */
  9945. "sDecimal": "",
  9946. /**
  9947. * DataTables has a build in number formatter (`formatNumber`) which is
  9948. * used to format large numbers that are used in the table information.
  9949. * By default a comma is used, but this can be trivially changed to any
  9950. * character you wish with this parameter.
  9951. * @type string
  9952. * @default ,
  9953. *
  9954. * @dtopt Language
  9955. * @name DataTable.defaults.language.thousands
  9956. *
  9957. * @example
  9958. * $(document).ready( function() {
  9959. * $('#example').dataTable( {
  9960. * "language": {
  9961. * "thousands": "'"
  9962. * }
  9963. * } );
  9964. * } );
  9965. */
  9966. "sThousands": ",",
  9967. /**
  9968. * Detail the action that will be taken when the drop down menu for the
  9969. * pagination length option is changed. The '_MENU_' variable is replaced
  9970. * with a default select list of 10, 25, 50 and 100, and can be replaced
  9971. * with a custom select box if required.
  9972. * @type string
  9973. * @default Show _MENU_ entries
  9974. *
  9975. * @dtopt Language
  9976. * @name DataTable.defaults.language.lengthMenu
  9977. *
  9978. * @example
  9979. * // Language change only
  9980. * $(document).ready( function() {
  9981. * $('#example').dataTable( {
  9982. * "language": {
  9983. * "lengthMenu": "Display _MENU_ records"
  9984. * }
  9985. * } );
  9986. * } );
  9987. *
  9988. * @example
  9989. * // Language and options change
  9990. * $(document).ready( function() {
  9991. * $('#example').dataTable( {
  9992. * "language": {
  9993. * "lengthMenu": 'Display <select>'+
  9994. * '<option value="10">10</option>'+
  9995. * '<option value="20">20</option>'+
  9996. * '<option value="30">30</option>'+
  9997. * '<option value="40">40</option>'+
  9998. * '<option value="50">50</option>'+
  9999. * '<option value="-1">All</option>'+
  10000. * '</select> records'
  10001. * }
  10002. * } );
  10003. * } );
  10004. */
  10005. "sLengthMenu": "Show _MENU_ entries",
  10006. /**
  10007. * When using Ajax sourced data and during the first draw when DataTables is
  10008. * gathering the data, this message is shown in an empty row in the table to
  10009. * indicate to the end user the the data is being loaded. Note that this
  10010. * parameter is not used when loading data by server-side processing, just
  10011. * Ajax sourced data with client-side processing.
  10012. * @type string
  10013. * @default Loading...
  10014. *
  10015. * @dtopt Language
  10016. * @name DataTable.defaults.language.loadingRecords
  10017. *
  10018. * @example
  10019. * $(document).ready( function() {
  10020. * $('#example').dataTable( {
  10021. * "language": {
  10022. * "loadingRecords": "Please wait - loading..."
  10023. * }
  10024. * } );
  10025. * } );
  10026. */
  10027. "sLoadingRecords": "Loading...",
  10028. /**
  10029. * Text which is displayed when the table is processing a user action
  10030. * (usually a sort command or similar).
  10031. * @type string
  10032. * @default Processing...
  10033. *
  10034. * @dtopt Language
  10035. * @name DataTable.defaults.language.processing
  10036. *
  10037. * @example
  10038. * $(document).ready( function() {
  10039. * $('#example').dataTable( {
  10040. * "language": {
  10041. * "processing": "DataTables is currently busy"
  10042. * }
  10043. * } );
  10044. * } );
  10045. */
  10046. "sProcessing": "Processing...",
  10047. /**
  10048. * Details the actions that will be taken when the user types into the
  10049. * filtering input text box. The variable "_INPUT_", if used in the string,
  10050. * is replaced with the HTML text box for the filtering input allowing
  10051. * control over where it appears in the string. If "_INPUT_" is not given
  10052. * then the input box is appended to the string automatically.
  10053. * @type string
  10054. * @default Search:
  10055. *
  10056. * @dtopt Language
  10057. * @name DataTable.defaults.language.search
  10058. *
  10059. * @example
  10060. * // Input text box will be appended at the end automatically
  10061. * $(document).ready( function() {
  10062. * $('#example').dataTable( {
  10063. * "language": {
  10064. * "search": "Filter records:"
  10065. * }
  10066. * } );
  10067. * } );
  10068. *
  10069. * @example
  10070. * // Specify where the filter should appear
  10071. * $(document).ready( function() {
  10072. * $('#example').dataTable( {
  10073. * "language": {
  10074. * "search": "Apply filter _INPUT_ to table"
  10075. * }
  10076. * } );
  10077. * } );
  10078. */
  10079. "sSearch": "Search:",
  10080. /**
  10081. * Assign a `placeholder` attribute to the search `input` element
  10082. * @type string
  10083. * @default
  10084. *
  10085. * @dtopt Language
  10086. * @name DataTable.defaults.language.searchPlaceholder
  10087. */
  10088. "sSearchPlaceholder": "",
  10089. /**
  10090. * All of the language information can be stored in a file on the
  10091. * server-side, which DataTables will look up if this parameter is passed.
  10092. * It must store the URL of the language file, which is in a JSON format,
  10093. * and the object has the same properties as the oLanguage object in the
  10094. * initialiser object (i.e. the above parameters). Please refer to one of
  10095. * the example language files to see how this works in action.
  10096. * @type string
  10097. * @default <i>Empty string - i.e. disabled</i>
  10098. *
  10099. * @dtopt Language
  10100. * @name DataTable.defaults.language.url
  10101. *
  10102. * @example
  10103. * $(document).ready( function() {
  10104. * $('#example').dataTable( {
  10105. * "language": {
  10106. * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  10107. * }
  10108. * } );
  10109. * } );
  10110. */
  10111. "sUrl": "",
  10112. /**
  10113. * Text shown inside the table records when the is no information to be
  10114. * displayed after filtering. `emptyTable` is shown when there is simply no
  10115. * information in the table at all (regardless of filtering).
  10116. * @type string
  10117. * @default No matching records found
  10118. *
  10119. * @dtopt Language
  10120. * @name DataTable.defaults.language.zeroRecords
  10121. *
  10122. * @example
  10123. * $(document).ready( function() {
  10124. * $('#example').dataTable( {
  10125. * "language": {
  10126. * "zeroRecords": "No records to display"
  10127. * }
  10128. * } );
  10129. * } );
  10130. */
  10131. "sZeroRecords": "No matching records found"
  10132. },
  10133. /**
  10134. * This parameter allows you to have define the global filtering state at
  10135. * initialisation time. As an object the `search` parameter must be
  10136. * defined, but all other parameters are optional. When `regex` is true,
  10137. * the search string will be treated as a regular expression, when false
  10138. * (default) it will be treated as a straight string. When `smart`
  10139. * DataTables will use it's smart filtering methods (to word match at
  10140. * any point in the data), when false this will not be done.
  10141. * @namespace
  10142. * @extends DataTable.models.oSearch
  10143. *
  10144. * @dtopt Options
  10145. * @name DataTable.defaults.search
  10146. *
  10147. * @example
  10148. * $(document).ready( function() {
  10149. * $('#example').dataTable( {
  10150. * "search": {"search": "Initial search"}
  10151. * } );
  10152. * } )
  10153. */
  10154. "oSearch": $.extend( {}, DataTable.models.oSearch ),
  10155. /**
  10156. * __Deprecated__ The functionality provided by this parameter has now been
  10157. * superseded by that provided through `ajax`, which should be used instead.
  10158. *
  10159. * By default DataTables will look for the property `data` (or `aaData` for
  10160. * compatibility with DataTables 1.9-) when obtaining data from an Ajax
  10161. * source or for server-side processing - this parameter allows that
  10162. * property to be changed. You can use Javascript dotted object notation to
  10163. * get a data source for multiple levels of nesting.
  10164. * @type string
  10165. * @default data
  10166. *
  10167. * @dtopt Options
  10168. * @dtopt Server-side
  10169. * @name DataTable.defaults.ajaxDataProp
  10170. *
  10171. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10172. */
  10173. "sAjaxDataProp": "data",
  10174. /**
  10175. * __Deprecated__ The functionality provided by this parameter has now been
  10176. * superseded by that provided through `ajax`, which should be used instead.
  10177. *
  10178. * You can instruct DataTables to load data from an external
  10179. * source using this parameter (use aData if you want to pass data in you
  10180. * already have). Simply provide a url a JSON object can be obtained from.
  10181. * @type string
  10182. * @default null
  10183. *
  10184. * @dtopt Options
  10185. * @dtopt Server-side
  10186. * @name DataTable.defaults.ajaxSource
  10187. *
  10188. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10189. */
  10190. "sAjaxSource": null,
  10191. /**
  10192. * This initialisation variable allows you to specify exactly where in the
  10193. * DOM you want DataTables to inject the various controls it adds to the page
  10194. * (for example you might want the pagination controls at the top of the
  10195. * table). DIV elements (with or without a custom class) can also be added to
  10196. * aid styling. The follow syntax is used:
  10197. * <ul>
  10198. * <li>The following options are allowed:
  10199. * <ul>
  10200. * <li>'l' - Length changing</li>
  10201. * <li>'f' - Filtering input</li>
  10202. * <li>'t' - The table!</li>
  10203. * <li>'i' - Information</li>
  10204. * <li>'p' - Pagination</li>
  10205. * <li>'r' - pRocessing</li>
  10206. * </ul>
  10207. * </li>
  10208. * <li>The following constants are allowed:
  10209. * <ul>
  10210. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  10211. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  10212. * </ul>
  10213. * </li>
  10214. * <li>The following syntax is expected:
  10215. * <ul>
  10216. * <li>'&lt;' and '&gt;' - div elements</li>
  10217. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  10218. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  10219. * </ul>
  10220. * </li>
  10221. * <li>Examples:
  10222. * <ul>
  10223. * <li>'&lt;"wrapper"flipt&gt;'</li>
  10224. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  10225. * </ul>
  10226. * </li>
  10227. * </ul>
  10228. * @type string
  10229. * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
  10230. * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
  10231. *
  10232. * @dtopt Options
  10233. * @name DataTable.defaults.dom
  10234. *
  10235. * @example
  10236. * $(document).ready( function() {
  10237. * $('#example').dataTable( {
  10238. * "dom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&gt;'
  10239. * } );
  10240. * } );
  10241. */
  10242. "sDom": "lfrtip",
  10243. /**
  10244. * Search delay option. This will throttle full table searches that use the
  10245. * DataTables provided search input element (it does not effect calls to
  10246. * `dt-api search()`, providing a delay before the search is made.
  10247. * @type integer
  10248. * @default 0
  10249. *
  10250. * @dtopt Options
  10251. * @name DataTable.defaults.searchDelay
  10252. *
  10253. * @example
  10254. * $(document).ready( function() {
  10255. * $('#example').dataTable( {
  10256. * "searchDelay": 200
  10257. * } );
  10258. * } )
  10259. */
  10260. "searchDelay": null,
  10261. /**
  10262. * DataTables features six different built-in options for the buttons to
  10263. * display for pagination control:
  10264. *
  10265. * * `numbers` - Page number buttons only
  10266. * * `simple` - 'Previous' and 'Next' buttons only
  10267. * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
  10268. * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
  10269. * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers
  10270. * * `first_last_numbers` - 'First' and 'Last' buttons, plus page numbers
  10271. *
  10272. * Further methods can be added using {@link DataTable.ext.oPagination}.
  10273. * @type string
  10274. * @default simple_numbers
  10275. *
  10276. * @dtopt Options
  10277. * @name DataTable.defaults.pagingType
  10278. *
  10279. * @example
  10280. * $(document).ready( function() {
  10281. * $('#example').dataTable( {
  10282. * "pagingType": "full_numbers"
  10283. * } );
  10284. * } )
  10285. */
  10286. "sPaginationType": "simple_numbers",
  10287. /**
  10288. * Enable horizontal scrolling. When a table is too wide to fit into a
  10289. * certain layout, or you have a large number of columns in the table, you
  10290. * can enable x-scrolling to show the table in a viewport, which can be
  10291. * scrolled. This property can be `true` which will allow the table to
  10292. * scroll horizontally when needed, or any CSS unit, or a number (in which
  10293. * case it will be treated as a pixel measurement). Setting as simply `true`
  10294. * is recommended.
  10295. * @type boolean|string
  10296. * @default <i>blank string - i.e. disabled</i>
  10297. *
  10298. * @dtopt Features
  10299. * @name DataTable.defaults.scrollX
  10300. *
  10301. * @example
  10302. * $(document).ready( function() {
  10303. * $('#example').dataTable( {
  10304. * "scrollX": true,
  10305. * "scrollCollapse": true
  10306. * } );
  10307. * } );
  10308. */
  10309. "sScrollX": "",
  10310. /**
  10311. * This property can be used to force a DataTable to use more width than it
  10312. * might otherwise do when x-scrolling is enabled. For example if you have a
  10313. * table which requires to be well spaced, this parameter is useful for
  10314. * "over-sizing" the table, and thus forcing scrolling. This property can by
  10315. * any CSS unit, or a number (in which case it will be treated as a pixel
  10316. * measurement).
  10317. * @type string
  10318. * @default <i>blank string - i.e. disabled</i>
  10319. *
  10320. * @dtopt Options
  10321. * @name DataTable.defaults.scrollXInner
  10322. *
  10323. * @example
  10324. * $(document).ready( function() {
  10325. * $('#example').dataTable( {
  10326. * "scrollX": "100%",
  10327. * "scrollXInner": "110%"
  10328. * } );
  10329. * } );
  10330. */
  10331. "sScrollXInner": "",
  10332. /**
  10333. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  10334. * to the given height, and enable scrolling for any data which overflows the
  10335. * current viewport. This can be used as an alternative to paging to display
  10336. * a lot of data in a small area (although paging and scrolling can both be
  10337. * enabled at the same time). This property can be any CSS unit, or a number
  10338. * (in which case it will be treated as a pixel measurement).
  10339. * @type string
  10340. * @default <i>blank string - i.e. disabled</i>
  10341. *
  10342. * @dtopt Features
  10343. * @name DataTable.defaults.scrollY
  10344. *
  10345. * @example
  10346. * $(document).ready( function() {
  10347. * $('#example').dataTable( {
  10348. * "scrollY": "200px",
  10349. * "paginate": false
  10350. * } );
  10351. * } );
  10352. */
  10353. "sScrollY": "",
  10354. /**
  10355. * __Deprecated__ The functionality provided by this parameter has now been
  10356. * superseded by that provided through `ajax`, which should be used instead.
  10357. *
  10358. * Set the HTTP method that is used to make the Ajax call for server-side
  10359. * processing or Ajax sourced data.
  10360. * @type string
  10361. * @default GET
  10362. *
  10363. * @dtopt Options
  10364. * @dtopt Server-side
  10365. * @name DataTable.defaults.serverMethod
  10366. *
  10367. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10368. */
  10369. "sServerMethod": "GET",
  10370. /**
  10371. * DataTables makes use of renderers when displaying HTML elements for
  10372. * a table. These renderers can be added or modified by plug-ins to
  10373. * generate suitable mark-up for a site. For example the Bootstrap
  10374. * integration plug-in for DataTables uses a paging button renderer to
  10375. * display pagination buttons in the mark-up required by Bootstrap.
  10376. *
  10377. * For further information about the renderers available see
  10378. * DataTable.ext.renderer
  10379. * @type string|object
  10380. * @default null
  10381. *
  10382. * @name DataTable.defaults.renderer
  10383. *
  10384. */
  10385. "renderer": null,
  10386. /**
  10387. * Set the data property name that DataTables should use to get a row's id
  10388. * to set as the `id` property in the node.
  10389. * @type string
  10390. * @default DT_RowId
  10391. *
  10392. * @name DataTable.defaults.rowId
  10393. */
  10394. "rowId": "DT_RowId"
  10395. };
  10396. _fnHungarianMap( DataTable.defaults );
  10397. /*
  10398. * Developer note - See note in model.defaults.js about the use of Hungarian
  10399. * notation and camel case.
  10400. */
  10401. /**
  10402. * Column options that can be given to DataTables at initialisation time.
  10403. * @namespace
  10404. */
  10405. DataTable.defaults.column = {
  10406. /**
  10407. * Define which column(s) an order will occur on for this column. This
  10408. * allows a column's ordering to take multiple columns into account when
  10409. * doing a sort or use the data from a different column. For example first
  10410. * name / last name columns make sense to do a multi-column sort over the
  10411. * two columns.
  10412. * @type array|int
  10413. * @default null <i>Takes the value of the column index automatically</i>
  10414. *
  10415. * @name DataTable.defaults.column.orderData
  10416. * @dtopt Columns
  10417. *
  10418. * @example
  10419. * // Using `columnDefs`
  10420. * $(document).ready( function() {
  10421. * $('#example').dataTable( {
  10422. * "columnDefs": [
  10423. * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
  10424. * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
  10425. * { "orderData": 2, "targets": [ 2 ] }
  10426. * ]
  10427. * } );
  10428. * } );
  10429. *
  10430. * @example
  10431. * // Using `columns`
  10432. * $(document).ready( function() {
  10433. * $('#example').dataTable( {
  10434. * "columns": [
  10435. * { "orderData": [ 0, 1 ] },
  10436. * { "orderData": [ 1, 0 ] },
  10437. * { "orderData": 2 },
  10438. * null,
  10439. * null
  10440. * ]
  10441. * } );
  10442. * } );
  10443. */
  10444. "aDataSort": null,
  10445. "iDataSort": -1,
  10446. /**
  10447. * You can control the default ordering direction, and even alter the
  10448. * behaviour of the sort handler (i.e. only allow ascending ordering etc)
  10449. * using this parameter.
  10450. * @type array
  10451. * @default [ 'asc', 'desc' ]
  10452. *
  10453. * @name DataTable.defaults.column.orderSequence
  10454. * @dtopt Columns
  10455. *
  10456. * @example
  10457. * // Using `columnDefs`
  10458. * $(document).ready( function() {
  10459. * $('#example').dataTable( {
  10460. * "columnDefs": [
  10461. * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
  10462. * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
  10463. * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
  10464. * ]
  10465. * } );
  10466. * } );
  10467. *
  10468. * @example
  10469. * // Using `columns`
  10470. * $(document).ready( function() {
  10471. * $('#example').dataTable( {
  10472. * "columns": [
  10473. * null,
  10474. * { "orderSequence": [ "asc" ] },
  10475. * { "orderSequence": [ "desc", "asc", "asc" ] },
  10476. * { "orderSequence": [ "desc" ] },
  10477. * null
  10478. * ]
  10479. * } );
  10480. * } );
  10481. */
  10482. "asSorting": [ 'asc', 'desc' ],
  10483. /**
  10484. * Enable or disable filtering on the data in this column.
  10485. * @type boolean
  10486. * @default true
  10487. *
  10488. * @name DataTable.defaults.column.searchable
  10489. * @dtopt Columns
  10490. *
  10491. * @example
  10492. * // Using `columnDefs`
  10493. * $(document).ready( function() {
  10494. * $('#example').dataTable( {
  10495. * "columnDefs": [
  10496. * { "searchable": false, "targets": [ 0 ] }
  10497. * ] } );
  10498. * } );
  10499. *
  10500. * @example
  10501. * // Using `columns`
  10502. * $(document).ready( function() {
  10503. * $('#example').dataTable( {
  10504. * "columns": [
  10505. * { "searchable": false },
  10506. * null,
  10507. * null,
  10508. * null,
  10509. * null
  10510. * ] } );
  10511. * } );
  10512. */
  10513. "bSearchable": true,
  10514. /**
  10515. * Enable or disable ordering on this column.
  10516. * @type boolean
  10517. * @default true
  10518. *
  10519. * @name DataTable.defaults.column.orderable
  10520. * @dtopt Columns
  10521. *
  10522. * @example
  10523. * // Using `columnDefs`
  10524. * $(document).ready( function() {
  10525. * $('#example').dataTable( {
  10526. * "columnDefs": [
  10527. * { "orderable": false, "targets": [ 0 ] }
  10528. * ] } );
  10529. * } );
  10530. *
  10531. * @example
  10532. * // Using `columns`
  10533. * $(document).ready( function() {
  10534. * $('#example').dataTable( {
  10535. * "columns": [
  10536. * { "orderable": false },
  10537. * null,
  10538. * null,
  10539. * null,
  10540. * null
  10541. * ] } );
  10542. * } );
  10543. */
  10544. "bSortable": true,
  10545. /**
  10546. * Enable or disable the display of this column.
  10547. * @type boolean
  10548. * @default true
  10549. *
  10550. * @name DataTable.defaults.column.visible
  10551. * @dtopt Columns
  10552. *
  10553. * @example
  10554. * // Using `columnDefs`
  10555. * $(document).ready( function() {
  10556. * $('#example').dataTable( {
  10557. * "columnDefs": [
  10558. * { "visible": false, "targets": [ 0 ] }
  10559. * ] } );
  10560. * } );
  10561. *
  10562. * @example
  10563. * // Using `columns`
  10564. * $(document).ready( function() {
  10565. * $('#example').dataTable( {
  10566. * "columns": [
  10567. * { "visible": false },
  10568. * null,
  10569. * null,
  10570. * null,
  10571. * null
  10572. * ] } );
  10573. * } );
  10574. */
  10575. "bVisible": true,
  10576. /**
  10577. * Developer definable function that is called whenever a cell is created (Ajax source,
  10578. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  10579. * allowing you to modify the DOM element (add background colour for example) when the
  10580. * element is available.
  10581. * @type function
  10582. * @param {element} td The TD node that has been created
  10583. * @param {*} cellData The Data for the cell
  10584. * @param {array|object} rowData The data for the whole row
  10585. * @param {int} row The row index for the aoData data store
  10586. * @param {int} col The column index for aoColumns
  10587. *
  10588. * @name DataTable.defaults.column.createdCell
  10589. * @dtopt Columns
  10590. *
  10591. * @example
  10592. * $(document).ready( function() {
  10593. * $('#example').dataTable( {
  10594. * "columnDefs": [ {
  10595. * "targets": [3],
  10596. * "createdCell": function (td, cellData, rowData, row, col) {
  10597. * if ( cellData == "1.7" ) {
  10598. * $(td).css('color', 'blue')
  10599. * }
  10600. * }
  10601. * } ]
  10602. * });
  10603. * } );
  10604. */
  10605. "fnCreatedCell": null,
  10606. /**
  10607. * This parameter has been replaced by `data` in DataTables to ensure naming
  10608. * consistency. `dataProp` can still be used, as there is backwards
  10609. * compatibility in DataTables for this option, but it is strongly
  10610. * recommended that you use `data` in preference to `dataProp`.
  10611. * @name DataTable.defaults.column.dataProp
  10612. */
  10613. /**
  10614. * This property can be used to read data from any data source property,
  10615. * including deeply nested objects / properties. `data` can be given in a
  10616. * number of different ways which effect its behaviour:
  10617. *
  10618. * * `integer` - treated as an array index for the data source. This is the
  10619. * default that DataTables uses (incrementally increased for each column).
  10620. * * `string` - read an object property from the data source. There are
  10621. * three 'special' options that can be used in the string to alter how
  10622. * DataTables reads the data from the source object:
  10623. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10624. * Javascript to read from nested objects, so to can the options
  10625. * specified in `data`. For example: `browser.version` or
  10626. * `browser.name`. If your object parameter name contains a period, use
  10627. * `\\` to escape it - i.e. `first\\.name`.
  10628. * * `[]` - Array notation. DataTables can automatically combine data
  10629. * from and array source, joining the data with the characters provided
  10630. * between the two brackets. For example: `name[, ]` would provide a
  10631. * comma-space separated list from the source array. If no characters
  10632. * are provided between the brackets, the original array source is
  10633. * returned.
  10634. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10635. * execute a function of the name given. For example: `browser()` for a
  10636. * simple function on the data source, `browser.version()` for a
  10637. * function in a nested property or even `browser().version` to get an
  10638. * object property if the function called returns an object. Note that
  10639. * function notation is recommended for use in `render` rather than
  10640. * `data` as it is much simpler to use as a renderer.
  10641. * * `null` - use the original data source for the row rather than plucking
  10642. * data directly from it. This action has effects on two other
  10643. * initialisation options:
  10644. * * `defaultContent` - When null is given as the `data` option and
  10645. * `defaultContent` is specified for the column, the value defined by
  10646. * `defaultContent` will be used for the cell.
  10647. * * `render` - When null is used for the `data` option and the `render`
  10648. * option is specified for the column, the whole data source for the
  10649. * row is used for the renderer.
  10650. * * `function` - the function given will be executed whenever DataTables
  10651. * needs to set or get the data for a cell in the column. The function
  10652. * takes three parameters:
  10653. * * Parameters:
  10654. * * `{array|object}` The data source for the row
  10655. * * `{string}` The type call data requested - this will be 'set' when
  10656. * setting data or 'filter', 'display', 'type', 'sort' or undefined
  10657. * when gathering data. Note that when `undefined` is given for the
  10658. * type DataTables expects to get the raw data for the object back<
  10659. * * `{*}` Data to set when the second parameter is 'set'.
  10660. * * Return:
  10661. * * The return value from the function is not required when 'set' is
  10662. * the type of call, but otherwise the return is what will be used
  10663. * for the data requested.
  10664. *
  10665. * Note that `data` is a getter and setter option. If you just require
  10666. * formatting of data for output, you will likely want to use `render` which
  10667. * is simply a getter and thus simpler to use.
  10668. *
  10669. * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
  10670. * name change reflects the flexibility of this property and is consistent
  10671. * with the naming of mRender. If 'mDataProp' is given, then it will still
  10672. * be used by DataTables, as it automatically maps the old name to the new
  10673. * if required.
  10674. *
  10675. * @type string|int|function|null
  10676. * @default null <i>Use automatically calculated column index</i>
  10677. *
  10678. * @name DataTable.defaults.column.data
  10679. * @dtopt Columns
  10680. *
  10681. * @example
  10682. * // Read table data from objects
  10683. * // JSON structure for each row:
  10684. * // {
  10685. * // "engine": {value},
  10686. * // "browser": {value},
  10687. * // "platform": {value},
  10688. * // "version": {value},
  10689. * // "grade": {value}
  10690. * // }
  10691. * $(document).ready( function() {
  10692. * $('#example').dataTable( {
  10693. * "ajaxSource": "sources/objects.txt",
  10694. * "columns": [
  10695. * { "data": "engine" },
  10696. * { "data": "browser" },
  10697. * { "data": "platform" },
  10698. * { "data": "version" },
  10699. * { "data": "grade" }
  10700. * ]
  10701. * } );
  10702. * } );
  10703. *
  10704. * @example
  10705. * // Read information from deeply nested objects
  10706. * // JSON structure for each row:
  10707. * // {
  10708. * // "engine": {value},
  10709. * // "browser": {value},
  10710. * // "platform": {
  10711. * // "inner": {value}
  10712. * // },
  10713. * // "details": [
  10714. * // {value}, {value}
  10715. * // ]
  10716. * // }
  10717. * $(document).ready( function() {
  10718. * $('#example').dataTable( {
  10719. * "ajaxSource": "sources/deep.txt",
  10720. * "columns": [
  10721. * { "data": "engine" },
  10722. * { "data": "browser" },
  10723. * { "data": "platform.inner" },
  10724. * { "data": "details.0" },
  10725. * { "data": "details.1" }
  10726. * ]
  10727. * } );
  10728. * } );
  10729. *
  10730. * @example
  10731. * // Using `data` as a function to provide different information for
  10732. * // sorting, filtering and display. In this case, currency (price)
  10733. * $(document).ready( function() {
  10734. * $('#example').dataTable( {
  10735. * "columnDefs": [ {
  10736. * "targets": [ 0 ],
  10737. * "data": function ( source, type, val ) {
  10738. * if (type === 'set') {
  10739. * source.price = val;
  10740. * // Store the computed dislay and filter values for efficiency
  10741. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  10742. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  10743. * return;
  10744. * }
  10745. * else if (type === 'display') {
  10746. * return source.price_display;
  10747. * }
  10748. * else if (type === 'filter') {
  10749. * return source.price_filter;
  10750. * }
  10751. * // 'sort', 'type' and undefined all just use the integer
  10752. * return source.price;
  10753. * }
  10754. * } ]
  10755. * } );
  10756. * } );
  10757. *
  10758. * @example
  10759. * // Using default content
  10760. * $(document).ready( function() {
  10761. * $('#example').dataTable( {
  10762. * "columnDefs": [ {
  10763. * "targets": [ 0 ],
  10764. * "data": null,
  10765. * "defaultContent": "Click to edit"
  10766. * } ]
  10767. * } );
  10768. * } );
  10769. *
  10770. * @example
  10771. * // Using array notation - outputting a list from an array
  10772. * $(document).ready( function() {
  10773. * $('#example').dataTable( {
  10774. * "columnDefs": [ {
  10775. * "targets": [ 0 ],
  10776. * "data": "name[, ]"
  10777. * } ]
  10778. * } );
  10779. * } );
  10780. *
  10781. */
  10782. "mData": null,
  10783. /**
  10784. * This property is the rendering partner to `data` and it is suggested that
  10785. * when you want to manipulate data for display (including filtering,
  10786. * sorting etc) without altering the underlying data for the table, use this
  10787. * property. `render` can be considered to be the the read only companion to
  10788. * `data` which is read / write (then as such more complex). Like `data`
  10789. * this option can be given in a number of different ways to effect its
  10790. * behaviour:
  10791. *
  10792. * * `integer` - treated as an array index for the data source. This is the
  10793. * default that DataTables uses (incrementally increased for each column).
  10794. * * `string` - read an object property from the data source. There are
  10795. * three 'special' options that can be used in the string to alter how
  10796. * DataTables reads the data from the source object:
  10797. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10798. * Javascript to read from nested objects, so to can the options
  10799. * specified in `data`. For example: `browser.version` or
  10800. * `browser.name`. If your object parameter name contains a period, use
  10801. * `\\` to escape it - i.e. `first\\.name`.
  10802. * * `[]` - Array notation. DataTables can automatically combine data
  10803. * from and array source, joining the data with the characters provided
  10804. * between the two brackets. For example: `name[, ]` would provide a
  10805. * comma-space separated list from the source array. If no characters
  10806. * are provided between the brackets, the original array source is
  10807. * returned.
  10808. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10809. * execute a function of the name given. For example: `browser()` for a
  10810. * simple function on the data source, `browser.version()` for a
  10811. * function in a nested property or even `browser().version` to get an
  10812. * object property if the function called returns an object.
  10813. * * `object` - use different data for the different data types requested by
  10814. * DataTables ('filter', 'display', 'type' or 'sort'). The property names
  10815. * of the object is the data type the property refers to and the value can
  10816. * defined using an integer, string or function using the same rules as
  10817. * `render` normally does. Note that an `_` option _must_ be specified.
  10818. * This is the default value to use if you haven't specified a value for
  10819. * the data type requested by DataTables.
  10820. * * `function` - the function given will be executed whenever DataTables
  10821. * needs to set or get the data for a cell in the column. The function
  10822. * takes three parameters:
  10823. * * Parameters:
  10824. * * {array|object} The data source for the row (based on `data`)
  10825. * * {string} The type call data requested - this will be 'filter',
  10826. * 'display', 'type' or 'sort'.
  10827. * * {array|object} The full data source for the row (not based on
  10828. * `data`)
  10829. * * Return:
  10830. * * The return value from the function is what will be used for the
  10831. * data requested.
  10832. *
  10833. * @type string|int|function|object|null
  10834. * @default null Use the data source value.
  10835. *
  10836. * @name DataTable.defaults.column.render
  10837. * @dtopt Columns
  10838. *
  10839. * @example
  10840. * // Create a comma separated list from an array of objects
  10841. * $(document).ready( function() {
  10842. * $('#example').dataTable( {
  10843. * "ajaxSource": "sources/deep.txt",
  10844. * "columns": [
  10845. * { "data": "engine" },
  10846. * { "data": "browser" },
  10847. * {
  10848. * "data": "platform",
  10849. * "render": "[, ].name"
  10850. * }
  10851. * ]
  10852. * } );
  10853. * } );
  10854. *
  10855. * @example
  10856. * // Execute a function to obtain data
  10857. * $(document).ready( function() {
  10858. * $('#example').dataTable( {
  10859. * "columnDefs": [ {
  10860. * "targets": [ 0 ],
  10861. * "data": null, // Use the full data source object for the renderer's source
  10862. * "render": "browserName()"
  10863. * } ]
  10864. * } );
  10865. * } );
  10866. *
  10867. * @example
  10868. * // As an object, extracting different data for the different types
  10869. * // This would be used with a data source such as:
  10870. * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
  10871. * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
  10872. * // (which has both forms) is used for filtering for if a user inputs either format, while
  10873. * // the formatted phone number is the one that is shown in the table.
  10874. * $(document).ready( function() {
  10875. * $('#example').dataTable( {
  10876. * "columnDefs": [ {
  10877. * "targets": [ 0 ],
  10878. * "data": null, // Use the full data source object for the renderer's source
  10879. * "render": {
  10880. * "_": "phone",
  10881. * "filter": "phone_filter",
  10882. * "display": "phone_display"
  10883. * }
  10884. * } ]
  10885. * } );
  10886. * } );
  10887. *
  10888. * @example
  10889. * // Use as a function to create a link from the data source
  10890. * $(document).ready( function() {
  10891. * $('#example').dataTable( {
  10892. * "columnDefs": [ {
  10893. * "targets": [ 0 ],
  10894. * "data": "download_link",
  10895. * "render": function ( data, type, full ) {
  10896. * return '<a href="'+data+'">Download</a>';
  10897. * }
  10898. * } ]
  10899. * } );
  10900. * } );
  10901. */
  10902. "mRender": null,
  10903. /**
  10904. * Change the cell type created for the column - either TD cells or TH cells. This
  10905. * can be useful as TH cells have semantic meaning in the table body, allowing them
  10906. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  10907. * @type string
  10908. * @default td
  10909. *
  10910. * @name DataTable.defaults.column.cellType
  10911. * @dtopt Columns
  10912. *
  10913. * @example
  10914. * // Make the first column use TH cells
  10915. * $(document).ready( function() {
  10916. * $('#example').dataTable( {
  10917. * "columnDefs": [ {
  10918. * "targets": [ 0 ],
  10919. * "cellType": "th"
  10920. * } ]
  10921. * } );
  10922. * } );
  10923. */
  10924. "sCellType": "td",
  10925. /**
  10926. * Class to give to each cell in this column.
  10927. * @type string
  10928. * @default <i>Empty string</i>
  10929. *
  10930. * @name DataTable.defaults.column.class
  10931. * @dtopt Columns
  10932. *
  10933. * @example
  10934. * // Using `columnDefs`
  10935. * $(document).ready( function() {
  10936. * $('#example').dataTable( {
  10937. * "columnDefs": [
  10938. * { "class": "my_class", "targets": [ 0 ] }
  10939. * ]
  10940. * } );
  10941. * } );
  10942. *
  10943. * @example
  10944. * // Using `columns`
  10945. * $(document).ready( function() {
  10946. * $('#example').dataTable( {
  10947. * "columns": [
  10948. * { "class": "my_class" },
  10949. * null,
  10950. * null,
  10951. * null,
  10952. * null
  10953. * ]
  10954. * } );
  10955. * } );
  10956. */
  10957. "sClass": "",
  10958. /**
  10959. * When DataTables calculates the column widths to assign to each column,
  10960. * it finds the longest string in each column and then constructs a
  10961. * temporary table and reads the widths from that. The problem with this
  10962. * is that "mmm" is much wider then "iiii", but the latter is a longer
  10963. * string - thus the calculation can go wrong (doing it properly and putting
  10964. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  10965. * a "work around" we provide this option. It will append its value to the
  10966. * text that is found to be the longest string for the column - i.e. padding.
  10967. * Generally you shouldn't need this!
  10968. * @type string
  10969. * @default <i>Empty string<i>
  10970. *
  10971. * @name DataTable.defaults.column.contentPadding
  10972. * @dtopt Columns
  10973. *
  10974. * @example
  10975. * // Using `columns`
  10976. * $(document).ready( function() {
  10977. * $('#example').dataTable( {
  10978. * "columns": [
  10979. * null,
  10980. * null,
  10981. * null,
  10982. * {
  10983. * "contentPadding": "mmm"
  10984. * }
  10985. * ]
  10986. * } );
  10987. * } );
  10988. */
  10989. "sContentPadding": "",
  10990. /**
  10991. * Allows a default value to be given for a column's data, and will be used
  10992. * whenever a null data source is encountered (this can be because `data`
  10993. * is set to null, or because the data source itself is null).
  10994. * @type string
  10995. * @default null
  10996. *
  10997. * @name DataTable.defaults.column.defaultContent
  10998. * @dtopt Columns
  10999. *
  11000. * @example
  11001. * // Using `columnDefs`
  11002. * $(document).ready( function() {
  11003. * $('#example').dataTable( {
  11004. * "columnDefs": [
  11005. * {
  11006. * "data": null,
  11007. * "defaultContent": "Edit",
  11008. * "targets": [ -1 ]
  11009. * }
  11010. * ]
  11011. * } );
  11012. * } );
  11013. *
  11014. * @example
  11015. * // Using `columns`
  11016. * $(document).ready( function() {
  11017. * $('#example').dataTable( {
  11018. * "columns": [
  11019. * null,
  11020. * null,
  11021. * null,
  11022. * {
  11023. * "data": null,
  11024. * "defaultContent": "Edit"
  11025. * }
  11026. * ]
  11027. * } );
  11028. * } );
  11029. */
  11030. "sDefaultContent": null,
  11031. /**
  11032. * This parameter is only used in DataTables' server-side processing. It can
  11033. * be exceptionally useful to know what columns are being displayed on the
  11034. * client side, and to map these to database fields. When defined, the names
  11035. * also allow DataTables to reorder information from the server if it comes
  11036. * back in an unexpected order (i.e. if you switch your columns around on the
  11037. * client-side, your server-side code does not also need updating).
  11038. * @type string
  11039. * @default <i>Empty string</i>
  11040. *
  11041. * @name DataTable.defaults.column.name
  11042. * @dtopt Columns
  11043. *
  11044. * @example
  11045. * // Using `columnDefs`
  11046. * $(document).ready( function() {
  11047. * $('#example').dataTable( {
  11048. * "columnDefs": [
  11049. * { "name": "engine", "targets": [ 0 ] },
  11050. * { "name": "browser", "targets": [ 1 ] },
  11051. * { "name": "platform", "targets": [ 2 ] },
  11052. * { "name": "version", "targets": [ 3 ] },
  11053. * { "name": "grade", "targets": [ 4 ] }
  11054. * ]
  11055. * } );
  11056. * } );
  11057. *
  11058. * @example
  11059. * // Using `columns`
  11060. * $(document).ready( function() {
  11061. * $('#example').dataTable( {
  11062. * "columns": [
  11063. * { "name": "engine" },
  11064. * { "name": "browser" },
  11065. * { "name": "platform" },
  11066. * { "name": "version" },
  11067. * { "name": "grade" }
  11068. * ]
  11069. * } );
  11070. * } );
  11071. */
  11072. "sName": "",
  11073. /**
  11074. * Defines a data source type for the ordering which can be used to read
  11075. * real-time information from the table (updating the internally cached
  11076. * version) prior to ordering. This allows ordering to occur on user
  11077. * editable elements such as form inputs.
  11078. * @type string
  11079. * @default std
  11080. *
  11081. * @name DataTable.defaults.column.orderDataType
  11082. * @dtopt Columns
  11083. *
  11084. * @example
  11085. * // Using `columnDefs`
  11086. * $(document).ready( function() {
  11087. * $('#example').dataTable( {
  11088. * "columnDefs": [
  11089. * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
  11090. * { "type": "numeric", "targets": [ 3 ] },
  11091. * { "orderDataType": "dom-select", "targets": [ 4 ] },
  11092. * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
  11093. * ]
  11094. * } );
  11095. * } );
  11096. *
  11097. * @example
  11098. * // Using `columns`
  11099. * $(document).ready( function() {
  11100. * $('#example').dataTable( {
  11101. * "columns": [
  11102. * null,
  11103. * null,
  11104. * { "orderDataType": "dom-text" },
  11105. * { "orderDataType": "dom-text", "type": "numeric" },
  11106. * { "orderDataType": "dom-select" },
  11107. * { "orderDataType": "dom-checkbox" }
  11108. * ]
  11109. * } );
  11110. * } );
  11111. */
  11112. "sSortDataType": "std",
  11113. /**
  11114. * The title of this column.
  11115. * @type string
  11116. * @default null <i>Derived from the 'TH' value for this column in the
  11117. * original HTML table.</i>
  11118. *
  11119. * @name DataTable.defaults.column.title
  11120. * @dtopt Columns
  11121. *
  11122. * @example
  11123. * // Using `columnDefs`
  11124. * $(document).ready( function() {
  11125. * $('#example').dataTable( {
  11126. * "columnDefs": [
  11127. * { "title": "My column title", "targets": [ 0 ] }
  11128. * ]
  11129. * } );
  11130. * } );
  11131. *
  11132. * @example
  11133. * // Using `columns`
  11134. * $(document).ready( function() {
  11135. * $('#example').dataTable( {
  11136. * "columns": [
  11137. * { "title": "My column title" },
  11138. * null,
  11139. * null,
  11140. * null,
  11141. * null
  11142. * ]
  11143. * } );
  11144. * } );
  11145. */
  11146. "sTitle": null,
  11147. /**
  11148. * The type allows you to specify how the data for this column will be
  11149. * ordered. Four types (string, numeric, date and html (which will strip
  11150. * HTML tags before ordering)) are currently available. Note that only date
  11151. * formats understood by Javascript's Date() object will be accepted as type
  11152. * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
  11153. * 'numeric', 'date' or 'html' (by default). Further types can be adding
  11154. * through plug-ins.
  11155. * @type string
  11156. * @default null <i>Auto-detected from raw data</i>
  11157. *
  11158. * @name DataTable.defaults.column.type
  11159. * @dtopt Columns
  11160. *
  11161. * @example
  11162. * // Using `columnDefs`
  11163. * $(document).ready( function() {
  11164. * $('#example').dataTable( {
  11165. * "columnDefs": [
  11166. * { "type": "html", "targets": [ 0 ] }
  11167. * ]
  11168. * } );
  11169. * } );
  11170. *
  11171. * @example
  11172. * // Using `columns`
  11173. * $(document).ready( function() {
  11174. * $('#example').dataTable( {
  11175. * "columns": [
  11176. * { "type": "html" },
  11177. * null,
  11178. * null,
  11179. * null,
  11180. * null
  11181. * ]
  11182. * } );
  11183. * } );
  11184. */
  11185. "sType": null,
  11186. /**
  11187. * Defining the width of the column, this parameter may take any CSS value
  11188. * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
  11189. * been given a specific width through this interface ensuring that the table
  11190. * remains readable.
  11191. * @type string
  11192. * @default null <i>Automatic</i>
  11193. *
  11194. * @name DataTable.defaults.column.width
  11195. * @dtopt Columns
  11196. *
  11197. * @example
  11198. * // Using `columnDefs`
  11199. * $(document).ready( function() {
  11200. * $('#example').dataTable( {
  11201. * "columnDefs": [
  11202. * { "width": "20%", "targets": [ 0 ] }
  11203. * ]
  11204. * } );
  11205. * } );
  11206. *
  11207. * @example
  11208. * // Using `columns`
  11209. * $(document).ready( function() {
  11210. * $('#example').dataTable( {
  11211. * "columns": [
  11212. * { "width": "20%" },
  11213. * null,
  11214. * null,
  11215. * null,
  11216. * null
  11217. * ]
  11218. * } );
  11219. * } );
  11220. */
  11221. "sWidth": null
  11222. };
  11223. _fnHungarianMap( DataTable.defaults.column );
  11224. /**
  11225. * DataTables settings object - this holds all the information needed for a
  11226. * given table, including configuration, data and current application of the
  11227. * table options. DataTables does not have a single instance for each DataTable
  11228. * with the settings attached to that instance, but rather instances of the
  11229. * DataTable "class" are created on-the-fly as needed (typically by a
  11230. * $().dataTable() call) and the settings object is then applied to that
  11231. * instance.
  11232. *
  11233. * Note that this object is related to {@link DataTable.defaults} but this
  11234. * one is the internal data store for DataTables's cache of columns. It should
  11235. * NOT be manipulated outside of DataTables. Any configuration should be done
  11236. * through the initialisation options.
  11237. * @namespace
  11238. * @todo Really should attach the settings object to individual instances so we
  11239. * don't need to create new instances on each $().dataTable() call (if the
  11240. * table already exists). It would also save passing oSettings around and
  11241. * into every single function. However, this is a very significant
  11242. * architecture change for DataTables and will almost certainly break
  11243. * backwards compatibility with older installations. This is something that
  11244. * will be done in 2.0.
  11245. */
  11246. DataTable.models.oSettings = {
  11247. /**
  11248. * Primary features of DataTables and their enablement state.
  11249. * @namespace
  11250. */
  11251. "oFeatures": {
  11252. /**
  11253. * Flag to say if DataTables should automatically try to calculate the
  11254. * optimum table and columns widths (true) or not (false).
  11255. * Note that this parameter will be set by the initialisation routine. To
  11256. * set a default use {@link DataTable.defaults}.
  11257. * @type boolean
  11258. */
  11259. "bAutoWidth": null,
  11260. /**
  11261. * Delay the creation of TR and TD elements until they are actually
  11262. * needed by a driven page draw. This can give a significant speed
  11263. * increase for Ajax source and Javascript source data, but makes no
  11264. * difference at all fro DOM and server-side processing tables.
  11265. * Note that this parameter will be set by the initialisation routine. To
  11266. * set a default use {@link DataTable.defaults}.
  11267. * @type boolean
  11268. */
  11269. "bDeferRender": null,
  11270. /**
  11271. * Enable filtering on the table or not. Note that if this is disabled
  11272. * then there is no filtering at all on the table, including fnFilter.
  11273. * To just remove the filtering input use sDom and remove the 'f' option.
  11274. * Note that this parameter will be set by the initialisation routine. To
  11275. * set a default use {@link DataTable.defaults}.
  11276. * @type boolean
  11277. */
  11278. "bFilter": null,
  11279. /**
  11280. * Table information element (the 'Showing x of y records' div) enable
  11281. * flag.
  11282. * Note that this parameter will be set by the initialisation routine. To
  11283. * set a default use {@link DataTable.defaults}.
  11284. * @type boolean
  11285. */
  11286. "bInfo": null,
  11287. /**
  11288. * Present a user control allowing the end user to change the page size
  11289. * when pagination is enabled.
  11290. * Note that this parameter will be set by the initialisation routine. To
  11291. * set a default use {@link DataTable.defaults}.
  11292. * @type boolean
  11293. */
  11294. "bLengthChange": null,
  11295. /**
  11296. * Pagination enabled or not. Note that if this is disabled then length
  11297. * changing must also be disabled.
  11298. * Note that this parameter will be set by the initialisation routine. To
  11299. * set a default use {@link DataTable.defaults}.
  11300. * @type boolean
  11301. */
  11302. "bPaginate": null,
  11303. /**
  11304. * Processing indicator enable flag whenever DataTables is enacting a
  11305. * user request - typically an Ajax request for server-side processing.
  11306. * Note that this parameter will be set by the initialisation routine. To
  11307. * set a default use {@link DataTable.defaults}.
  11308. * @type boolean
  11309. */
  11310. "bProcessing": null,
  11311. /**
  11312. * Server-side processing enabled flag - when enabled DataTables will
  11313. * get all data from the server for every draw - there is no filtering,
  11314. * sorting or paging done on the client-side.
  11315. * Note that this parameter will be set by the initialisation routine. To
  11316. * set a default use {@link DataTable.defaults}.
  11317. * @type boolean
  11318. */
  11319. "bServerSide": null,
  11320. /**
  11321. * Sorting enablement flag.
  11322. * Note that this parameter will be set by the initialisation routine. To
  11323. * set a default use {@link DataTable.defaults}.
  11324. * @type boolean
  11325. */
  11326. "bSort": null,
  11327. /**
  11328. * Multi-column sorting
  11329. * Note that this parameter will be set by the initialisation routine. To
  11330. * set a default use {@link DataTable.defaults}.
  11331. * @type boolean
  11332. */
  11333. "bSortMulti": null,
  11334. /**
  11335. * Apply a class to the columns which are being sorted to provide a
  11336. * visual highlight or not. This can slow things down when enabled since
  11337. * there is a lot of DOM interaction.
  11338. * Note that this parameter will be set by the initialisation routine. To
  11339. * set a default use {@link DataTable.defaults}.
  11340. * @type boolean
  11341. */
  11342. "bSortClasses": null,
  11343. /**
  11344. * State saving enablement flag.
  11345. * Note that this parameter will be set by the initialisation routine. To
  11346. * set a default use {@link DataTable.defaults}.
  11347. * @type boolean
  11348. */
  11349. "bStateSave": null
  11350. },
  11351. /**
  11352. * Scrolling settings for a table.
  11353. * @namespace
  11354. */
  11355. "oScroll": {
  11356. /**
  11357. * When the table is shorter in height than sScrollY, collapse the
  11358. * table container down to the height of the table (when true).
  11359. * Note that this parameter will be set by the initialisation routine. To
  11360. * set a default use {@link DataTable.defaults}.
  11361. * @type boolean
  11362. */
  11363. "bCollapse": null,
  11364. /**
  11365. * Width of the scrollbar for the web-browser's platform. Calculated
  11366. * during table initialisation.
  11367. * @type int
  11368. * @default 0
  11369. */
  11370. "iBarWidth": 0,
  11371. /**
  11372. * Viewport width for horizontal scrolling. Horizontal scrolling is
  11373. * disabled if an empty string.
  11374. * Note that this parameter will be set by the initialisation routine. To
  11375. * set a default use {@link DataTable.defaults}.
  11376. * @type string
  11377. */
  11378. "sX": null,
  11379. /**
  11380. * Width to expand the table to when using x-scrolling. Typically you
  11381. * should not need to use this.
  11382. * Note that this parameter will be set by the initialisation routine. To
  11383. * set a default use {@link DataTable.defaults}.
  11384. * @type string
  11385. * @deprecated
  11386. */
  11387. "sXInner": null,
  11388. /**
  11389. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  11390. * if an empty string.
  11391. * Note that this parameter will be set by the initialisation routine. To
  11392. * set a default use {@link DataTable.defaults}.
  11393. * @type string
  11394. */
  11395. "sY": null
  11396. },
  11397. /**
  11398. * Language information for the table.
  11399. * @namespace
  11400. * @extends DataTable.defaults.oLanguage
  11401. */
  11402. "oLanguage": {
  11403. /**
  11404. * Information callback function. See
  11405. * {@link DataTable.defaults.fnInfoCallback}
  11406. * @type function
  11407. * @default null
  11408. */
  11409. "fnInfoCallback": null
  11410. },
  11411. /**
  11412. * Browser support parameters
  11413. * @namespace
  11414. */
  11415. "oBrowser": {
  11416. /**
  11417. * Indicate if the browser incorrectly calculates width:100% inside a
  11418. * scrolling element (IE6/7)
  11419. * @type boolean
  11420. * @default false
  11421. */
  11422. "bScrollOversize": false,
  11423. /**
  11424. * Determine if the vertical scrollbar is on the right or left of the
  11425. * scrolling container - needed for rtl language layout, although not
  11426. * all browsers move the scrollbar (Safari).
  11427. * @type boolean
  11428. * @default false
  11429. */
  11430. "bScrollbarLeft": false,
  11431. /**
  11432. * Flag for if `getBoundingClientRect` is fully supported or not
  11433. * @type boolean
  11434. * @default false
  11435. */
  11436. "bBounding": false,
  11437. /**
  11438. * Browser scrollbar width
  11439. * @type integer
  11440. * @default 0
  11441. */
  11442. "barWidth": 0
  11443. },
  11444. "ajax": null,
  11445. /**
  11446. * Array referencing the nodes which are used for the features. The
  11447. * parameters of this object match what is allowed by sDom - i.e.
  11448. * <ul>
  11449. * <li>'l' - Length changing</li>
  11450. * <li>'f' - Filtering input</li>
  11451. * <li>'t' - The table!</li>
  11452. * <li>'i' - Information</li>
  11453. * <li>'p' - Pagination</li>
  11454. * <li>'r' - pRocessing</li>
  11455. * </ul>
  11456. * @type array
  11457. * @default []
  11458. */
  11459. "aanFeatures": [],
  11460. /**
  11461. * Store data information - see {@link DataTable.models.oRow} for detailed
  11462. * information.
  11463. * @type array
  11464. * @default []
  11465. */
  11466. "aoData": [],
  11467. /**
  11468. * Array of indexes which are in the current display (after filtering etc)
  11469. * @type array
  11470. * @default []
  11471. */
  11472. "aiDisplay": [],
  11473. /**
  11474. * Array of indexes for display - no filtering
  11475. * @type array
  11476. * @default []
  11477. */
  11478. "aiDisplayMaster": [],
  11479. /**
  11480. * Map of row ids to data indexes
  11481. * @type object
  11482. * @default {}
  11483. */
  11484. "aIds": {},
  11485. /**
  11486. * Store information about each column that is in use
  11487. * @type array
  11488. * @default []
  11489. */
  11490. "aoColumns": [],
  11491. /**
  11492. * Store information about the table's header
  11493. * @type array
  11494. * @default []
  11495. */
  11496. "aoHeader": [],
  11497. /**
  11498. * Store information about the table's footer
  11499. * @type array
  11500. * @default []
  11501. */
  11502. "aoFooter": [],
  11503. /**
  11504. * Store the applied global search information in case we want to force a
  11505. * research or compare the old search to a new one.
  11506. * Note that this parameter will be set by the initialisation routine. To
  11507. * set a default use {@link DataTable.defaults}.
  11508. * @namespace
  11509. * @extends DataTable.models.oSearch
  11510. */
  11511. "oPreviousSearch": {},
  11512. /**
  11513. * Store the applied search for each column - see
  11514. * {@link DataTable.models.oSearch} for the format that is used for the
  11515. * filtering information for each column.
  11516. * @type array
  11517. * @default []
  11518. */
  11519. "aoPreSearchCols": [],
  11520. /**
  11521. * Sorting that is applied to the table. Note that the inner arrays are
  11522. * used in the following manner:
  11523. * <ul>
  11524. * <li>Index 0 - column number</li>
  11525. * <li>Index 1 - current sorting direction</li>
  11526. * </ul>
  11527. * Note that this parameter will be set by the initialisation routine. To
  11528. * set a default use {@link DataTable.defaults}.
  11529. * @type array
  11530. * @todo These inner arrays should really be objects
  11531. */
  11532. "aaSorting": null,
  11533. /**
  11534. * Sorting that is always applied to the table (i.e. prefixed in front of
  11535. * aaSorting).
  11536. * Note that this parameter will be set by the initialisation routine. To
  11537. * set a default use {@link DataTable.defaults}.
  11538. * @type array
  11539. * @default []
  11540. */
  11541. "aaSortingFixed": [],
  11542. /**
  11543. * Classes to use for the striping of a table.
  11544. * Note that this parameter will be set by the initialisation routine. To
  11545. * set a default use {@link DataTable.defaults}.
  11546. * @type array
  11547. * @default []
  11548. */
  11549. "asStripeClasses": null,
  11550. /**
  11551. * If restoring a table - we should restore its striping classes as well
  11552. * @type array
  11553. * @default []
  11554. */
  11555. "asDestroyStripes": [],
  11556. /**
  11557. * If restoring a table - we should restore its width
  11558. * @type int
  11559. * @default 0
  11560. */
  11561. "sDestroyWidth": 0,
  11562. /**
  11563. * Callback functions array for every time a row is inserted (i.e. on a draw).
  11564. * @type array
  11565. * @default []
  11566. */
  11567. "aoRowCallback": [],
  11568. /**
  11569. * Callback functions for the header on each draw.
  11570. * @type array
  11571. * @default []
  11572. */
  11573. "aoHeaderCallback": [],
  11574. /**
  11575. * Callback function for the footer on each draw.
  11576. * @type array
  11577. * @default []
  11578. */
  11579. "aoFooterCallback": [],
  11580. /**
  11581. * Array of callback functions for draw callback functions
  11582. * @type array
  11583. * @default []
  11584. */
  11585. "aoDrawCallback": [],
  11586. /**
  11587. * Array of callback functions for row created function
  11588. * @type array
  11589. * @default []
  11590. */
  11591. "aoRowCreatedCallback": [],
  11592. /**
  11593. * Callback functions for just before the table is redrawn. A return of
  11594. * false will be used to cancel the draw.
  11595. * @type array
  11596. * @default []
  11597. */
  11598. "aoPreDrawCallback": [],
  11599. /**
  11600. * Callback functions for when the table has been initialised.
  11601. * @type array
  11602. * @default []
  11603. */
  11604. "aoInitComplete": [],
  11605. /**
  11606. * Callbacks for modifying the settings to be stored for state saving, prior to
  11607. * saving state.
  11608. * @type array
  11609. * @default []
  11610. */
  11611. "aoStateSaveParams": [],
  11612. /**
  11613. * Callbacks for modifying the settings that have been stored for state saving
  11614. * prior to using the stored values to restore the state.
  11615. * @type array
  11616. * @default []
  11617. */
  11618. "aoStateLoadParams": [],
  11619. /**
  11620. * Callbacks for operating on the settings object once the saved state has been
  11621. * loaded
  11622. * @type array
  11623. * @default []
  11624. */
  11625. "aoStateLoaded": [],
  11626. /**
  11627. * Cache the table ID for quick access
  11628. * @type string
  11629. * @default <i>Empty string</i>
  11630. */
  11631. "sTableId": "",
  11632. /**
  11633. * The TABLE node for the main table
  11634. * @type node
  11635. * @default null
  11636. */
  11637. "nTable": null,
  11638. /**
  11639. * Permanent ref to the thead element
  11640. * @type node
  11641. * @default null
  11642. */
  11643. "nTHead": null,
  11644. /**
  11645. * Permanent ref to the tfoot element - if it exists
  11646. * @type node
  11647. * @default null
  11648. */
  11649. "nTFoot": null,
  11650. /**
  11651. * Permanent ref to the tbody element
  11652. * @type node
  11653. * @default null
  11654. */
  11655. "nTBody": null,
  11656. /**
  11657. * Cache the wrapper node (contains all DataTables controlled elements)
  11658. * @type node
  11659. * @default null
  11660. */
  11661. "nTableWrapper": null,
  11662. /**
  11663. * Indicate if when using server-side processing the loading of data
  11664. * should be deferred until the second draw.
  11665. * Note that this parameter will be set by the initialisation routine. To
  11666. * set a default use {@link DataTable.defaults}.
  11667. * @type boolean
  11668. * @default false
  11669. */
  11670. "bDeferLoading": false,
  11671. /**
  11672. * Indicate if all required information has been read in
  11673. * @type boolean
  11674. * @default false
  11675. */
  11676. "bInitialised": false,
  11677. /**
  11678. * Information about open rows. Each object in the array has the parameters
  11679. * 'nTr' and 'nParent'
  11680. * @type array
  11681. * @default []
  11682. */
  11683. "aoOpenRows": [],
  11684. /**
  11685. * Dictate the positioning of DataTables' control elements - see
  11686. * {@link DataTable.model.oInit.sDom}.
  11687. * Note that this parameter will be set by the initialisation routine. To
  11688. * set a default use {@link DataTable.defaults}.
  11689. * @type string
  11690. * @default null
  11691. */
  11692. "sDom": null,
  11693. /**
  11694. * Search delay (in mS)
  11695. * @type integer
  11696. * @default null
  11697. */
  11698. "searchDelay": null,
  11699. /**
  11700. * Which type of pagination should be used.
  11701. * Note that this parameter will be set by the initialisation routine. To
  11702. * set a default use {@link DataTable.defaults}.
  11703. * @type string
  11704. * @default two_button
  11705. */
  11706. "sPaginationType": "two_button",
  11707. /**
  11708. * The state duration (for `stateSave`) in seconds.
  11709. * Note that this parameter will be set by the initialisation routine. To
  11710. * set a default use {@link DataTable.defaults}.
  11711. * @type int
  11712. * @default 0
  11713. */
  11714. "iStateDuration": 0,
  11715. /**
  11716. * Array of callback functions for state saving. Each array element is an
  11717. * object with the following parameters:
  11718. * <ul>
  11719. * <li>function:fn - function to call. Takes two parameters, oSettings
  11720. * and the JSON string to save that has been thus far created. Returns
  11721. * a JSON string to be inserted into a json object
  11722. * (i.e. '"param": [ 0, 1, 2]')</li>
  11723. * <li>string:sName - name of callback</li>
  11724. * </ul>
  11725. * @type array
  11726. * @default []
  11727. */
  11728. "aoStateSave": [],
  11729. /**
  11730. * Array of callback functions for state loading. Each array element is an
  11731. * object with the following parameters:
  11732. * <ul>
  11733. * <li>function:fn - function to call. Takes two parameters, oSettings
  11734. * and the object stored. May return false to cancel state loading</li>
  11735. * <li>string:sName - name of callback</li>
  11736. * </ul>
  11737. * @type array
  11738. * @default []
  11739. */
  11740. "aoStateLoad": [],
  11741. /**
  11742. * State that was saved. Useful for back reference
  11743. * @type object
  11744. * @default null
  11745. */
  11746. "oSavedState": null,
  11747. /**
  11748. * State that was loaded. Useful for back reference
  11749. * @type object
  11750. * @default null
  11751. */
  11752. "oLoadedState": null,
  11753. /**
  11754. * Source url for AJAX data for the table.
  11755. * Note that this parameter will be set by the initialisation routine. To
  11756. * set a default use {@link DataTable.defaults}.
  11757. * @type string
  11758. * @default null
  11759. */
  11760. "sAjaxSource": null,
  11761. /**
  11762. * Property from a given object from which to read the table data from. This
  11763. * can be an empty string (when not server-side processing), in which case
  11764. * it is assumed an an array is given directly.
  11765. * Note that this parameter will be set by the initialisation routine. To
  11766. * set a default use {@link DataTable.defaults}.
  11767. * @type string
  11768. */
  11769. "sAjaxDataProp": null,
  11770. /**
  11771. * Note if draw should be blocked while getting data
  11772. * @type boolean
  11773. * @default true
  11774. */
  11775. "bAjaxDataGet": true,
  11776. /**
  11777. * The last jQuery XHR object that was used for server-side data gathering.
  11778. * This can be used for working with the XHR information in one of the
  11779. * callbacks
  11780. * @type object
  11781. * @default null
  11782. */
  11783. "jqXHR": null,
  11784. /**
  11785. * JSON returned from the server in the last Ajax request
  11786. * @type object
  11787. * @default undefined
  11788. */
  11789. "json": undefined,
  11790. /**
  11791. * Data submitted as part of the last Ajax request
  11792. * @type object
  11793. * @default undefined
  11794. */
  11795. "oAjaxData": undefined,
  11796. /**
  11797. * Function to get the server-side data.
  11798. * Note that this parameter will be set by the initialisation routine. To
  11799. * set a default use {@link DataTable.defaults}.
  11800. * @type function
  11801. */
  11802. "fnServerData": null,
  11803. /**
  11804. * Functions which are called prior to sending an Ajax request so extra
  11805. * parameters can easily be sent to the server
  11806. * @type array
  11807. * @default []
  11808. */
  11809. "aoServerParams": [],
  11810. /**
  11811. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  11812. * required).
  11813. * Note that this parameter will be set by the initialisation routine. To
  11814. * set a default use {@link DataTable.defaults}.
  11815. * @type string
  11816. */
  11817. "sServerMethod": null,
  11818. /**
  11819. * Format numbers for display.
  11820. * Note that this parameter will be set by the initialisation routine. To
  11821. * set a default use {@link DataTable.defaults}.
  11822. * @type function
  11823. */
  11824. "fnFormatNumber": null,
  11825. /**
  11826. * List of options that can be used for the user selectable length menu.
  11827. * Note that this parameter will be set by the initialisation routine. To
  11828. * set a default use {@link DataTable.defaults}.
  11829. * @type array
  11830. * @default []
  11831. */
  11832. "aLengthMenu": null,
  11833. /**
  11834. * Counter for the draws that the table does. Also used as a tracker for
  11835. * server-side processing
  11836. * @type int
  11837. * @default 0
  11838. */
  11839. "iDraw": 0,
  11840. /**
  11841. * Indicate if a redraw is being done - useful for Ajax
  11842. * @type boolean
  11843. * @default false
  11844. */
  11845. "bDrawing": false,
  11846. /**
  11847. * Draw index (iDraw) of the last error when parsing the returned data
  11848. * @type int
  11849. * @default -1
  11850. */
  11851. "iDrawError": -1,
  11852. /**
  11853. * Paging display length
  11854. * @type int
  11855. * @default 10
  11856. */
  11857. "_iDisplayLength": 10,
  11858. /**
  11859. * Paging start point - aiDisplay index
  11860. * @type int
  11861. * @default 0
  11862. */
  11863. "_iDisplayStart": 0,
  11864. /**
  11865. * Server-side processing - number of records in the result set
  11866. * (i.e. before filtering), Use fnRecordsTotal rather than
  11867. * this property to get the value of the number of records, regardless of
  11868. * the server-side processing setting.
  11869. * @type int
  11870. * @default 0
  11871. * @private
  11872. */
  11873. "_iRecordsTotal": 0,
  11874. /**
  11875. * Server-side processing - number of records in the current display set
  11876. * (i.e. after filtering). Use fnRecordsDisplay rather than
  11877. * this property to get the value of the number of records, regardless of
  11878. * the server-side processing setting.
  11879. * @type boolean
  11880. * @default 0
  11881. * @private
  11882. */
  11883. "_iRecordsDisplay": 0,
  11884. /**
  11885. * The classes to use for the table
  11886. * @type object
  11887. * @default {}
  11888. */
  11889. "oClasses": {},
  11890. /**
  11891. * Flag attached to the settings object so you can check in the draw
  11892. * callback if filtering has been done in the draw. Deprecated in favour of
  11893. * events.
  11894. * @type boolean
  11895. * @default false
  11896. * @deprecated
  11897. */
  11898. "bFiltered": false,
  11899. /**
  11900. * Flag attached to the settings object so you can check in the draw
  11901. * callback if sorting has been done in the draw. Deprecated in favour of
  11902. * events.
  11903. * @type boolean
  11904. * @default false
  11905. * @deprecated
  11906. */
  11907. "bSorted": false,
  11908. /**
  11909. * Indicate that if multiple rows are in the header and there is more than
  11910. * one unique cell per column, if the top one (true) or bottom one (false)
  11911. * should be used for sorting / title by DataTables.
  11912. * Note that this parameter will be set by the initialisation routine. To
  11913. * set a default use {@link DataTable.defaults}.
  11914. * @type boolean
  11915. */
  11916. "bSortCellsTop": null,
  11917. /**
  11918. * Initialisation object that is used for the table
  11919. * @type object
  11920. * @default null
  11921. */
  11922. "oInit": null,
  11923. /**
  11924. * Destroy callback functions - for plug-ins to attach themselves to the
  11925. * destroy so they can clean up markup and events.
  11926. * @type array
  11927. * @default []
  11928. */
  11929. "aoDestroyCallback": [],
  11930. /**
  11931. * Get the number of records in the current record set, before filtering
  11932. * @type function
  11933. */
  11934. "fnRecordsTotal": function ()
  11935. {
  11936. return _fnDataSource( this ) == 'ssp' ?
  11937. this._iRecordsTotal * 1 :
  11938. this.aiDisplayMaster.length;
  11939. },
  11940. /**
  11941. * Get the number of records in the current record set, after filtering
  11942. * @type function
  11943. */
  11944. "fnRecordsDisplay": function ()
  11945. {
  11946. return _fnDataSource( this ) == 'ssp' ?
  11947. this._iRecordsDisplay * 1 :
  11948. this.aiDisplay.length;
  11949. },
  11950. /**
  11951. * Get the display end point - aiDisplay index
  11952. * @type function
  11953. */
  11954. "fnDisplayEnd": function ()
  11955. {
  11956. var
  11957. len = this._iDisplayLength,
  11958. start = this._iDisplayStart,
  11959. calc = start + len,
  11960. records = this.aiDisplay.length,
  11961. features = this.oFeatures,
  11962. paginate = features.bPaginate;
  11963. if ( features.bServerSide ) {
  11964. return paginate === false || len === -1 ?
  11965. start + records :
  11966. Math.min( start+len, this._iRecordsDisplay );
  11967. }
  11968. else {
  11969. return ! paginate || calc>records || len===-1 ?
  11970. records :
  11971. calc;
  11972. }
  11973. },
  11974. /**
  11975. * The DataTables object for this table
  11976. * @type object
  11977. * @default null
  11978. */
  11979. "oInstance": null,
  11980. /**
  11981. * Unique identifier for each instance of the DataTables object. If there
  11982. * is an ID on the table node, then it takes that value, otherwise an
  11983. * incrementing internal counter is used.
  11984. * @type string
  11985. * @default null
  11986. */
  11987. "sInstance": null,
  11988. /**
  11989. * tabindex attribute value that is added to DataTables control elements, allowing
  11990. * keyboard navigation of the table and its controls.
  11991. */
  11992. "iTabIndex": 0,
  11993. /**
  11994. * DIV container for the footer scrolling table if scrolling
  11995. */
  11996. "nScrollHead": null,
  11997. /**
  11998. * DIV container for the footer scrolling table if scrolling
  11999. */
  12000. "nScrollFoot": null,
  12001. /**
  12002. * Last applied sort
  12003. * @type array
  12004. * @default []
  12005. */
  12006. "aLastSort": [],
  12007. /**
  12008. * Stored plug-in instances
  12009. * @type object
  12010. * @default {}
  12011. */
  12012. "oPlugins": {},
  12013. /**
  12014. * Function used to get a row's id from the row's data
  12015. * @type function
  12016. * @default null
  12017. */
  12018. "rowIdFn": null,
  12019. /**
  12020. * Data location where to store a row's id
  12021. * @type string
  12022. * @default null
  12023. */
  12024. "rowId": null
  12025. };
  12026. /**
  12027. * Extension object for DataTables that is used to provide all extension
  12028. * options.
  12029. *
  12030. * Note that the `DataTable.ext` object is available through
  12031. * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
  12032. * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
  12033. * @namespace
  12034. * @extends DataTable.models.ext
  12035. */
  12036. /**
  12037. * DataTables extensions
  12038. *
  12039. * This namespace acts as a collection area for plug-ins that can be used to
  12040. * extend DataTables capabilities. Indeed many of the build in methods
  12041. * use this method to provide their own capabilities (sorting methods for
  12042. * example).
  12043. *
  12044. * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
  12045. * reasons
  12046. *
  12047. * @namespace
  12048. */
  12049. DataTable.ext = _ext = {
  12050. /**
  12051. * Buttons. For use with the Buttons extension for DataTables. This is
  12052. * defined here so other extensions can define buttons regardless of load
  12053. * order. It is _not_ used by DataTables core.
  12054. *
  12055. * @type object
  12056. * @default {}
  12057. */
  12058. buttons: {},
  12059. /**
  12060. * Element class names
  12061. *
  12062. * @type object
  12063. * @default {}
  12064. */
  12065. classes: {},
  12066. /**
  12067. * DataTables build type (expanded by the download builder)
  12068. *
  12069. * @type string
  12070. */
  12071. builder: "-source-",
  12072. /**
  12073. * Error reporting.
  12074. *
  12075. * How should DataTables report an error. Can take the value 'alert',
  12076. * 'throw', 'none' or a function.
  12077. *
  12078. * @type string|function
  12079. * @default alert
  12080. */
  12081. errMode: "alert",
  12082. /**
  12083. * Feature plug-ins.
  12084. *
  12085. * This is an array of objects which describe the feature plug-ins that are
  12086. * available to DataTables. These feature plug-ins are then available for
  12087. * use through the `dom` initialisation option.
  12088. *
  12089. * Each feature plug-in is described by an object which must have the
  12090. * following properties:
  12091. *
  12092. * * `fnInit` - function that is used to initialise the plug-in,
  12093. * * `cFeature` - a character so the feature can be enabled by the `dom`
  12094. * instillation option. This is case sensitive.
  12095. *
  12096. * The `fnInit` function has the following input parameters:
  12097. *
  12098. * 1. `{object}` DataTables settings object: see
  12099. * {@link DataTable.models.oSettings}
  12100. *
  12101. * And the following return is expected:
  12102. *
  12103. * * {node|null} The element which contains your feature. Note that the
  12104. * return may also be void if your plug-in does not require to inject any
  12105. * DOM elements into DataTables control (`dom`) - for example this might
  12106. * be useful when developing a plug-in which allows table control via
  12107. * keyboard entry
  12108. *
  12109. * @type array
  12110. *
  12111. * @example
  12112. * $.fn.dataTable.ext.features.push( {
  12113. * "fnInit": function( oSettings ) {
  12114. * return new TableTools( { "oDTSettings": oSettings } );
  12115. * },
  12116. * "cFeature": "T"
  12117. * } );
  12118. */
  12119. feature: [],
  12120. /**
  12121. * Row searching.
  12122. *
  12123. * This method of searching is complimentary to the default type based
  12124. * searching, and a lot more comprehensive as it allows you complete control
  12125. * over the searching logic. Each element in this array is a function
  12126. * (parameters described below) that is called for every row in the table,
  12127. * and your logic decides if it should be included in the searching data set
  12128. * or not.
  12129. *
  12130. * Searching functions have the following input parameters:
  12131. *
  12132. * 1. `{object}` DataTables settings object: see
  12133. * {@link DataTable.models.oSettings}
  12134. * 2. `{array|object}` Data for the row to be processed (same as the
  12135. * original format that was passed in as the data source, or an array
  12136. * from a DOM data source
  12137. * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
  12138. * can be useful to retrieve the `TR` element if you need DOM interaction.
  12139. *
  12140. * And the following return is expected:
  12141. *
  12142. * * {boolean} Include the row in the searched result set (true) or not
  12143. * (false)
  12144. *
  12145. * Note that as with the main search ability in DataTables, technically this
  12146. * is "filtering", since it is subtractive. However, for consistency in
  12147. * naming we call it searching here.
  12148. *
  12149. * @type array
  12150. * @default []
  12151. *
  12152. * @example
  12153. * // The following example shows custom search being applied to the
  12154. * // fourth column (i.e. the data[3] index) based on two input values
  12155. * // from the end-user, matching the data in a certain range.
  12156. * $.fn.dataTable.ext.search.push(
  12157. * function( settings, data, dataIndex ) {
  12158. * var min = document.getElementById('min').value * 1;
  12159. * var max = document.getElementById('max').value * 1;
  12160. * var version = data[3] == "-" ? 0 : data[3]*1;
  12161. *
  12162. * if ( min == "" && max == "" ) {
  12163. * return true;
  12164. * }
  12165. * else if ( min == "" && version < max ) {
  12166. * return true;
  12167. * }
  12168. * else if ( min < version && "" == max ) {
  12169. * return true;
  12170. * }
  12171. * else if ( min < version && version < max ) {
  12172. * return true;
  12173. * }
  12174. * return false;
  12175. * }
  12176. * );
  12177. */
  12178. search: [],
  12179. /**
  12180. * Selector extensions
  12181. *
  12182. * The `selector` option can be used to extend the options available for the
  12183. * selector modifier options (`selector-modifier` object data type) that
  12184. * each of the three built in selector types offer (row, column and cell +
  12185. * their plural counterparts). For example the Select extension uses this
  12186. * mechanism to provide an option to select only rows, columns and cells
  12187. * that have been marked as selected by the end user (`{selected: true}`),
  12188. * which can be used in conjunction with the existing built in selector
  12189. * options.
  12190. *
  12191. * Each property is an array to which functions can be pushed. The functions
  12192. * take three attributes:
  12193. *
  12194. * * Settings object for the host table
  12195. * * Options object (`selector-modifier` object type)
  12196. * * Array of selected item indexes
  12197. *
  12198. * The return is an array of the resulting item indexes after the custom
  12199. * selector has been applied.
  12200. *
  12201. * @type object
  12202. */
  12203. selector: {
  12204. cell: [],
  12205. column: [],
  12206. row: []
  12207. },
  12208. /**
  12209. * Internal functions, exposed for used in plug-ins.
  12210. *
  12211. * Please note that you should not need to use the internal methods for
  12212. * anything other than a plug-in (and even then, try to avoid if possible).
  12213. * The internal function may change between releases.
  12214. *
  12215. * @type object
  12216. * @default {}
  12217. */
  12218. internal: {},
  12219. /**
  12220. * Legacy configuration options. Enable and disable legacy options that
  12221. * are available in DataTables.
  12222. *
  12223. * @type object
  12224. */
  12225. legacy: {
  12226. /**
  12227. * Enable / disable DataTables 1.9 compatible server-side processing
  12228. * requests
  12229. *
  12230. * @type boolean
  12231. * @default null
  12232. */
  12233. ajax: null
  12234. },
  12235. /**
  12236. * Pagination plug-in methods.
  12237. *
  12238. * Each entry in this object is a function and defines which buttons should
  12239. * be shown by the pagination rendering method that is used for the table:
  12240. * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
  12241. * buttons are displayed in the document, while the functions here tell it
  12242. * what buttons to display. This is done by returning an array of button
  12243. * descriptions (what each button will do).
  12244. *
  12245. * Pagination types (the four built in options and any additional plug-in
  12246. * options defined here) can be used through the `paginationType`
  12247. * initialisation parameter.
  12248. *
  12249. * The functions defined take two parameters:
  12250. *
  12251. * 1. `{int} page` The current page index
  12252. * 2. `{int} pages` The number of pages in the table
  12253. *
  12254. * Each function is expected to return an array where each element of the
  12255. * array can be one of:
  12256. *
  12257. * * `first` - Jump to first page when activated
  12258. * * `last` - Jump to last page when activated
  12259. * * `previous` - Show previous page when activated
  12260. * * `next` - Show next page when activated
  12261. * * `{int}` - Show page of the index given
  12262. * * `{array}` - A nested array containing the above elements to add a
  12263. * containing 'DIV' element (might be useful for styling).
  12264. *
  12265. * Note that DataTables v1.9- used this object slightly differently whereby
  12266. * an object with two functions would be defined for each plug-in. That
  12267. * ability is still supported by DataTables 1.10+ to provide backwards
  12268. * compatibility, but this option of use is now decremented and no longer
  12269. * documented in DataTables 1.10+.
  12270. *
  12271. * @type object
  12272. * @default {}
  12273. *
  12274. * @example
  12275. * // Show previous, next and current page buttons only
  12276. * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
  12277. * return [ 'previous', page, 'next' ];
  12278. * };
  12279. */
  12280. pager: {},
  12281. renderer: {
  12282. pageButton: {},
  12283. header: {}
  12284. },
  12285. /**
  12286. * Ordering plug-ins - custom data source
  12287. *
  12288. * The extension options for ordering of data available here is complimentary
  12289. * to the default type based ordering that DataTables typically uses. It
  12290. * allows much greater control over the the data that is being used to
  12291. * order a column, but is necessarily therefore more complex.
  12292. *
  12293. * This type of ordering is useful if you want to do ordering based on data
  12294. * live from the DOM (for example the contents of an 'input' element) rather
  12295. * than just the static string that DataTables knows of.
  12296. *
  12297. * The way these plug-ins work is that you create an array of the values you
  12298. * wish to be ordering for the column in question and then return that
  12299. * array. The data in the array much be in the index order of the rows in
  12300. * the table (not the currently ordering order!). Which order data gathering
  12301. * function is run here depends on the `dt-init columns.orderDataType`
  12302. * parameter that is used for the column (if any).
  12303. *
  12304. * The functions defined take two parameters:
  12305. *
  12306. * 1. `{object}` DataTables settings object: see
  12307. * {@link DataTable.models.oSettings}
  12308. * 2. `{int}` Target column index
  12309. *
  12310. * Each function is expected to return an array:
  12311. *
  12312. * * `{array}` Data for the column to be ordering upon
  12313. *
  12314. * @type array
  12315. *
  12316. * @example
  12317. * // Ordering using `input` node values
  12318. * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
  12319. * {
  12320. * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
  12321. * return $('input', td).val();
  12322. * } );
  12323. * }
  12324. */
  12325. order: {},
  12326. /**
  12327. * Type based plug-ins.
  12328. *
  12329. * Each column in DataTables has a type assigned to it, either by automatic
  12330. * detection or by direct assignment using the `type` option for the column.
  12331. * The type of a column will effect how it is ordering and search (plug-ins
  12332. * can also make use of the column type if required).
  12333. *
  12334. * @namespace
  12335. */
  12336. type: {
  12337. /**
  12338. * Type detection functions.
  12339. *
  12340. * The functions defined in this object are used to automatically detect
  12341. * a column's type, making initialisation of DataTables super easy, even
  12342. * when complex data is in the table.
  12343. *
  12344. * The functions defined take two parameters:
  12345. *
  12346. * 1. `{*}` Data from the column cell to be analysed
  12347. * 2. `{settings}` DataTables settings object. This can be used to
  12348. * perform context specific type detection - for example detection
  12349. * based on language settings such as using a comma for a decimal
  12350. * place. Generally speaking the options from the settings will not
  12351. * be required
  12352. *
  12353. * Each function is expected to return:
  12354. *
  12355. * * `{string|null}` Data type detected, or null if unknown (and thus
  12356. * pass it on to the other type detection functions.
  12357. *
  12358. * @type array
  12359. *
  12360. * @example
  12361. * // Currency type detection plug-in:
  12362. * $.fn.dataTable.ext.type.detect.push(
  12363. * function ( data, settings ) {
  12364. * // Check the numeric part
  12365. * if ( ! data.substring(1).match(/[0-9]/) ) {
  12366. * return null;
  12367. * }
  12368. *
  12369. * // Check prefixed by currency
  12370. * if ( data.charAt(0) == '$' || data.charAt(0) == '&pound;' ) {
  12371. * return 'currency';
  12372. * }
  12373. * return null;
  12374. * }
  12375. * );
  12376. */
  12377. detect: [],
  12378. /**
  12379. * Type based search formatting.
  12380. *
  12381. * The type based searching functions can be used to pre-format the
  12382. * data to be search on. For example, it can be used to strip HTML
  12383. * tags or to de-format telephone numbers for numeric only searching.
  12384. *
  12385. * Note that is a search is not defined for a column of a given type,
  12386. * no search formatting will be performed.
  12387. *
  12388. * Pre-processing of searching data plug-ins - When you assign the sType
  12389. * for a column (or have it automatically detected for you by DataTables
  12390. * or a type detection plug-in), you will typically be using this for
  12391. * custom sorting, but it can also be used to provide custom searching
  12392. * by allowing you to pre-processing the data and returning the data in
  12393. * the format that should be searched upon. This is done by adding
  12394. * functions this object with a parameter name which matches the sType
  12395. * for that target column. This is the corollary of <i>afnSortData</i>
  12396. * for searching data.
  12397. *
  12398. * The functions defined take a single parameter:
  12399. *
  12400. * 1. `{*}` Data from the column cell to be prepared for searching
  12401. *
  12402. * Each function is expected to return:
  12403. *
  12404. * * `{string|null}` Formatted string that will be used for the searching.
  12405. *
  12406. * @type object
  12407. * @default {}
  12408. *
  12409. * @example
  12410. * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
  12411. * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
  12412. * }
  12413. */
  12414. search: {},
  12415. /**
  12416. * Type based ordering.
  12417. *
  12418. * The column type tells DataTables what ordering to apply to the table
  12419. * when a column is sorted upon. The order for each type that is defined,
  12420. * is defined by the functions available in this object.
  12421. *
  12422. * Each ordering option can be described by three properties added to
  12423. * this object:
  12424. *
  12425. * * `{type}-pre` - Pre-formatting function
  12426. * * `{type}-asc` - Ascending order function
  12427. * * `{type}-desc` - Descending order function
  12428. *
  12429. * All three can be used together, only `{type}-pre` or only
  12430. * `{type}-asc` and `{type}-desc` together. It is generally recommended
  12431. * that only `{type}-pre` is used, as this provides the optimal
  12432. * implementation in terms of speed, although the others are provided
  12433. * for compatibility with existing Javascript sort functions.
  12434. *
  12435. * `{type}-pre`: Functions defined take a single parameter:
  12436. *
  12437. * 1. `{*}` Data from the column cell to be prepared for ordering
  12438. *
  12439. * And return:
  12440. *
  12441. * * `{*}` Data to be sorted upon
  12442. *
  12443. * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
  12444. * functions, taking two parameters:
  12445. *
  12446. * 1. `{*}` Data to compare to the second parameter
  12447. * 2. `{*}` Data to compare to the first parameter
  12448. *
  12449. * And returning:
  12450. *
  12451. * * `{*}` Ordering match: <0 if first parameter should be sorted lower
  12452. * than the second parameter, ===0 if the two parameters are equal and
  12453. * >0 if the first parameter should be sorted height than the second
  12454. * parameter.
  12455. *
  12456. * @type object
  12457. * @default {}
  12458. *
  12459. * @example
  12460. * // Numeric ordering of formatted numbers with a pre-formatter
  12461. * $.extend( $.fn.dataTable.ext.type.order, {
  12462. * "string-pre": function(x) {
  12463. * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  12464. * return parseFloat( a );
  12465. * }
  12466. * } );
  12467. *
  12468. * @example
  12469. * // Case-sensitive string ordering, with no pre-formatting method
  12470. * $.extend( $.fn.dataTable.ext.order, {
  12471. * "string-case-asc": function(x,y) {
  12472. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12473. * },
  12474. * "string-case-desc": function(x,y) {
  12475. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12476. * }
  12477. * } );
  12478. */
  12479. order: {}
  12480. },
  12481. /**
  12482. * Unique DataTables instance counter
  12483. *
  12484. * @type int
  12485. * @private
  12486. */
  12487. _unique: 0,
  12488. //
  12489. // Depreciated
  12490. // The following properties are retained for backwards compatiblity only.
  12491. // The should not be used in new projects and will be removed in a future
  12492. // version
  12493. //
  12494. /**
  12495. * Version check function.
  12496. * @type function
  12497. * @depreciated Since 1.10
  12498. */
  12499. fnVersionCheck: DataTable.fnVersionCheck,
  12500. /**
  12501. * Index for what 'this' index API functions should use
  12502. * @type int
  12503. * @deprecated Since v1.10
  12504. */
  12505. iApiIndex: 0,
  12506. /**
  12507. * jQuery UI class container
  12508. * @type object
  12509. * @deprecated Since v1.10
  12510. */
  12511. oJUIClasses: {},
  12512. /**
  12513. * Software version
  12514. * @type string
  12515. * @deprecated Since v1.10
  12516. */
  12517. sVersion: DataTable.version
  12518. };
  12519. //
  12520. // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
  12521. //
  12522. $.extend( _ext, {
  12523. afnFiltering: _ext.search,
  12524. aTypes: _ext.type.detect,
  12525. ofnSearch: _ext.type.search,
  12526. oSort: _ext.type.order,
  12527. afnSortData: _ext.order,
  12528. aoFeatures: _ext.feature,
  12529. oApi: _ext.internal,
  12530. oStdClasses: _ext.classes,
  12531. oPagination: _ext.pager
  12532. } );
  12533. $.extend( DataTable.ext.classes, {
  12534. "sTable": "dataTable",
  12535. "sNoFooter": "no-footer",
  12536. /* Paging buttons */
  12537. "sPageButton": "paginate_button",
  12538. "sPageButtonActive": "current",
  12539. "sPageButtonDisabled": "disabled",
  12540. /* Striping classes */
  12541. "sStripeOdd": "odd",
  12542. "sStripeEven": "even",
  12543. /* Empty row */
  12544. "sRowEmpty": "dataTables_empty",
  12545. /* Features */
  12546. "sWrapper": "dataTables_wrapper",
  12547. "sFilter": "dataTables_filter",
  12548. "sInfo": "dataTables_info",
  12549. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  12550. "sLength": "dataTables_length",
  12551. "sProcessing": "dataTables_processing",
  12552. /* Sorting */
  12553. "sSortAsc": "sorting_asc",
  12554. "sSortDesc": "sorting_desc",
  12555. "sSortable": "sorting", /* Sortable in both directions */
  12556. "sSortableAsc": "sorting_asc_disabled",
  12557. "sSortableDesc": "sorting_desc_disabled",
  12558. "sSortableNone": "sorting_disabled",
  12559. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  12560. /* Filtering */
  12561. "sFilterInput": "",
  12562. /* Page length */
  12563. "sLengthSelect": "",
  12564. /* Scrolling */
  12565. "sScrollWrapper": "dataTables_scroll",
  12566. "sScrollHead": "dataTables_scrollHead",
  12567. "sScrollHeadInner": "dataTables_scrollHeadInner",
  12568. "sScrollBody": "dataTables_scrollBody",
  12569. "sScrollFoot": "dataTables_scrollFoot",
  12570. "sScrollFootInner": "dataTables_scrollFootInner",
  12571. /* Misc */
  12572. "sHeaderTH": "",
  12573. "sFooterTH": "",
  12574. // Deprecated
  12575. "sSortJUIAsc": "",
  12576. "sSortJUIDesc": "",
  12577. "sSortJUI": "",
  12578. "sSortJUIAscAllowed": "",
  12579. "sSortJUIDescAllowed": "",
  12580. "sSortJUIWrapper": "",
  12581. "sSortIcon": "",
  12582. "sJUIHeader": "",
  12583. "sJUIFooter": ""
  12584. } );
  12585. var extPagination = DataTable.ext.pager;
  12586. function _numbers ( page, pages ) {
  12587. var
  12588. numbers = [],
  12589. buttons = extPagination.numbers_length,
  12590. half = Math.floor( buttons / 2 ),
  12591. i = 1;
  12592. if ( pages <= buttons ) {
  12593. numbers = _range( 0, pages );
  12594. }
  12595. else if ( page <= half ) {
  12596. numbers = _range( 0, buttons-2 );
  12597. numbers.push( 'ellipsis' );
  12598. numbers.push( pages-1 );
  12599. }
  12600. else if ( page >= pages - 1 - half ) {
  12601. numbers = _range( pages-(buttons-2), pages );
  12602. numbers.splice( 0, 0, 'ellipsis' ); // no unshift in ie6
  12603. numbers.splice( 0, 0, 0 );
  12604. }
  12605. else {
  12606. numbers = _range( page-half+2, page+half-1 );
  12607. numbers.push( 'ellipsis' );
  12608. numbers.push( pages-1 );
  12609. numbers.splice( 0, 0, 'ellipsis' );
  12610. numbers.splice( 0, 0, 0 );
  12611. }
  12612. numbers.DT_el = 'span';
  12613. return numbers;
  12614. }
  12615. $.extend( extPagination, {
  12616. simple: function ( page, pages ) {
  12617. return [ 'previous', 'next' ];
  12618. },
  12619. full: function ( page, pages ) {
  12620. return [ 'first', 'previous', 'next', 'last' ];
  12621. },
  12622. numbers: function ( page, pages ) {
  12623. return [ _numbers(page, pages) ];
  12624. },
  12625. simple_numbers: function ( page, pages ) {
  12626. return [ 'previous', _numbers(page, pages), 'next' ];
  12627. },
  12628. full_numbers: function ( page, pages ) {
  12629. return [ 'first', 'previous', _numbers(page, pages), 'next', 'last' ];
  12630. },
  12631. first_last_numbers: function (page, pages) {
  12632. return ['first', _numbers(page, pages), 'last'];
  12633. },
  12634. // For testing and plug-ins to use
  12635. _numbers: _numbers,
  12636. // Number of number buttons (including ellipsis) to show. _Must be odd!_
  12637. numbers_length: 7
  12638. } );
  12639. $.extend( true, DataTable.ext.renderer, {
  12640. pageButton: {
  12641. _: function ( settings, host, idx, buttons, page, pages ) {
  12642. var classes = settings.oClasses;
  12643. var lang = settings.oLanguage.oPaginate;
  12644. var aria = settings.oLanguage.oAria.paginate || {};
  12645. var btnDisplay, btnClass, counter=0;
  12646. var attach = function( container, buttons ) {
  12647. var i, ien, node, button;
  12648. var clickHandler = function ( e ) {
  12649. _fnPageChange( settings, e.data.action, true );
  12650. };
  12651. for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
  12652. button = buttons[i];
  12653. if ( $.isArray( button ) ) {
  12654. var inner = $( '<'+(button.DT_el || 'div')+'/>' )
  12655. .appendTo( container );
  12656. attach( inner, button );
  12657. }
  12658. else {
  12659. btnDisplay = null;
  12660. btnClass = '';
  12661. switch ( button ) {
  12662. case 'ellipsis':
  12663. container.append('<span class="ellipsis">&#x2026;</span>');
  12664. break;
  12665. case 'first':
  12666. btnDisplay = lang.sFirst;
  12667. btnClass = button + (page > 0 ?
  12668. '' : ' '+classes.sPageButtonDisabled);
  12669. break;
  12670. case 'previous':
  12671. btnDisplay = lang.sPrevious;
  12672. btnClass = button + (page > 0 ?
  12673. '' : ' '+classes.sPageButtonDisabled);
  12674. break;
  12675. case 'next':
  12676. btnDisplay = lang.sNext;
  12677. btnClass = button + (page < pages-1 ?
  12678. '' : ' '+classes.sPageButtonDisabled);
  12679. break;
  12680. case 'last':
  12681. btnDisplay = lang.sLast;
  12682. btnClass = button + (page < pages-1 ?
  12683. '' : ' '+classes.sPageButtonDisabled);
  12684. break;
  12685. default:
  12686. btnDisplay = button + 1;
  12687. btnClass = page === button ?
  12688. classes.sPageButtonActive : '';
  12689. break;
  12690. }
  12691. if ( btnDisplay !== null ) {
  12692. node = $('<a>', {
  12693. 'class': classes.sPageButton+' '+btnClass,
  12694. 'aria-controls': settings.sTableId,
  12695. 'aria-label': aria[ button ],
  12696. 'data-dt-idx': counter,
  12697. 'tabindex': settings.iTabIndex,
  12698. 'id': idx === 0 && typeof button === 'string' ?
  12699. settings.sTableId +'_'+ button :
  12700. null
  12701. } )
  12702. .html( btnDisplay )
  12703. .appendTo( container );
  12704. _fnBindAction(
  12705. node, {action: button}, clickHandler
  12706. );
  12707. counter++;
  12708. }
  12709. }
  12710. }
  12711. };
  12712. // IE9 throws an 'unknown error' if document.activeElement is used
  12713. // inside an iframe or frame. Try / catch the error. Not good for
  12714. // accessibility, but neither are frames.
  12715. var activeEl;
  12716. try {
  12717. // Because this approach is destroying and recreating the paging
  12718. // elements, focus is lost on the select button which is bad for
  12719. // accessibility. So we want to restore focus once the draw has
  12720. // completed
  12721. activeEl = $(host).find(document.activeElement).data('dt-idx');
  12722. }
  12723. catch (e) {}
  12724. attach( $(host).empty(), buttons );
  12725. if ( activeEl !== undefined ) {
  12726. $(host).find( '[data-dt-idx='+activeEl+']' ).focus();
  12727. }
  12728. }
  12729. }
  12730. } );
  12731. // Built in type detection. See model.ext.aTypes for information about
  12732. // what is required from this methods.
  12733. $.extend( DataTable.ext.type.detect, [
  12734. // Plain numbers - first since V8 detects some plain numbers as dates
  12735. // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
  12736. function ( d, settings )
  12737. {
  12738. var decimal = settings.oLanguage.sDecimal;
  12739. return _isNumber( d, decimal ) ? 'num'+decimal : null;
  12740. },
  12741. // Dates (only those recognised by the browser's Date.parse)
  12742. function ( d, settings )
  12743. {
  12744. // V8 tries _very_ hard to make a string passed into `Date.parse()`
  12745. // valid, so we need to use a regex to restrict date formats. Use a
  12746. // plug-in for anything other than ISO8601 style strings
  12747. if ( d && !(d instanceof Date) && ! _re_date.test(d) ) {
  12748. return null;
  12749. }
  12750. var parsed = Date.parse(d);
  12751. return (parsed !== null && !isNaN(parsed)) || _empty(d) ? 'date' : null;
  12752. },
  12753. // Formatted numbers
  12754. function ( d, settings )
  12755. {
  12756. var decimal = settings.oLanguage.sDecimal;
  12757. return _isNumber( d, decimal, true ) ? 'num-fmt'+decimal : null;
  12758. },
  12759. // HTML numeric
  12760. function ( d, settings )
  12761. {
  12762. var decimal = settings.oLanguage.sDecimal;
  12763. return _htmlNumeric( d, decimal ) ? 'html-num'+decimal : null;
  12764. },
  12765. // HTML numeric, formatted
  12766. function ( d, settings )
  12767. {
  12768. var decimal = settings.oLanguage.sDecimal;
  12769. return _htmlNumeric( d, decimal, true ) ? 'html-num-fmt'+decimal : null;
  12770. },
  12771. // HTML (this is strict checking - there must be html)
  12772. function ( d, settings )
  12773. {
  12774. return _empty( d ) || (typeof d === 'string' && d.indexOf('<') !== -1) ?
  12775. 'html' : null;
  12776. }
  12777. ] );
  12778. // Filter formatting functions. See model.ext.ofnSearch for information about
  12779. // what is required from these methods.
  12780. //
  12781. // Note that additional search methods are added for the html numbers and
  12782. // html formatted numbers by `_addNumericSort()` when we know what the decimal
  12783. // place is
  12784. $.extend( DataTable.ext.type.search, {
  12785. html: function ( data ) {
  12786. return _empty(data) ?
  12787. data :
  12788. typeof data === 'string' ?
  12789. data
  12790. .replace( _re_new_lines, " " )
  12791. .replace( _re_html, "" ) :
  12792. '';
  12793. },
  12794. string: function ( data ) {
  12795. return _empty(data) ?
  12796. data :
  12797. typeof data === 'string' ?
  12798. data.replace( _re_new_lines, " " ) :
  12799. data;
  12800. }
  12801. } );
  12802. var __numericReplace = function ( d, decimalPlace, re1, re2 ) {
  12803. if ( d !== 0 && (!d || d === '-') ) {
  12804. return -Infinity;
  12805. }
  12806. // If a decimal place other than `.` is used, it needs to be given to the
  12807. // function so we can detect it and replace with a `.` which is the only
  12808. // decimal place Javascript recognises - it is not locale aware.
  12809. if ( decimalPlace ) {
  12810. d = _numToDecimal( d, decimalPlace );
  12811. }
  12812. if ( d.replace ) {
  12813. if ( re1 ) {
  12814. d = d.replace( re1, '' );
  12815. }
  12816. if ( re2 ) {
  12817. d = d.replace( re2, '' );
  12818. }
  12819. }
  12820. return d * 1;
  12821. };
  12822. // Add the numeric 'deformatting' functions for sorting and search. This is done
  12823. // in a function to provide an easy ability for the language options to add
  12824. // additional methods if a non-period decimal place is used.
  12825. function _addNumericSort ( decimalPlace ) {
  12826. $.each(
  12827. {
  12828. // Plain numbers
  12829. "num": function ( d ) {
  12830. return __numericReplace( d, decimalPlace );
  12831. },
  12832. // Formatted numbers
  12833. "num-fmt": function ( d ) {
  12834. return __numericReplace( d, decimalPlace, _re_formatted_numeric );
  12835. },
  12836. // HTML numeric
  12837. "html-num": function ( d ) {
  12838. return __numericReplace( d, decimalPlace, _re_html );
  12839. },
  12840. // HTML numeric, formatted
  12841. "html-num-fmt": function ( d ) {
  12842. return __numericReplace( d, decimalPlace, _re_html, _re_formatted_numeric );
  12843. }
  12844. },
  12845. function ( key, fn ) {
  12846. // Add the ordering method
  12847. _ext.type.order[ key+decimalPlace+'-pre' ] = fn;
  12848. // For HTML types add a search formatter that will strip the HTML
  12849. if ( key.match(/^html\-/) ) {
  12850. _ext.type.search[ key+decimalPlace ] = _ext.type.search.html;
  12851. }
  12852. }
  12853. );
  12854. }
  12855. // Default sort methods
  12856. $.extend( _ext.type.order, {
  12857. // Dates
  12858. "date-pre": function ( d ) {
  12859. var ts = Date.parse( d );
  12860. return isNaN(ts) ? -Infinity : ts;
  12861. },
  12862. // html
  12863. "html-pre": function ( a ) {
  12864. return _empty(a) ?
  12865. '' :
  12866. a.replace ?
  12867. a.replace( /<.*?>/g, "" ).toLowerCase() :
  12868. a+'';
  12869. },
  12870. // string
  12871. "string-pre": function ( a ) {
  12872. // This is a little complex, but faster than always calling toString,
  12873. // http://jsperf.com/tostring-v-check
  12874. return _empty(a) ?
  12875. '' :
  12876. typeof a === 'string' ?
  12877. a.toLowerCase() :
  12878. ! a.toString ?
  12879. '' :
  12880. a.toString();
  12881. },
  12882. // string-asc and -desc are retained only for compatibility with the old
  12883. // sort methods
  12884. "string-asc": function ( x, y ) {
  12885. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12886. },
  12887. "string-desc": function ( x, y ) {
  12888. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12889. }
  12890. } );
  12891. // Numeric sorting types - order doesn't matter here
  12892. _addNumericSort( '' );
  12893. $.extend( true, DataTable.ext.renderer, {
  12894. header: {
  12895. _: function ( settings, cell, column, classes ) {
  12896. // No additional mark-up required
  12897. // Attach a sort listener to update on sort - note that using the
  12898. // `DT` namespace will allow the event to be removed automatically
  12899. // on destroy, while the `dt` namespaced event is the one we are
  12900. // listening for
  12901. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  12902. if ( settings !== ctx ) { // need to check this this is the host
  12903. return; // table, not a nested one
  12904. }
  12905. var colIdx = column.idx;
  12906. cell
  12907. .removeClass(
  12908. column.sSortingClass +' '+
  12909. classes.sSortAsc +' '+
  12910. classes.sSortDesc
  12911. )
  12912. .addClass( columns[ colIdx ] == 'asc' ?
  12913. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  12914. classes.sSortDesc :
  12915. column.sSortingClass
  12916. );
  12917. } );
  12918. },
  12919. jqueryui: function ( settings, cell, column, classes ) {
  12920. $('<div/>')
  12921. .addClass( classes.sSortJUIWrapper )
  12922. .append( cell.contents() )
  12923. .append( $('<span/>')
  12924. .addClass( classes.sSortIcon+' '+column.sSortingClassJUI )
  12925. )
  12926. .appendTo( cell );
  12927. // Attach a sort listener to update on sort
  12928. $(settings.nTable).on( 'order.dt.DT', function ( e, ctx, sorting, columns ) {
  12929. if ( settings !== ctx ) {
  12930. return;
  12931. }
  12932. var colIdx = column.idx;
  12933. cell
  12934. .removeClass( classes.sSortAsc +" "+classes.sSortDesc )
  12935. .addClass( columns[ colIdx ] == 'asc' ?
  12936. classes.sSortAsc : columns[ colIdx ] == 'desc' ?
  12937. classes.sSortDesc :
  12938. column.sSortingClass
  12939. );
  12940. cell
  12941. .find( 'span.'+classes.sSortIcon )
  12942. .removeClass(
  12943. classes.sSortJUIAsc +" "+
  12944. classes.sSortJUIDesc +" "+
  12945. classes.sSortJUI +" "+
  12946. classes.sSortJUIAscAllowed +" "+
  12947. classes.sSortJUIDescAllowed
  12948. )
  12949. .addClass( columns[ colIdx ] == 'asc' ?
  12950. classes.sSortJUIAsc : columns[ colIdx ] == 'desc' ?
  12951. classes.sSortJUIDesc :
  12952. column.sSortingClassJUI
  12953. );
  12954. } );
  12955. }
  12956. }
  12957. } );
  12958. /*
  12959. * Public helper functions. These aren't used internally by DataTables, or
  12960. * called by any of the options passed into DataTables, but they can be used
  12961. * externally by developers working with DataTables. They are helper functions
  12962. * to make working with DataTables a little bit easier.
  12963. */
  12964. var __htmlEscapeEntities = function ( d ) {
  12965. return typeof d === 'string' ?
  12966. d.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') :
  12967. d;
  12968. };
  12969. /**
  12970. * Helpers for `columns.render`.
  12971. *
  12972. * The options defined here can be used with the `columns.render` initialisation
  12973. * option to provide a display renderer. The following functions are defined:
  12974. *
  12975. * * `number` - Will format numeric data (defined by `columns.data`) for
  12976. * display, retaining the original unformatted data for sorting and filtering.
  12977. * It takes 5 parameters:
  12978. * * `string` - Thousands grouping separator
  12979. * * `string` - Decimal point indicator
  12980. * * `integer` - Number of decimal points to show
  12981. * * `string` (optional) - Prefix.
  12982. * * `string` (optional) - Postfix (/suffix).
  12983. * * `text` - Escape HTML to help prevent XSS attacks. It has no optional
  12984. * parameters.
  12985. *
  12986. * @example
  12987. * // Column definition using the number renderer
  12988. * {
  12989. * data: "salary",
  12990. * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
  12991. * }
  12992. *
  12993. * @namespace
  12994. */
  12995. DataTable.render = {
  12996. number: function ( thousands, decimal, precision, prefix, postfix ) {
  12997. return {
  12998. display: function ( d ) {
  12999. if ( typeof d !== 'number' && typeof d !== 'string' ) {
  13000. return d;
  13001. }
  13002. var negative = d < 0 ? '-' : '';
  13003. var flo = parseFloat( d );
  13004. // If NaN then there isn't much formatting that we can do - just
  13005. // return immediately, escaping any HTML (this was supposed to
  13006. // be a number after all)
  13007. if ( isNaN( flo ) ) {
  13008. return __htmlEscapeEntities( d );
  13009. }
  13010. flo = flo.toFixed( precision );
  13011. d = Math.abs( flo );
  13012. var intPart = parseInt( d, 10 );
  13013. var floatPart = precision ?
  13014. decimal+(d - intPart).toFixed( precision ).substring( 2 ):
  13015. '';
  13016. return negative + (prefix||'') +
  13017. intPart.toString().replace(
  13018. /\B(?=(\d{3})+(?!\d))/g, thousands
  13019. ) +
  13020. floatPart +
  13021. (postfix||'');
  13022. }
  13023. };
  13024. },
  13025. text: function () {
  13026. return {
  13027. display: __htmlEscapeEntities
  13028. };
  13029. }
  13030. };
  13031. /*
  13032. * This is really a good bit rubbish this method of exposing the internal methods
  13033. * publicly... - To be fixed in 2.0 using methods on the prototype
  13034. */
  13035. /**
  13036. * Create a wrapper function for exporting an internal functions to an external API.
  13037. * @param {string} fn API function name
  13038. * @returns {function} wrapped function
  13039. * @memberof DataTable#internal
  13040. */
  13041. function _fnExternApiFunc (fn)
  13042. {
  13043. return function() {
  13044. var args = [_fnSettingsFromNode( this[DataTable.ext.iApiIndex] )].concat(
  13045. Array.prototype.slice.call(arguments)
  13046. );
  13047. return DataTable.ext.internal[fn].apply( this, args );
  13048. };
  13049. }
  13050. /**
  13051. * Reference to internal functions for use by plug-in developers. Note that
  13052. * these methods are references to internal functions and are considered to be
  13053. * private. If you use these methods, be aware that they are liable to change
  13054. * between versions.
  13055. * @namespace
  13056. */
  13057. $.extend( DataTable.ext.internal, {
  13058. _fnExternApiFunc: _fnExternApiFunc,
  13059. _fnBuildAjax: _fnBuildAjax,
  13060. _fnAjaxUpdate: _fnAjaxUpdate,
  13061. _fnAjaxParameters: _fnAjaxParameters,
  13062. _fnAjaxUpdateDraw: _fnAjaxUpdateDraw,
  13063. _fnAjaxDataSrc: _fnAjaxDataSrc,
  13064. _fnAddColumn: _fnAddColumn,
  13065. _fnColumnOptions: _fnColumnOptions,
  13066. _fnAdjustColumnSizing: _fnAdjustColumnSizing,
  13067. _fnVisibleToColumnIndex: _fnVisibleToColumnIndex,
  13068. _fnColumnIndexToVisible: _fnColumnIndexToVisible,
  13069. _fnVisbleColumns: _fnVisbleColumns,
  13070. _fnGetColumns: _fnGetColumns,
  13071. _fnColumnTypes: _fnColumnTypes,
  13072. _fnApplyColumnDefs: _fnApplyColumnDefs,
  13073. _fnHungarianMap: _fnHungarianMap,
  13074. _fnCamelToHungarian: _fnCamelToHungarian,
  13075. _fnLanguageCompat: _fnLanguageCompat,
  13076. _fnBrowserDetect: _fnBrowserDetect,
  13077. _fnAddData: _fnAddData,
  13078. _fnAddTr: _fnAddTr,
  13079. _fnNodeToDataIndex: _fnNodeToDataIndex,
  13080. _fnNodeToColumnIndex: _fnNodeToColumnIndex,
  13081. _fnGetCellData: _fnGetCellData,
  13082. _fnSetCellData: _fnSetCellData,
  13083. _fnSplitObjNotation: _fnSplitObjNotation,
  13084. _fnGetObjectDataFn: _fnGetObjectDataFn,
  13085. _fnSetObjectDataFn: _fnSetObjectDataFn,
  13086. _fnGetDataMaster: _fnGetDataMaster,
  13087. _fnClearTable: _fnClearTable,
  13088. _fnDeleteIndex: _fnDeleteIndex,
  13089. _fnInvalidate: _fnInvalidate,
  13090. _fnGetRowElements: _fnGetRowElements,
  13091. _fnCreateTr: _fnCreateTr,
  13092. _fnBuildHead: _fnBuildHead,
  13093. _fnDrawHead: _fnDrawHead,
  13094. _fnDraw: _fnDraw,
  13095. _fnReDraw: _fnReDraw,
  13096. _fnAddOptionsHtml: _fnAddOptionsHtml,
  13097. _fnDetectHeader: _fnDetectHeader,
  13098. _fnGetUniqueThs: _fnGetUniqueThs,
  13099. _fnFeatureHtmlFilter: _fnFeatureHtmlFilter,
  13100. _fnFilterComplete: _fnFilterComplete,
  13101. _fnFilterCustom: _fnFilterCustom,
  13102. _fnFilterColumn: _fnFilterColumn,
  13103. _fnFilter: _fnFilter,
  13104. _fnFilterCreateSearch: _fnFilterCreateSearch,
  13105. _fnEscapeRegex: _fnEscapeRegex,
  13106. _fnFilterData: _fnFilterData,
  13107. _fnFeatureHtmlInfo: _fnFeatureHtmlInfo,
  13108. _fnUpdateInfo: _fnUpdateInfo,
  13109. _fnInfoMacros: _fnInfoMacros,
  13110. _fnInitialise: _fnInitialise,
  13111. _fnInitComplete: _fnInitComplete,
  13112. _fnLengthChange: _fnLengthChange,
  13113. _fnFeatureHtmlLength: _fnFeatureHtmlLength,
  13114. _fnFeatureHtmlPaginate: _fnFeatureHtmlPaginate,
  13115. _fnPageChange: _fnPageChange,
  13116. _fnFeatureHtmlProcessing: _fnFeatureHtmlProcessing,
  13117. _fnProcessingDisplay: _fnProcessingDisplay,
  13118. _fnFeatureHtmlTable: _fnFeatureHtmlTable,
  13119. _fnScrollDraw: _fnScrollDraw,
  13120. _fnApplyToChildren: _fnApplyToChildren,
  13121. _fnCalculateColumnWidths: _fnCalculateColumnWidths,
  13122. _fnThrottle: _fnThrottle,
  13123. _fnConvertToWidth: _fnConvertToWidth,
  13124. _fnGetWidestNode: _fnGetWidestNode,
  13125. _fnGetMaxLenString: _fnGetMaxLenString,
  13126. _fnStringToCss: _fnStringToCss,
  13127. _fnSortFlatten: _fnSortFlatten,
  13128. _fnSort: _fnSort,
  13129. _fnSortAria: _fnSortAria,
  13130. _fnSortListener: _fnSortListener,
  13131. _fnSortAttachListener: _fnSortAttachListener,
  13132. _fnSortingClasses: _fnSortingClasses,
  13133. _fnSortData: _fnSortData,
  13134. _fnSaveState: _fnSaveState,
  13135. _fnLoadState: _fnLoadState,
  13136. _fnSettingsFromNode: _fnSettingsFromNode,
  13137. _fnLog: _fnLog,
  13138. _fnMap: _fnMap,
  13139. _fnBindAction: _fnBindAction,
  13140. _fnCallbackReg: _fnCallbackReg,
  13141. _fnCallbackFire: _fnCallbackFire,
  13142. _fnLengthOverflow: _fnLengthOverflow,
  13143. _fnRenderer: _fnRenderer,
  13144. _fnDataSource: _fnDataSource,
  13145. _fnRowAttributes: _fnRowAttributes,
  13146. _fnExtend: _fnExtend,
  13147. _fnCalculateEnd: function () {} // Used by a lot of plug-ins, but redundant
  13148. // in 1.10, so this dead-end function is
  13149. // added to prevent errors
  13150. } );
  13151. // jQuery access
  13152. $.fn.dataTable = DataTable;
  13153. // Provide access to the host jQuery object (circular reference)
  13154. DataTable.$ = $;
  13155. // Legacy aliases
  13156. $.fn.dataTableSettings = DataTable.settings;
  13157. $.fn.dataTableExt = DataTable.ext;
  13158. // With a capital `D` we return a DataTables API instance rather than a
  13159. // jQuery object
  13160. $.fn.DataTable = function ( opts ) {
  13161. return $(this).dataTable( opts ).api();
  13162. };
  13163. // All properties that are available to $.fn.dataTable should also be
  13164. // available on $.fn.DataTable
  13165. $.each( DataTable, function ( prop, val ) {
  13166. $.fn.DataTable[ prop ] = val;
  13167. } );
  13168. // Information about events fired by DataTables - for documentation.
  13169. /**
  13170. * Draw event, fired whenever the table is redrawn on the page, at the same
  13171. * point as fnDrawCallback. This may be useful for binding events or
  13172. * performing calculations when the table is altered at all.
  13173. * @name DataTable#draw.dt
  13174. * @event
  13175. * @param {event} e jQuery event object
  13176. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13177. */
  13178. /**
  13179. * Search event, fired when the searching applied to the table (using the
  13180. * built-in global search, or column filters) is altered.
  13181. * @name DataTable#search.dt
  13182. * @event
  13183. * @param {event} e jQuery event object
  13184. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13185. */
  13186. /**
  13187. * Page change event, fired when the paging of the table is altered.
  13188. * @name DataTable#page.dt
  13189. * @event
  13190. * @param {event} e jQuery event object
  13191. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13192. */
  13193. /**
  13194. * Order event, fired when the ordering applied to the table is altered.
  13195. * @name DataTable#order.dt
  13196. * @event
  13197. * @param {event} e jQuery event object
  13198. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13199. */
  13200. /**
  13201. * DataTables initialisation complete event, fired when the table is fully
  13202. * drawn, including Ajax data loaded, if Ajax data is required.
  13203. * @name DataTable#init.dt
  13204. * @event
  13205. * @param {event} e jQuery event object
  13206. * @param {object} oSettings DataTables settings object
  13207. * @param {object} json The JSON object request from the server - only
  13208. * present if client-side Ajax sourced data is used</li></ol>
  13209. */
  13210. /**
  13211. * State save event, fired when the table has changed state a new state save
  13212. * is required. This event allows modification of the state saving object
  13213. * prior to actually doing the save, including addition or other state
  13214. * properties (for plug-ins) or modification of a DataTables core property.
  13215. * @name DataTable#stateSaveParams.dt
  13216. * @event
  13217. * @param {event} e jQuery event object
  13218. * @param {object} oSettings DataTables settings object
  13219. * @param {object} json The state information to be saved
  13220. */
  13221. /**
  13222. * State load event, fired when the table is loading state from the stored
  13223. * data, but prior to the settings object being modified by the saved state
  13224. * - allowing modification of the saved state is required or loading of
  13225. * state for a plug-in.
  13226. * @name DataTable#stateLoadParams.dt
  13227. * @event
  13228. * @param {event} e jQuery event object
  13229. * @param {object} oSettings DataTables settings object
  13230. * @param {object} json The saved state information
  13231. */
  13232. /**
  13233. * State loaded event, fired when state has been loaded from stored data and
  13234. * the settings object has been modified by the loaded data.
  13235. * @name DataTable#stateLoaded.dt
  13236. * @event
  13237. * @param {event} e jQuery event object
  13238. * @param {object} oSettings DataTables settings object
  13239. * @param {object} json The saved state information
  13240. */
  13241. /**
  13242. * Processing event, fired when DataTables is doing some kind of processing
  13243. * (be it, order, searcg or anything else). It can be used to indicate to
  13244. * the end user that there is something happening, or that something has
  13245. * finished.
  13246. * @name DataTable#processing.dt
  13247. * @event
  13248. * @param {event} e jQuery event object
  13249. * @param {object} oSettings DataTables settings object
  13250. * @param {boolean} bShow Flag for if DataTables is doing processing or not
  13251. */
  13252. /**
  13253. * Ajax (XHR) event, fired whenever an Ajax request is completed from a
  13254. * request to made to the server for new data. This event is called before
  13255. * DataTables processed the returned data, so it can also be used to pre-
  13256. * process the data returned from the server, if needed.
  13257. *
  13258. * Note that this trigger is called in `fnServerData`, if you override
  13259. * `fnServerData` and which to use this event, you need to trigger it in you
  13260. * success function.
  13261. * @name DataTable#xhr.dt
  13262. * @event
  13263. * @param {event} e jQuery event object
  13264. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13265. * @param {object} json JSON returned from the server
  13266. *
  13267. * @example
  13268. * // Use a custom property returned from the server in another DOM element
  13269. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  13270. * $('#status').html( json.status );
  13271. * } );
  13272. *
  13273. * @example
  13274. * // Pre-process the data returned from the server
  13275. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  13276. * for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
  13277. * json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
  13278. * }
  13279. * // Note no return - manipulate the data directly in the JSON object.
  13280. * } );
  13281. */
  13282. /**
  13283. * Destroy event, fired when the DataTable is destroyed by calling fnDestroy
  13284. * or passing the bDestroy:true parameter in the initialisation object. This
  13285. * can be used to remove bound events, added DOM nodes, etc.
  13286. * @name DataTable#destroy.dt
  13287. * @event
  13288. * @param {event} e jQuery event object
  13289. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13290. */
  13291. /**
  13292. * Page length change event, fired when number of records to show on each
  13293. * page (the length) is changed.
  13294. * @name DataTable#length.dt
  13295. * @event
  13296. * @param {event} e jQuery event object
  13297. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13298. * @param {integer} len New length
  13299. */
  13300. /**
  13301. * Column sizing has changed.
  13302. * @name DataTable#column-sizing.dt
  13303. * @event
  13304. * @param {event} e jQuery event object
  13305. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13306. */
  13307. /**
  13308. * Column visibility has changed.
  13309. * @name DataTable#column-visibility.dt
  13310. * @event
  13311. * @param {event} e jQuery event object
  13312. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13313. * @param {int} column Column index
  13314. * @param {bool} vis `false` if column now hidden, or `true` if visible
  13315. */
  13316. return $.fn.dataTable;
  13317. }));