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

jquery.dataTables.js 527KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870
  1. /*! DataTables 1.10.24
  2. * ©2008-2021 SpryMedia Ltd - datatables.net/license
  3. */
  4. /**
  5. * @summary DataTables
  6. * @description Paginate, search and order HTML tables
  7. * @version 1.10.24
  8. * @file jquery.dataTables.js
  9. * @author SpryMedia Ltd
  10. * @contact www.datatables.net
  11. * @copyright Copyright 2008-2021 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. } else if (typeof exports === 'object') {
  32. // CommonJS
  33. module.exports = function (root, $) {
  34. if (!root) {
  35. // CommonJS environments without a window global must pass a
  36. // root. This will give an error otherwise
  37. root = window;
  38. }
  39. if (!$) {
  40. $ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
  41. require('jquery') :
  42. require('jquery')(root);
  43. }
  44. return factory($, root, root.document);
  45. };
  46. } else {
  47. // Browser
  48. factory(jQuery, window, document);
  49. }
  50. }
  51. (function ($, window, document, undefined) {
  52. "use strict";
  53. /**
  54. * DataTables is a plug-in for the jQuery Javascript library. It is a highly
  55. * flexible tool, based upon the foundations of progressive enhancement,
  56. * which will add advanced interaction controls to any HTML table. For a
  57. * full list of features please refer to
  58. * [DataTables.net](href="http://datatables.net).
  59. *
  60. * Note that the `DataTable` object is not a global variable but is aliased
  61. * to `jQuery.fn.DataTable` and `jQuery.fn.dataTable` through which it may
  62. * be accessed.
  63. *
  64. * @class
  65. * @param {object} [init={}] Configuration object for DataTables. Options
  66. * are defined by {@link DataTable.defaults}
  67. * @requires jQuery 1.7+
  68. *
  69. * @example
  70. * // Basic initialisation
  71. * $(document).ready( function {
  72. * $('#example').dataTable();
  73. * } );
  74. *
  75. * @example
  76. * // Initialisation with configuration options - in this case, disable
  77. * // pagination and sorting.
  78. * $(document).ready( function {
  79. * $('#example').dataTable( {
  80. * "paginate": false,
  81. * "sort": false
  82. * } );
  83. * } );
  84. */
  85. var DataTable = function (options) {
  86. /**
  87. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  88. * return the resulting jQuery object.
  89. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  90. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  91. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  92. * criterion ("applied") or all TR elements (i.e. no filter).
  93. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  94. * Can be either 'current', whereby the current sorting of the table is used, or
  95. * 'original' whereby the original order the data was read into the table is used.
  96. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  97. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  98. * 'current' and filter is 'applied', regardless of what they might be given as.
  99. * @returns {object} jQuery object, filtered by the given selector.
  100. * @dtopt API
  101. * @deprecated Since v1.10
  102. *
  103. * @example
  104. * $(document).ready(function() {
  105. * var oTable = $('#example').dataTable();
  106. *
  107. * // Highlight every second row
  108. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  109. * } );
  110. *
  111. * @example
  112. * $(document).ready(function() {
  113. * var oTable = $('#example').dataTable();
  114. *
  115. * // Filter to rows with 'Webkit' in them, add a background colour and then
  116. * // remove the filter, thus highlighting the 'Webkit' rows only.
  117. * oTable.fnFilter('Webkit');
  118. * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
  119. * oTable.fnFilter('');
  120. * } );
  121. */
  122. this.$ = function (sSelector, oOpts) {
  123. return this.api(true).$(sSelector, oOpts);
  124. };
  125. /**
  126. * Almost identical to $ in operation, but in this case returns the data for the matched
  127. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  128. * rather than any descendants, so the data can be obtained for the row/cell. If matching
  129. * rows are found, the data returned is the original data array/object that was used to
  130. * create the row (or a generated array if from a DOM source).
  131. *
  132. * This method is often useful in-combination with $ where both functions are given the
  133. * same parameters and the array indexes will match identically.
  134. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  135. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  136. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  137. * criterion ("applied") or all elements (i.e. no filter).
  138. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  139. * Can be either 'current', whereby the current sorting of the table is used, or
  140. * 'original' whereby the original order the data was read into the table is used.
  141. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  142. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  143. * 'current' and filter is 'applied', regardless of what they might be given as.
  144. * @returns {array} Data for the matched elements. If any elements, as a result of the
  145. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  146. * entry in the array.
  147. * @dtopt API
  148. * @deprecated Since v1.10
  149. *
  150. * @example
  151. * $(document).ready(function() {
  152. * var oTable = $('#example').dataTable();
  153. *
  154. * // Get the data from the first row in the table
  155. * var data = oTable._('tr:first');
  156. *
  157. * // Do something useful with the data
  158. * alert( "First cell is: "+data[0] );
  159. * } );
  160. *
  161. * @example
  162. * $(document).ready(function() {
  163. * var oTable = $('#example').dataTable();
  164. *
  165. * // Filter to 'Webkit' and get all data for
  166. * oTable.fnFilter('Webkit');
  167. * var data = oTable._('tr', {"search": "applied"});
  168. *
  169. * // Do something with the data
  170. * alert( data.length+" rows matched the search" );
  171. * } );
  172. */
  173. this._ = function (sSelector, oOpts) {
  174. return this.api(true).rows(sSelector, oOpts).data();
  175. };
  176. /**
  177. * Create a DataTables Api instance, with the currently selected tables for
  178. * the Api's context.
  179. * @param {boolean} [traditional=false] Set the API instance's context to be
  180. * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
  181. * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
  182. * or if all tables captured in the jQuery object should be used.
  183. * @return {DataTables.Api}
  184. */
  185. this.api = function (traditional) {
  186. return traditional ?
  187. new _Api(
  188. _fnSettingsFromNode(this[_ext.iApiIndex])
  189. ) :
  190. new _Api(this);
  191. };
  192. /**
  193. * Add a single new row or multiple rows of data to the table. Please note
  194. * that this is suitable for client-side processing only - if you are using
  195. * server-side processing (i.e. "bServerSide": true), then to add data, you
  196. * must add it to the data source, i.e. the server-side, through an Ajax call.
  197. * @param {array|object} data The data to be added to the table. This can be:
  198. * <ul>
  199. * <li>1D array of data - add a single row with the data provided</li>
  200. * <li>2D array of arrays - add multiple rows in a single call</li>
  201. * <li>object - data object when using <i>mData</i></li>
  202. * <li>array of objects - multiple data objects when using <i>mData</i></li>
  203. * </ul>
  204. * @param {bool} [redraw=true] redraw the table or not
  205. * @returns {array} An array of integers, representing the list of indexes in
  206. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  207. * the table.
  208. * @dtopt API
  209. * @deprecated Since v1.10
  210. *
  211. * @example
  212. * // Global var for counter
  213. * var giCount = 2;
  214. *
  215. * $(document).ready(function() {
  216. * $('#example').dataTable();
  217. * } );
  218. *
  219. * function fnClickAddRow() {
  220. * $('#example').dataTable().fnAddData( [
  221. * giCount+".1",
  222. * giCount+".2",
  223. * giCount+".3",
  224. * giCount+".4" ]
  225. * );
  226. *
  227. * giCount++;
  228. * }
  229. */
  230. this.fnAddData = function (data, redraw) {
  231. var api = this.api(true);
  232. /* Check if we want to add multiple rows or not */
  233. var rows = Array.isArray(data) && (Array.isArray(data[0]) || $.isPlainObject(data[0])) ?
  234. api.rows.add(data) :
  235. api.row.add(data);
  236. if (redraw === undefined || redraw) {
  237. api.draw();
  238. }
  239. return rows.flatten().toArray();
  240. };
  241. /**
  242. * This function will make DataTables recalculate the column sizes, based on the data
  243. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  244. * through the sWidth parameter). This can be useful when the width of the table's
  245. * parent element changes (for example a window resize).
  246. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  247. * @dtopt API
  248. * @deprecated Since v1.10
  249. *
  250. * @example
  251. * $(document).ready(function() {
  252. * var oTable = $('#example').dataTable( {
  253. * "sScrollY": "200px",
  254. * "bPaginate": false
  255. * } );
  256. *
  257. * $(window).on('resize', function () {
  258. * oTable.fnAdjustColumnSizing();
  259. * } );
  260. * } );
  261. */
  262. this.fnAdjustColumnSizing = function (bRedraw) {
  263. var api = this.api(true).columns.adjust();
  264. var settings = api.settings()[0];
  265. var scroll = settings.oScroll;
  266. if (bRedraw === undefined || bRedraw) {
  267. api.draw(false);
  268. } else if (scroll.sX !== "" || scroll.sY !== "") {
  269. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  270. _fnScrollDraw(settings);
  271. }
  272. };
  273. /**
  274. * Quickly and simply clear a table
  275. * @param {bool} [bRedraw=true] redraw the table or not
  276. * @dtopt API
  277. * @deprecated Since v1.10
  278. *
  279. * @example
  280. * $(document).ready(function() {
  281. * var oTable = $('#example').dataTable();
  282. *
  283. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  284. * oTable.fnClearTable();
  285. * } );
  286. */
  287. this.fnClearTable = function (bRedraw) {
  288. var api = this.api(true).clear();
  289. if (bRedraw === undefined || bRedraw) {
  290. api.draw();
  291. }
  292. };
  293. /**
  294. * The exact opposite of 'opening' a row, this function will close any rows which
  295. * are currently 'open'.
  296. * @param {node} nTr the table row to 'close'
  297. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  298. * @dtopt API
  299. * @deprecated Since v1.10
  300. *
  301. * @example
  302. * $(document).ready(function() {
  303. * var oTable;
  304. *
  305. * // 'open' an information row when a row is clicked on
  306. * $('#example tbody tr').click( function () {
  307. * if ( oTable.fnIsOpen(this) ) {
  308. * oTable.fnClose( this );
  309. * } else {
  310. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  311. * }
  312. * } );
  313. *
  314. * oTable = $('#example').dataTable();
  315. * } );
  316. */
  317. this.fnClose = function (nTr) {
  318. this.api(true).row(nTr).child.hide();
  319. };
  320. /**
  321. * Remove a row for the table
  322. * @param {mixed} target The index of the row from aoData to be deleted, or
  323. * the TR element you want to delete
  324. * @param {function|null} [callBack] Callback function
  325. * @param {bool} [redraw=true] Redraw the table or not
  326. * @returns {array} The row that was deleted
  327. * @dtopt API
  328. * @deprecated Since v1.10
  329. *
  330. * @example
  331. * $(document).ready(function() {
  332. * var oTable = $('#example').dataTable();
  333. *
  334. * // Immediately remove the first row
  335. * oTable.fnDeleteRow( 0 );
  336. * } );
  337. */
  338. this.fnDeleteRow = function (target, callback, redraw) {
  339. var api = this.api(true);
  340. var rows = api.rows(target);
  341. var settings = rows.settings()[0];
  342. var data = settings.aoData[rows[0][0]];
  343. rows.remove();
  344. if (callback) {
  345. callback.call(this, settings, data);
  346. }
  347. if (redraw === undefined || redraw) {
  348. api.draw();
  349. }
  350. return data;
  351. };
  352. /**
  353. * Restore the table to it's original state in the DOM by removing all of DataTables
  354. * enhancements, alterations to the DOM structure of the table and event listeners.
  355. * @param {boolean} [remove=false] Completely remove the table from the DOM
  356. * @dtopt API
  357. * @deprecated Since v1.10
  358. *
  359. * @example
  360. * $(document).ready(function() {
  361. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  362. * var oTable = $('#example').dataTable();
  363. * oTable.fnDestroy();
  364. * } );
  365. */
  366. this.fnDestroy = function (remove) {
  367. this.api(true).destroy(remove);
  368. };
  369. /**
  370. * Redraw the table
  371. * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
  372. * @dtopt API
  373. * @deprecated Since v1.10
  374. *
  375. * @example
  376. * $(document).ready(function() {
  377. * var oTable = $('#example').dataTable();
  378. *
  379. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  380. * oTable.fnDraw();
  381. * } );
  382. */
  383. this.fnDraw = function (complete) {
  384. // Note that this isn't an exact match to the old call to _fnDraw - it takes
  385. // into account the new data, but can hold position.
  386. this.api(true).draw(complete);
  387. };
  388. /**
  389. * Filter the input based on data
  390. * @param {string} sInput String to filter the table on
  391. * @param {int|null} [iColumn] Column to limit filtering to
  392. * @param {bool} [bRegex=false] Treat as regular expression or not
  393. * @param {bool} [bSmart=true] Perform smart filtering or not
  394. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  395. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  396. * @dtopt API
  397. * @deprecated Since v1.10
  398. *
  399. * @example
  400. * $(document).ready(function() {
  401. * var oTable = $('#example').dataTable();
  402. *
  403. * // Sometime later - filter...
  404. * oTable.fnFilter( 'test string' );
  405. * } );
  406. */
  407. this.fnFilter = function (sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive) {
  408. var api = this.api(true);
  409. if (iColumn === null || iColumn === undefined) {
  410. api.search(sInput, bRegex, bSmart, bCaseInsensitive);
  411. } else {
  412. api.column(iColumn).search(sInput, bRegex, bSmart, bCaseInsensitive);
  413. }
  414. api.draw();
  415. };
  416. /**
  417. * Get the data for the whole table, an individual row or an individual cell based on the
  418. * provided parameters.
  419. * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
  420. * a TR node then the data source for the whole row will be returned. If given as a
  421. * TD/TH cell node then iCol will be automatically calculated and the data for the
  422. * cell returned. If given as an integer, then this is treated as the aoData internal
  423. * data index for the row (see fnGetPosition) and the data for that row used.
  424. * @param {int} [col] Optional column index that you want the data of.
  425. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  426. * returned. If mRow is defined, just data for that row, and is iCol is
  427. * defined, only data for the designated cell is returned.
  428. * @dtopt API
  429. * @deprecated Since v1.10
  430. *
  431. * @example
  432. * // Row data
  433. * $(document).ready(function() {
  434. * oTable = $('#example').dataTable();
  435. *
  436. * oTable.$('tr').click( function () {
  437. * var data = oTable.fnGetData( this );
  438. * // ... do something with the array / object of data for the row
  439. * } );
  440. * } );
  441. *
  442. * @example
  443. * // Individual cell data
  444. * $(document).ready(function() {
  445. * oTable = $('#example').dataTable();
  446. *
  447. * oTable.$('td').click( function () {
  448. * var sData = oTable.fnGetData( this );
  449. * alert( 'The cell clicked on had the value of '+sData );
  450. * } );
  451. * } );
  452. */
  453. this.fnGetData = function (src, col) {
  454. var api = this.api(true);
  455. if (src !== undefined) {
  456. var type = src.nodeName ? src.nodeName.toLowerCase() : '';
  457. return col !== undefined || type == 'td' || type == 'th' ?
  458. api.cell(src, col).data() :
  459. api.row(src).data() || null;
  460. }
  461. return api.data().toArray();
  462. };
  463. /**
  464. * Get an array of the TR nodes that are used in the table's body. Note that you will
  465. * typically want to use the '$' API method in preference to this as it is more
  466. * flexible.
  467. * @param {int} [iRow] Optional row index for the TR element you want
  468. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  469. * in the table's body, or iRow is defined, just the TR element requested.
  470. * @dtopt API
  471. * @deprecated Since v1.10
  472. *
  473. * @example
  474. * $(document).ready(function() {
  475. * var oTable = $('#example').dataTable();
  476. *
  477. * // Get the nodes from the table
  478. * var nNodes = oTable.fnGetNodes( );
  479. * } );
  480. */
  481. this.fnGetNodes = function (iRow) {
  482. var api = this.api(true);
  483. return iRow !== undefined ?
  484. api.row(iRow).node() :
  485. api.rows().nodes().flatten().toArray();
  486. };
  487. /**
  488. * Get the array indexes of a particular cell from it's DOM element
  489. * and column index including hidden columns
  490. * @param {node} node this can either be a TR, TD or TH in the table's body
  491. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  492. * if given as a cell, an array of [row index, column index (visible),
  493. * column index (all)] is given.
  494. * @dtopt API
  495. * @deprecated Since v1.10
  496. *
  497. * @example
  498. * $(document).ready(function() {
  499. * $('#example tbody td').click( function () {
  500. * // Get the position of the current data from the node
  501. * var aPos = oTable.fnGetPosition( this );
  502. *
  503. * // Get the data array for this row
  504. * var aData = oTable.fnGetData( aPos[0] );
  505. *
  506. * // Update the data array and return the value
  507. * aData[ aPos[1] ] = 'clicked';
  508. * this.innerHTML = 'clicked';
  509. * } );
  510. *
  511. * // Init DataTables
  512. * oTable = $('#example').dataTable();
  513. * } );
  514. */
  515. this.fnGetPosition = function (node) {
  516. var api = this.api(true);
  517. var nodeName = node.nodeName.toUpperCase();
  518. if (nodeName == 'TR') {
  519. return api.row(node).index();
  520. } else if (nodeName == 'TD' || nodeName == 'TH') {
  521. var cell = api.cell(node).index();
  522. return [
  523. cell.row,
  524. cell.columnVisible,
  525. cell.column
  526. ];
  527. }
  528. return null;
  529. };
  530. /**
  531. * Check to see if a row is 'open' or not.
  532. * @param {node} nTr the table row to check
  533. * @returns {boolean} true if the row is currently open, false otherwise
  534. * @dtopt API
  535. * @deprecated Since v1.10
  536. *
  537. * @example
  538. * $(document).ready(function() {
  539. * var oTable;
  540. *
  541. * // 'open' an information row when a row is clicked on
  542. * $('#example tbody tr').click( function () {
  543. * if ( oTable.fnIsOpen(this) ) {
  544. * oTable.fnClose( this );
  545. * } else {
  546. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  547. * }
  548. * } );
  549. *
  550. * oTable = $('#example').dataTable();
  551. * } );
  552. */
  553. this.fnIsOpen = function (nTr) {
  554. return this.api(true).row(nTr).child.isShown();
  555. };
  556. /**
  557. * This function will place a new row directly after a row which is currently
  558. * on display on the page, with the HTML contents that is passed into the
  559. * function. This can be used, for example, to ask for confirmation that a
  560. * particular record should be deleted.
  561. * @param {node} nTr The table row to 'open'
  562. * @param {string|node|jQuery} mHtml The HTML to put into the row
  563. * @param {string} sClass Class to give the new TD cell
  564. * @returns {node} The row opened. Note that if the table row passed in as the
  565. * first parameter, is not found in the table, this method will silently
  566. * return.
  567. * @dtopt API
  568. * @deprecated Since v1.10
  569. *
  570. * @example
  571. * $(document).ready(function() {
  572. * var oTable;
  573. *
  574. * // 'open' an information row when a row is clicked on
  575. * $('#example tbody tr').click( function () {
  576. * if ( oTable.fnIsOpen(this) ) {
  577. * oTable.fnClose( this );
  578. * } else {
  579. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  580. * }
  581. * } );
  582. *
  583. * oTable = $('#example').dataTable();
  584. * } );
  585. */
  586. this.fnOpen = function (nTr, mHtml, sClass) {
  587. return this.api(true)
  588. .row(nTr)
  589. .child(mHtml, sClass)
  590. .show()
  591. .child()[0];
  592. };
  593. /**
  594. * Change the pagination - provides the internal logic for pagination in a simple API
  595. * function. With this function you can have a DataTables table go to the next,
  596. * previous, first or last pages.
  597. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  598. * or page number to jump to (integer), note that page 0 is the first page.
  599. * @param {bool} [bRedraw=true] Redraw the table or not
  600. * @dtopt API
  601. * @deprecated Since v1.10
  602. *
  603. * @example
  604. * $(document).ready(function() {
  605. * var oTable = $('#example').dataTable();
  606. * oTable.fnPageChange( 'next' );
  607. * } );
  608. */
  609. this.fnPageChange = function (mAction, bRedraw) {
  610. var api = this.api(true).page(mAction);
  611. if (bRedraw === undefined || bRedraw) {
  612. api.draw(false);
  613. }
  614. };
  615. /**
  616. * Show a particular column
  617. * @param {int} iCol The column whose display should be changed
  618. * @param {bool} bShow Show (true) or hide (false) the column
  619. * @param {bool} [bRedraw=true] Redraw the table or not
  620. * @dtopt API
  621. * @deprecated Since v1.10
  622. *
  623. * @example
  624. * $(document).ready(function() {
  625. * var oTable = $('#example').dataTable();
  626. *
  627. * // Hide the second column after initialisation
  628. * oTable.fnSetColumnVis( 1, false );
  629. * } );
  630. */
  631. this.fnSetColumnVis = function (iCol, bShow, bRedraw) {
  632. var api = this.api(true).column(iCol).visible(bShow);
  633. if (bRedraw === undefined || bRedraw) {
  634. api.columns.adjust().draw();
  635. }
  636. };
  637. /**
  638. * Get the settings for a particular table for external manipulation
  639. * @returns {object} DataTables settings object. See
  640. * {@link DataTable.models.oSettings}
  641. * @dtopt API
  642. * @deprecated Since v1.10
  643. *
  644. * @example
  645. * $(document).ready(function() {
  646. * var oTable = $('#example').dataTable();
  647. * var oSettings = oTable.fnSettings();
  648. *
  649. * // Show an example parameter from the settings
  650. * alert( oSettings._iDisplayStart );
  651. * } );
  652. */
  653. this.fnSettings = function () {
  654. return _fnSettingsFromNode(this[_ext.iApiIndex]);
  655. };
  656. /**
  657. * Sort the table by a particular column
  658. * @param {int} iCol the data index to sort on. Note that this will not match the
  659. * 'display index' if you have hidden data entries
  660. * @dtopt API
  661. * @deprecated Since v1.10
  662. *
  663. * @example
  664. * $(document).ready(function() {
  665. * var oTable = $('#example').dataTable();
  666. *
  667. * // Sort immediately with columns 0 and 1
  668. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  669. * } );
  670. */
  671. this.fnSort = function (aaSort) {
  672. this.api(true).order(aaSort).draw();
  673. };
  674. /**
  675. * Attach a sort listener to an element for a given column
  676. * @param {node} nNode the element to attach the sort listener to
  677. * @param {int} iColumn the column that a click on this node will sort on
  678. * @param {function} [fnCallback] callback function when sort is run
  679. * @dtopt API
  680. * @deprecated Since v1.10
  681. *
  682. * @example
  683. * $(document).ready(function() {
  684. * var oTable = $('#example').dataTable();
  685. *
  686. * // Sort on column 1, when 'sorter' is clicked on
  687. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  688. * } );
  689. */
  690. this.fnSortListener = function (nNode, iColumn, fnCallback) {
  691. this.api(true).order.listener(nNode, iColumn, fnCallback);
  692. };
  693. /**
  694. * Update a table cell or row - this method will accept either a single value to
  695. * update the cell with, an array of values with one element for each column or
  696. * an object in the same format as the original data source. The function is
  697. * self-referencing in order to make the multi column updates easier.
  698. * @param {object|array|string} mData Data to update the cell/row with
  699. * @param {node|int} mRow TR element you want to update or the aoData index
  700. * @param {int} [iColumn] The column to update, give as null or undefined to
  701. * update a whole row.
  702. * @param {bool} [bRedraw=true] Redraw the table or not
  703. * @param {bool} [bAction=true] Perform pre-draw actions or not
  704. * @returns {int} 0 on success, 1 on error
  705. * @dtopt API
  706. * @deprecated Since v1.10
  707. *
  708. * @example
  709. * $(document).ready(function() {
  710. * var oTable = $('#example').dataTable();
  711. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  712. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
  713. * } );
  714. */
  715. this.fnUpdate = function (mData, mRow, iColumn, bRedraw, bAction) {
  716. var api = this.api(true);
  717. if (iColumn === undefined || iColumn === null) {
  718. api.row(mRow).data(mData);
  719. } else {
  720. api.cell(mRow, iColumn).data(mData);
  721. }
  722. if (bAction === undefined || bAction) {
  723. api.columns.adjust();
  724. }
  725. if (bRedraw === undefined || bRedraw) {
  726. api.draw();
  727. }
  728. return 0;
  729. };
  730. /**
  731. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  732. * to ensure compatibility.
  733. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  734. * formats "X" and "X.Y" are also acceptable.
  735. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  736. * version, or false if this version of DataTales is not suitable
  737. * @method
  738. * @dtopt API
  739. * @deprecated Since v1.10
  740. *
  741. * @example
  742. * $(document).ready(function() {
  743. * var oTable = $('#example').dataTable();
  744. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  745. * } );
  746. */
  747. this.fnVersionCheck = _ext.fnVersionCheck;
  748. var _that = this;
  749. var emptyInit = options === undefined;
  750. var len = this.length;
  751. if (emptyInit) {
  752. options = {};
  753. }
  754. this.oApi = this.internal = _ext.internal;
  755. // Extend with old style plug-in API methods
  756. for (var fn in DataTable.ext.internal) {
  757. if (fn) {
  758. this[fn] = _fnExternApiFunc(fn);
  759. }
  760. }
  761. this.each(function () {
  762. // For each initialisation we want to give it a clean initialisation
  763. // object that can be bashed around
  764. var o = {};
  765. var oInit = len > 1 ? // optimisation for single table case
  766. _fnExtend(o, options, true) :
  767. options;
  768. /*global oInit,_that,emptyInit*/
  769. var i = 0, iLen, j, jLen, k, kLen;
  770. var sId = this.getAttribute('id');
  771. var bInitHandedOff = false;
  772. var defaults = DataTable.defaults;
  773. var $this = $(this);
  774. /* Sanity check */
  775. if (this.nodeName.toLowerCase() != 'table') {
  776. _fnLog(null, 0, 'Non-table node initialisation (' + this.nodeName + ')', 2);
  777. return;
  778. }
  779. /* Backwards compatibility for the defaults */
  780. _fnCompatOpts(defaults);
  781. _fnCompatCols(defaults.column);
  782. /* Convert the camel-case defaults to Hungarian */
  783. _fnCamelToHungarian(defaults, defaults, true);
  784. _fnCamelToHungarian(defaults.column, defaults.column, true);
  785. /* Setting up the initialisation object */
  786. _fnCamelToHungarian(defaults, $.extend(oInit, $this.data()), true);
  787. /* Check to see if we are re-initialising a table */
  788. var allSettings = DataTable.settings;
  789. for (i = 0, iLen = allSettings.length; i < iLen; i++) {
  790. var s = allSettings[i];
  791. /* Base check on table node */
  792. if (
  793. s.nTable == this ||
  794. (s.nTHead && s.nTHead.parentNode == this) ||
  795. (s.nTFoot && s.nTFoot.parentNode == this)
  796. ) {
  797. var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
  798. var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
  799. if (emptyInit || bRetrieve) {
  800. return s.oInstance;
  801. } else if (bDestroy) {
  802. s.oInstance.fnDestroy();
  803. break;
  804. } else {
  805. _fnLog(s, 0, 'Cannot reinitialise DataTable', 3);
  806. return;
  807. }
  808. }
  809. /* If the element we are initialising has the same ID as a table which was previously
  810. * initialised, but the table nodes don't match (from before) then we destroy the old
  811. * instance by simply deleting it. This is under the assumption that the table has been
  812. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  813. */
  814. if (s.sTableId == this.id) {
  815. allSettings.splice(i, 1);
  816. break;
  817. }
  818. }
  819. /* Ensure the table has an ID - required for accessibility */
  820. if (sId === null || sId === "") {
  821. sId = "DataTables_Table_" + (DataTable.ext._unique++);
  822. this.id = sId;
  823. }
  824. /* Create the settings object for this table and set some of the default parameters */
  825. var oSettings = $.extend(true, {}, DataTable.models.oSettings, {
  826. "sDestroyWidth": $this[0].style.width,
  827. "sInstance": sId,
  828. "sTableId": sId
  829. });
  830. oSettings.nTable = this;
  831. oSettings.oApi = _that.internal;
  832. oSettings.oInit = oInit;
  833. allSettings.push(oSettings);
  834. // Need to add the instance after the instance after the settings object has been added
  835. // to the settings array, so we can self reference the table instance if more than one
  836. oSettings.oInstance = (_that.length === 1) ? _that : $this.dataTable();
  837. // Backwards compatibility, before we apply all the defaults
  838. _fnCompatOpts(oInit);
  839. _fnLanguageCompat(oInit.oLanguage);
  840. // If the length menu is given, but the init display length is not, use the length menu
  841. if (oInit.aLengthMenu && !oInit.iDisplayLength) {
  842. oInit.iDisplayLength = Array.isArray(oInit.aLengthMenu[0]) ?
  843. oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
  844. }
  845. // Apply the defaults and init options to make a single init object will all
  846. // options defined from defaults and instance options.
  847. oInit = _fnExtend($.extend(true, {}, defaults), oInit);
  848. // Map the initialisation options onto the settings object
  849. _fnMap(oSettings.oFeatures, oInit, [
  850. "bPaginate",
  851. "bLengthChange",
  852. "bFilter",
  853. "bSort",
  854. "bSortMulti",
  855. "bInfo",
  856. "bProcessing",
  857. "bAutoWidth",
  858. "bSortClasses",
  859. "bServerSide",
  860. "bDeferRender"
  861. ]);
  862. _fnMap(oSettings, oInit, [
  863. "asStripeClasses",
  864. "ajax",
  865. "fnServerData",
  866. "fnFormatNumber",
  867. "sServerMethod",
  868. "aaSorting",
  869. "aaSortingFixed",
  870. "aLengthMenu",
  871. "sPaginationType",
  872. "sAjaxSource",
  873. "sAjaxDataProp",
  874. "iStateDuration",
  875. "sDom",
  876. "bSortCellsTop",
  877. "iTabIndex",
  878. "fnStateLoadCallback",
  879. "fnStateSaveCallback",
  880. "renderer",
  881. "searchDelay",
  882. "rowId",
  883. ["iCookieDuration", "iStateDuration"], // backwards compat
  884. ["oSearch", "oPreviousSearch"],
  885. ["aoSearchCols", "aoPreSearchCols"],
  886. ["iDisplayLength", "_iDisplayLength"]
  887. ]);
  888. _fnMap(oSettings.oScroll, oInit, [
  889. ["sScrollX", "sX"],
  890. ["sScrollXInner", "sXInner"],
  891. ["sScrollY", "sY"],
  892. ["bScrollCollapse", "bCollapse"]
  893. ]);
  894. _fnMap(oSettings.oLanguage, oInit, "fnInfoCallback");
  895. /* Callback functions which are array driven */
  896. _fnCallbackReg(oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user');
  897. _fnCallbackReg(oSettings, 'aoServerParams', oInit.fnServerParams, 'user');
  898. _fnCallbackReg(oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user');
  899. _fnCallbackReg(oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user');
  900. _fnCallbackReg(oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user');
  901. _fnCallbackReg(oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user');
  902. _fnCallbackReg(oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user');
  903. _fnCallbackReg(oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user');
  904. _fnCallbackReg(oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user');
  905. _fnCallbackReg(oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user');
  906. _fnCallbackReg(oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user');
  907. oSettings.rowIdFn = _fnGetObjectDataFn(oInit.rowId);
  908. /* Browser support detection */
  909. _fnBrowserDetect(oSettings);
  910. var oClasses = oSettings.oClasses;
  911. $.extend(oClasses, DataTable.ext.classes, oInit.oClasses);
  912. $this.addClass(oClasses.sTable);
  913. if (oSettings.iInitDisplayStart === undefined) {
  914. /* Display start point, taking into account the save saving */
  915. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  916. oSettings._iDisplayStart = oInit.iDisplayStart;
  917. }
  918. if (oInit.iDeferLoading !== null) {
  919. oSettings.bDeferLoading = true;
  920. var tmp = Array.isArray(oInit.iDeferLoading);
  921. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  922. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  923. }
  924. /* Language definitions */
  925. var oLanguage = oSettings.oLanguage;
  926. $.extend(true, oLanguage, oInit.oLanguage);
  927. if (oLanguage.sUrl) {
  928. /* Get the language definitions from a file - because this Ajax call makes the language
  929. * get async to the remainder of this function we use bInitHandedOff to indicate that
  930. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  931. */
  932. $.ajax({
  933. dataType: 'json',
  934. url: oLanguage.sUrl,
  935. success: function (json) {
  936. _fnLanguageCompat(json);
  937. _fnCamelToHungarian(defaults.oLanguage, json);
  938. $.extend(true, oLanguage, json);
  939. _fnCallbackFire(oSettings, null, 'i18n', [oSettings]);
  940. _fnInitialise(oSettings);
  941. },
  942. error: function () {
  943. // Error occurred loading language file, continue on as best we can
  944. _fnInitialise(oSettings);
  945. }
  946. });
  947. bInitHandedOff = true;
  948. } else {
  949. _fnCallbackFire(oSettings, null, 'i18n', [oSettings]);
  950. }
  951. /*
  952. * Stripes
  953. */
  954. if (oInit.asStripeClasses === null) {
  955. oSettings.asStripeClasses = [
  956. oClasses.sStripeOdd,
  957. oClasses.sStripeEven
  958. ];
  959. }
  960. /* Remove row stripe classes if they are already on the table row */
  961. var stripeClasses = oSettings.asStripeClasses;
  962. var rowOne = $this.children('tbody').find('tr').eq(0);
  963. if ($.inArray(true, $.map(stripeClasses, function (el, i) {
  964. return rowOne.hasClass(el);
  965. })) !== -1) {
  966. $('tbody tr', this).removeClass(stripeClasses.join(' '));
  967. oSettings.asDestroyStripes = stripeClasses.slice();
  968. }
  969. /*
  970. * Columns
  971. * See if we should load columns automatically or use defined ones
  972. */
  973. var anThs = [];
  974. var aoColumnsInit;
  975. var nThead = this.getElementsByTagName('thead');
  976. if (nThead.length !== 0) {
  977. _fnDetectHeader(oSettings.aoHeader, nThead[0]);
  978. anThs = _fnGetUniqueThs(oSettings);
  979. }
  980. /* If not given a column array, generate one with nulls */
  981. if (oInit.aoColumns === null) {
  982. aoColumnsInit = [];
  983. for (i = 0, iLen = anThs.length; i < iLen; i++) {
  984. aoColumnsInit.push(null);
  985. }
  986. } else {
  987. aoColumnsInit = oInit.aoColumns;
  988. }
  989. /* Add the columns */
  990. for (i = 0, iLen = aoColumnsInit.length; i < iLen; i++) {
  991. _fnAddColumn(oSettings, anThs ? anThs[i] : null);
  992. }
  993. /* Apply the column definitions */
  994. _fnApplyColumnDefs(oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  995. _fnColumnOptions(oSettings, iCol, oDef);
  996. });
  997. /* HTML5 attribute detection - build an mData object automatically if the
  998. * attributes are found
  999. */
  1000. if (rowOne.length) {
  1001. var a = function (cell, name) {
  1002. return cell.getAttribute('data-' + name) !== null ? name : null;
  1003. };
  1004. $(rowOne[0]).children('th, td').each(function (i, cell) {
  1005. var col = oSettings.aoColumns[i];
  1006. if (col.mData === i) {
  1007. var sort = a(cell, 'sort') || a(cell, 'order');
  1008. var filter = a(cell, 'filter') || a(cell, 'search');
  1009. if (sort !== null || filter !== null) {
  1010. col.mData = {
  1011. _: i + '.display',
  1012. sort: sort !== null ? i + '.@data-' + sort : undefined,
  1013. type: sort !== null ? i + '.@data-' + sort : undefined,
  1014. filter: filter !== null ? i + '.@data-' + filter : undefined
  1015. };
  1016. _fnColumnOptions(oSettings, i);
  1017. }
  1018. }
  1019. });
  1020. }
  1021. var features = oSettings.oFeatures;
  1022. var loadedInit = function () {
  1023. /*
  1024. * Sorting
  1025. * @todo For modularisation (1.11) this needs to do into a sort start up handler
  1026. */
  1027. // If aaSorting is not defined, then we use the first indicator in asSorting
  1028. // in case that has been altered, so the default sort reflects that option
  1029. if (oInit.aaSorting === undefined) {
  1030. var sorting = oSettings.aaSorting;
  1031. for (i = 0, iLen = sorting.length; i < iLen; i++) {
  1032. sorting[i][1] = oSettings.aoColumns[i].asSorting[0];
  1033. }
  1034. }
  1035. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  1036. * account, and also will apply sorting disabled classes if disabled
  1037. */
  1038. _fnSortingClasses(oSettings);
  1039. if (features.bSort) {
  1040. _fnCallbackReg(oSettings, 'aoDrawCallback', function () {
  1041. if (oSettings.bSorted) {
  1042. var aSort = _fnSortFlatten(oSettings);
  1043. var sortedColumns = {};
  1044. $.each(aSort, function (i, val) {
  1045. sortedColumns[val.src] = val.dir;
  1046. });
  1047. _fnCallbackFire(oSettings, null, 'order', [oSettings, aSort, sortedColumns]);
  1048. _fnSortAria(oSettings);
  1049. }
  1050. });
  1051. }
  1052. _fnCallbackReg(oSettings, 'aoDrawCallback', function () {
  1053. if (oSettings.bSorted || _fnDataSource(oSettings) === 'ssp' || features.bDeferRender) {
  1054. _fnSortingClasses(oSettings);
  1055. }
  1056. }, 'sc');
  1057. /*
  1058. * Final init
  1059. * Cache the header, body and footer as required, creating them if needed
  1060. */
  1061. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  1062. var captions = $this.children('caption').each(function () {
  1063. this._captionSide = $(this).css('caption-side');
  1064. });
  1065. var thead = $this.children('thead');
  1066. if (thead.length === 0) {
  1067. thead = $('<thead/>').appendTo($this);
  1068. }
  1069. oSettings.nTHead = thead[0];
  1070. var tbody = $this.children('tbody');
  1071. if (tbody.length === 0) {
  1072. tbody = $('<tbody/>').appendTo($this);
  1073. }
  1074. oSettings.nTBody = tbody[0];
  1075. var tfoot = $this.children('tfoot');
  1076. if (tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "")) {
  1077. // If we are a scrolling table, and no footer has been given, then we need to create
  1078. // a tfoot element for the caption element to be appended to
  1079. tfoot = $('<tfoot/>').appendTo($this);
  1080. }
  1081. if (tfoot.length === 0 || tfoot.children().length === 0) {
  1082. $this.addClass(oClasses.sNoFooter);
  1083. } else if (tfoot.length > 0) {
  1084. oSettings.nTFoot = tfoot[0];
  1085. _fnDetectHeader(oSettings.aoFooter, oSettings.nTFoot);
  1086. }
  1087. /* Check if there is data passing into the constructor */
  1088. if (oInit.aaData) {
  1089. for (i = 0; i < oInit.aaData.length; i++) {
  1090. _fnAddData(oSettings, oInit.aaData[i]);
  1091. }
  1092. } else if (oSettings.bDeferLoading || _fnDataSource(oSettings) == 'dom') {
  1093. /* Grab the data from the page - only do this when deferred loading or no Ajax
  1094. * source since there is no point in reading the DOM data if we are then going
  1095. * to replace it with Ajax data
  1096. */
  1097. _fnAddTr(oSettings, $(oSettings.nTBody).children('tr'));
  1098. }
  1099. /* Copy the data index array */
  1100. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  1101. /* Initialisation complete - table can be drawn */
  1102. oSettings.bInitialised = true;
  1103. /* Check if we need to initialise the table (it might not have been handed off to the
  1104. * language processor)
  1105. */
  1106. if (bInitHandedOff === false) {
  1107. _fnInitialise(oSettings);
  1108. }
  1109. };
  1110. /* Must be done after everything which can be overridden by the state saving! */
  1111. if (oInit.bStateSave) {
  1112. features.bStateSave = true;
  1113. _fnCallbackReg(oSettings, 'aoDrawCallback', _fnSaveState, 'state_save');
  1114. _fnLoadState(oSettings, oInit, loadedInit);
  1115. } else {
  1116. loadedInit();
  1117. }
  1118. });
  1119. _that = null;
  1120. return this;
  1121. };
  1122. /*
  1123. * It is useful to have variables which are scoped locally so only the
  1124. * DataTables functions can access them and they don't leak into global space.
  1125. * At the same time these functions are often useful over multiple files in the
  1126. * core and API, so we list, or at least document, all variables which are used
  1127. * by DataTables as private variables here. This also ensures that there is no
  1128. * clashing of variable names and that they can easily referenced for reuse.
  1129. */
  1130. // Defined else where
  1131. // _selector_run
  1132. // _selector_opts
  1133. // _selector_first
  1134. // _selector_row_indexes
  1135. var _ext; // DataTable.ext
  1136. var _Api; // DataTable.Api
  1137. var _api_register; // DataTable.Api.register
  1138. var _api_registerPlural; // DataTable.Api.registerPlural
  1139. var _re_dic = {};
  1140. var _re_new_lines = /[\r\n\u2028]/g;
  1141. var _re_html = /<.*?>/g;
  1142. // This is not strict ISO8601 - Date.parse() is quite lax, although
  1143. // implementations differ between browsers.
  1144. var _re_date = /^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/;
  1145. // Escape regular expression special characters
  1146. var _re_escape_regex = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-'].join('|\\') + ')', 'g');
  1147. // http://en.wikipedia.org/wiki/Foreign_exchange_market
  1148. // - \u20BD - Russian ruble.
  1149. // - \u20a9 - South Korean Won
  1150. // - \u20BA - Turkish Lira
  1151. // - \u20B9 - Indian Rupee
  1152. // - R - Brazil (R$) and South Africa
  1153. // - fr - Swiss Franc
  1154. // - kr - Swedish krona, Norwegian krone and Danish krone
  1155. // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
  1156. // - Ƀ - Bitcoin
  1157. // - Ξ - Ethereum
  1158. // standards as thousands separators.
  1159. var _re_formatted_numeric = /['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi;
  1160. var _empty = function (d) {
  1161. return !d || d === true || d === '-' ? true : false;
  1162. };
  1163. var _intVal = function (s) {
  1164. var integer = parseInt(s, 10);
  1165. return !isNaN(integer) && isFinite(s) ? integer : null;
  1166. };
  1167. // Convert from a formatted number with characters other than `.` as the
  1168. // decimal place, to a Javascript number
  1169. var _numToDecimal = function (num, decimalPoint) {
  1170. // Cache created regular expressions for speed as this function is called often
  1171. if (!_re_dic[decimalPoint]) {
  1172. _re_dic[decimalPoint] = new RegExp(_fnEscapeRegex(decimalPoint), 'g');
  1173. }
  1174. return typeof num === 'string' && decimalPoint !== '.' ?
  1175. num.replace(/\./g, '').replace(_re_dic[decimalPoint], '.') :
  1176. num;
  1177. };
  1178. var _isNumber = function (d, decimalPoint, formatted) {
  1179. var strType = typeof d === 'string';
  1180. // If empty return immediately so there must be a number if it is a
  1181. // formatted string (this stops the string "k", or "kr", etc being detected
  1182. // as a formatted number for currency
  1183. if (_empty(d)) {
  1184. return true;
  1185. }
  1186. if (decimalPoint && strType) {
  1187. d = _numToDecimal(d, decimalPoint);
  1188. }
  1189. if (formatted && strType) {
  1190. d = d.replace(_re_formatted_numeric, '');
  1191. }
  1192. return !isNaN(parseFloat(d)) && isFinite(d);
  1193. };
  1194. // A string without HTML in it can be considered to be HTML still
  1195. var _isHtml = function (d) {
  1196. return _empty(d) || typeof d === 'string';
  1197. };
  1198. var _htmlNumeric = function (d, decimalPoint, formatted) {
  1199. if (_empty(d)) {
  1200. return true;
  1201. }
  1202. var html = _isHtml(d);
  1203. return !html ?
  1204. null :
  1205. _isNumber(_stripHtml(d), decimalPoint, formatted) ?
  1206. true :
  1207. null;
  1208. };
  1209. var _pluck = function (a, prop, prop2) {
  1210. var out = [];
  1211. var i = 0, ien = a.length;
  1212. // Could have the test in the loop for slightly smaller code, but speed
  1213. // is essential here
  1214. if (prop2 !== undefined) {
  1215. for (; i < ien; i++) {
  1216. if (a[i] && a[i][prop]) {
  1217. out.push(a[i][prop][prop2]);
  1218. }
  1219. }
  1220. } else {
  1221. for (; i < ien; i++) {
  1222. if (a[i]) {
  1223. out.push(a[i][prop]);
  1224. }
  1225. }
  1226. }
  1227. return out;
  1228. };
  1229. // Basically the same as _pluck, but rather than looping over `a` we use `order`
  1230. // as the indexes to pick from `a`
  1231. var _pluck_order = function (a, order, prop, prop2) {
  1232. var out = [];
  1233. var i = 0, ien = order.length;
  1234. // Could have the test in the loop for slightly smaller code, but speed
  1235. // is essential here
  1236. if (prop2 !== undefined) {
  1237. for (; i < ien; i++) {
  1238. if (a[order[i]][prop]) {
  1239. out.push(a[order[i]][prop][prop2]);
  1240. }
  1241. }
  1242. } else {
  1243. for (; i < ien; i++) {
  1244. out.push(a[order[i]][prop]);
  1245. }
  1246. }
  1247. return out;
  1248. };
  1249. var _range = function (len, start) {
  1250. var out = [];
  1251. var end;
  1252. if (start === undefined) {
  1253. start = 0;
  1254. end = len;
  1255. } else {
  1256. end = start;
  1257. start = len;
  1258. }
  1259. for (var i = start; i < end; i++) {
  1260. out.push(i);
  1261. }
  1262. return out;
  1263. };
  1264. var _removeEmpty = function (a) {
  1265. var out = [];
  1266. for (var i = 0, ien = a.length; i < ien; i++) {
  1267. if (a[i]) { // careful - will remove all falsy values!
  1268. out.push(a[i]);
  1269. }
  1270. }
  1271. return out;
  1272. };
  1273. var _stripHtml = function (d) {
  1274. return d.replace(_re_html, '');
  1275. };
  1276. /**
  1277. * Determine if all values in the array are unique. This means we can short
  1278. * cut the _unique method at the cost of a single loop. A sorted array is used
  1279. * to easily check the values.
  1280. *
  1281. * @param {array} src Source array
  1282. * @return {boolean} true if all unique, false otherwise
  1283. * @ignore
  1284. */
  1285. var _areAllUnique = function (src) {
  1286. if (src.length < 2) {
  1287. return true;
  1288. }
  1289. var sorted = src.slice().sort();
  1290. var last = sorted[0];
  1291. for (var i = 1, ien = sorted.length; i < ien; i++) {
  1292. if (sorted[i] === last) {
  1293. return false;
  1294. }
  1295. last = sorted[i];
  1296. }
  1297. return true;
  1298. };
  1299. /**
  1300. * Find the unique elements in a source array.
  1301. *
  1302. * @param {array} src Source array
  1303. * @return {array} Array of unique items
  1304. * @ignore
  1305. */
  1306. var _unique = function (src) {
  1307. if (_areAllUnique(src)) {
  1308. return src.slice();
  1309. }
  1310. // A faster unique method is to use object keys to identify used values,
  1311. // but this doesn't work with arrays or objects, which we must also
  1312. // consider. See jsperf.com/compare-array-unique-versions/4 for more
  1313. // information.
  1314. var
  1315. out = [],
  1316. val,
  1317. i, ien = src.length,
  1318. j, k = 0;
  1319. again: for (i = 0; i < ien; i++) {
  1320. val = src[i];
  1321. for (j = 0; j < k; j++) {
  1322. if (out[j] === val) {
  1323. continue again;
  1324. }
  1325. }
  1326. out.push(val);
  1327. k++;
  1328. }
  1329. return out;
  1330. };
  1331. // Surprisingly this is faster than [].concat.apply
  1332. // https://jsperf.com/flatten-an-array-loop-vs-reduce/2
  1333. var _flatten = function (out, val) {
  1334. if (Array.isArray(val)) {
  1335. for (var i = 0; i < val.length; i++) {
  1336. _flatten(out, val[i]);
  1337. }
  1338. } else {
  1339. out.push(val);
  1340. }
  1341. return out;
  1342. }
  1343. // Array.isArray polyfill.
  1344. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray
  1345. if (!Array.isArray) {
  1346. Array.isArray = function (arg) {
  1347. return Object.prototype.toString.call(arg) === '[object Array]';
  1348. };
  1349. }
  1350. // .trim() polyfill
  1351. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim
  1352. if (!String.prototype.trim) {
  1353. String.prototype.trim = function () {
  1354. return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
  1355. };
  1356. }
  1357. /**
  1358. * DataTables utility methods
  1359. *
  1360. * This namespace provides helper methods that DataTables uses internally to
  1361. * create a DataTable, but which are not exclusively used only for DataTables.
  1362. * These methods can be used by extension authors to save the duplication of
  1363. * code.
  1364. *
  1365. * @namespace
  1366. */
  1367. DataTable.util = {
  1368. /**
  1369. * Throttle the calls to a function. Arguments and context are maintained
  1370. * for the throttled function.
  1371. *
  1372. * @param {function} fn Function to be called
  1373. * @param {integer} freq Call frequency in mS
  1374. * @return {function} Wrapped function
  1375. */
  1376. throttle: function (fn, freq) {
  1377. var
  1378. frequency = freq !== undefined ? freq : 200,
  1379. last,
  1380. timer;
  1381. return function () {
  1382. var
  1383. that = this,
  1384. now = +new Date(),
  1385. args = arguments;
  1386. if (last && now < last + frequency) {
  1387. clearTimeout(timer);
  1388. timer = setTimeout(function () {
  1389. last = undefined;
  1390. fn.apply(that, args);
  1391. }, frequency);
  1392. } else {
  1393. last = now;
  1394. fn.apply(that, args);
  1395. }
  1396. };
  1397. },
  1398. /**
  1399. * Escape a string such that it can be used in a regular expression
  1400. *
  1401. * @param {string} val string to escape
  1402. * @returns {string} escaped string
  1403. */
  1404. escapeRegex: function (val) {
  1405. return val.replace(_re_escape_regex, '\\$1');
  1406. }
  1407. };
  1408. /**
  1409. * Create a mapping object that allows camel case parameters to be looked up
  1410. * for their Hungarian counterparts. The mapping is stored in a private
  1411. * parameter called `_hungarianMap` which can be accessed on the source object.
  1412. * @param {object} o
  1413. * @memberof DataTable#oApi
  1414. */
  1415. function _fnHungarianMap(o) {
  1416. var
  1417. hungarian = 'a aa ai ao as b fn i m o s ',
  1418. match,
  1419. newKey,
  1420. map = {};
  1421. $.each(o, function (key, val) {
  1422. match = key.match(/^([^A-Z]+?)([A-Z])/);
  1423. if (match && hungarian.indexOf(match[1] + ' ') !== -1) {
  1424. newKey = key.replace(match[0], match[2].toLowerCase());
  1425. map[newKey] = key;
  1426. if (match[1] === 'o') {
  1427. _fnHungarianMap(o[key]);
  1428. }
  1429. }
  1430. });
  1431. o._hungarianMap = map;
  1432. }
  1433. /**
  1434. * Convert from camel case parameters to Hungarian, based on a Hungarian map
  1435. * created by _fnHungarianMap.
  1436. * @param {object} src The model object which holds all parameters that can be
  1437. * mapped.
  1438. * @param {object} user The object to convert from camel case to Hungarian.
  1439. * @param {boolean} force When set to `true`, properties which already have a
  1440. * Hungarian value in the `user` object will be overwritten. Otherwise they
  1441. * won't be.
  1442. * @memberof DataTable#oApi
  1443. */
  1444. function _fnCamelToHungarian(src, user, force) {
  1445. if (!src._hungarianMap) {
  1446. _fnHungarianMap(src);
  1447. }
  1448. var hungarianKey;
  1449. $.each(user, function (key, val) {
  1450. hungarianKey = src._hungarianMap[key];
  1451. if (hungarianKey !== undefined && (force || user[hungarianKey] === undefined)) {
  1452. // For objects, we need to buzz down into the object to copy parameters
  1453. if (hungarianKey.charAt(0) === 'o') {
  1454. // Copy the camelCase options over to the hungarian
  1455. if (!user[hungarianKey]) {
  1456. user[hungarianKey] = {};
  1457. }
  1458. $.extend(true, user[hungarianKey], user[key]);
  1459. _fnCamelToHungarian(src[hungarianKey], user[hungarianKey], force);
  1460. } else {
  1461. user[hungarianKey] = user[key];
  1462. }
  1463. }
  1464. });
  1465. }
  1466. /**
  1467. * Language compatibility - when certain options are given, and others aren't, we
  1468. * need to duplicate the values over, in order to provide backwards compatibility
  1469. * with older language files.
  1470. * @param {object} oSettings dataTables settings object
  1471. * @memberof DataTable#oApi
  1472. */
  1473. function _fnLanguageCompat(lang) {
  1474. // Note the use of the Hungarian notation for the parameters in this method as
  1475. // this is called after the mapping of camelCase to Hungarian
  1476. var defaults = DataTable.defaults.oLanguage;
  1477. // Default mapping
  1478. var defaultDecimal = defaults.sDecimal;
  1479. if (defaultDecimal) {
  1480. _addNumericSort(defaultDecimal);
  1481. }
  1482. if (lang) {
  1483. var zeroRecords = lang.sZeroRecords;
  1484. // Backwards compatibility - if there is no sEmptyTable given, then use the same as
  1485. // sZeroRecords - assuming that is given.
  1486. if (!lang.sEmptyTable && zeroRecords &&
  1487. defaults.sEmptyTable === "No data available in table") {
  1488. _fnMap(lang, lang, 'sZeroRecords', 'sEmptyTable');
  1489. }
  1490. // Likewise with loading records
  1491. if (!lang.sLoadingRecords && zeroRecords &&
  1492. defaults.sLoadingRecords === "Loading...") {
  1493. _fnMap(lang, lang, 'sZeroRecords', 'sLoadingRecords');
  1494. }
  1495. // Old parameter name of the thousands separator mapped onto the new
  1496. if (lang.sInfoThousands) {
  1497. lang.sThousands = lang.sInfoThousands;
  1498. }
  1499. var decimal = lang.sDecimal;
  1500. if (decimal && defaultDecimal !== decimal) {
  1501. _addNumericSort(decimal);
  1502. }
  1503. }
  1504. }
  1505. /**
  1506. * Map one parameter onto another
  1507. * @param {object} o Object to map
  1508. * @param {*} knew The new parameter name
  1509. * @param {*} old The old parameter name
  1510. */
  1511. var _fnCompatMap = function (o, knew, old) {
  1512. if (o[knew] !== undefined) {
  1513. o[old] = o[knew];
  1514. }
  1515. };
  1516. /**
  1517. * Provide backwards compatibility for the main DT options. Note that the new
  1518. * options are mapped onto the old parameters, so this is an external interface
  1519. * change only.
  1520. * @param {object} init Object to map
  1521. */
  1522. function _fnCompatOpts(init) {
  1523. _fnCompatMap(init, 'ordering', 'bSort');
  1524. _fnCompatMap(init, 'orderMulti', 'bSortMulti');
  1525. _fnCompatMap(init, 'orderClasses', 'bSortClasses');
  1526. _fnCompatMap(init, 'orderCellsTop', 'bSortCellsTop');
  1527. _fnCompatMap(init, 'order', 'aaSorting');
  1528. _fnCompatMap(init, 'orderFixed', 'aaSortingFixed');
  1529. _fnCompatMap(init, 'paging', 'bPaginate');
  1530. _fnCompatMap(init, 'pagingType', 'sPaginationType');
  1531. _fnCompatMap(init, 'pageLength', 'iDisplayLength');
  1532. _fnCompatMap(init, 'searching', 'bFilter');
  1533. // Boolean initialisation of x-scrolling
  1534. if (typeof init.sScrollX === 'boolean') {
  1535. init.sScrollX = init.sScrollX ? '100%' : '';
  1536. }
  1537. if (typeof init.scrollX === 'boolean') {
  1538. init.scrollX = init.scrollX ? '100%' : '';
  1539. }
  1540. // Column search objects are in an array, so it needs to be converted
  1541. // element by element
  1542. var searchCols = init.aoSearchCols;
  1543. if (searchCols) {
  1544. for (var i = 0, ien = searchCols.length; i < ien; i++) {
  1545. if (searchCols[i]) {
  1546. _fnCamelToHungarian(DataTable.models.oSearch, searchCols[i]);
  1547. }
  1548. }
  1549. }
  1550. }
  1551. /**
  1552. * Provide backwards compatibility for column options. Note that the new options
  1553. * are mapped onto the old parameters, so this is an external interface change
  1554. * only.
  1555. * @param {object} init Object to map
  1556. */
  1557. function _fnCompatCols(init) {
  1558. _fnCompatMap(init, 'orderable', 'bSortable');
  1559. _fnCompatMap(init, 'orderData', 'aDataSort');
  1560. _fnCompatMap(init, 'orderSequence', 'asSorting');
  1561. _fnCompatMap(init, 'orderDataType', 'sortDataType');
  1562. // orderData can be given as an integer
  1563. var dataSort = init.aDataSort;
  1564. if (typeof dataSort === 'number' && !Array.isArray(dataSort)) {
  1565. init.aDataSort = [dataSort];
  1566. }
  1567. }
  1568. /**
  1569. * Browser feature detection for capabilities, quirks
  1570. * @param {object} settings dataTables settings object
  1571. * @memberof DataTable#oApi
  1572. */
  1573. function _fnBrowserDetect(settings) {
  1574. // We don't need to do this every time DataTables is constructed, the values
  1575. // calculated are specific to the browser and OS configuration which we
  1576. // don't expect to change between initialisations
  1577. if (!DataTable.__browser) {
  1578. var browser = {};
  1579. DataTable.__browser = browser;
  1580. // Scrolling feature / quirks detection
  1581. var n = $('<div/>')
  1582. .css({
  1583. position: 'fixed',
  1584. top: 0,
  1585. left: $(window).scrollLeft() * -1, // allow for scrolling
  1586. height: 1,
  1587. width: 1,
  1588. overflow: 'hidden'
  1589. })
  1590. .append(
  1591. $('<div/>')
  1592. .css({
  1593. position: 'absolute',
  1594. top: 1,
  1595. left: 1,
  1596. width: 100,
  1597. overflow: 'scroll'
  1598. })
  1599. .append(
  1600. $('<div/>')
  1601. .css({
  1602. width: '100%',
  1603. height: 10
  1604. })
  1605. )
  1606. )
  1607. .appendTo('body');
  1608. var outer = n.children();
  1609. var inner = outer.children();
  1610. // Numbers below, in order, are:
  1611. // inner.offsetWidth, inner.clientWidth, outer.offsetWidth, outer.clientWidth
  1612. //
  1613. // IE6 XP: 100 100 100 83
  1614. // IE7 Vista: 100 100 100 83
  1615. // IE 8+ Windows: 83 83 100 83
  1616. // Evergreen Windows: 83 83 100 83
  1617. // Evergreen Mac with scrollbars: 85 85 100 85
  1618. // Evergreen Mac without scrollbars: 100 100 100 100
  1619. // Get scrollbar width
  1620. browser.barWidth = outer[0].offsetWidth - outer[0].clientWidth;
  1621. // IE6/7 will oversize a width 100% element inside a scrolling element, to
  1622. // include the width of the scrollbar, while other browsers ensure the inner
  1623. // element is contained without forcing scrolling
  1624. browser.bScrollOversize = inner[0].offsetWidth === 100 && outer[0].clientWidth !== 100;
  1625. // In rtl text layout, some browsers (most, but not all) will place the
  1626. // scrollbar on the left, rather than the right.
  1627. browser.bScrollbarLeft = Math.round(inner.offset().left) !== 1;
  1628. // IE8- don't provide height and width for getBoundingClientRect
  1629. browser.bBounding = n[0].getBoundingClientRect().width ? true : false;
  1630. n.remove();
  1631. }
  1632. $.extend(settings.oBrowser, DataTable.__browser);
  1633. settings.oScroll.iBarWidth = DataTable.__browser.barWidth;
  1634. }
  1635. /**
  1636. * Array.prototype reduce[Right] method, used for browsers which don't support
  1637. * JS 1.6. Done this way to reduce code size, since we iterate either way
  1638. * @param {object} settings dataTables settings object
  1639. * @memberof DataTable#oApi
  1640. */
  1641. function _fnReduce(that, fn, init, start, end, inc) {
  1642. var
  1643. i = start,
  1644. value,
  1645. isSet = false;
  1646. if (init !== undefined) {
  1647. value = init;
  1648. isSet = true;
  1649. }
  1650. while (i !== end) {
  1651. if (!that.hasOwnProperty(i)) {
  1652. continue;
  1653. }
  1654. value = isSet ?
  1655. fn(value, that[i], i, that) :
  1656. that[i];
  1657. isSet = true;
  1658. i += inc;
  1659. }
  1660. return value;
  1661. }
  1662. /**
  1663. * Add a column to the list used for the table with default values
  1664. * @param {object} oSettings dataTables settings object
  1665. * @param {node} nTh The th element for this column
  1666. * @memberof DataTable#oApi
  1667. */
  1668. function _fnAddColumn(oSettings, nTh) {
  1669. // Add column to aoColumns array
  1670. var oDefaults = DataTable.defaults.column;
  1671. var iCol = oSettings.aoColumns.length;
  1672. var oCol = $.extend({}, DataTable.models.oColumn, oDefaults, {
  1673. "nTh": nTh ? nTh : document.createElement('th'),
  1674. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  1675. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  1676. "mData": oDefaults.mData ? oDefaults.mData : iCol,
  1677. idx: iCol
  1678. });
  1679. oSettings.aoColumns.push(oCol);
  1680. // Add search object for column specific search. Note that the `searchCols[ iCol ]`
  1681. // passed into extend can be undefined. This allows the user to give a default
  1682. // with only some of the parameters defined, and also not give a default
  1683. var searchCols = oSettings.aoPreSearchCols;
  1684. searchCols[iCol] = $.extend({}, DataTable.models.oSearch, searchCols[iCol]);
  1685. // Use the default column options function to initialise classes etc
  1686. _fnColumnOptions(oSettings, iCol, $(nTh).data());
  1687. }
  1688. /**
  1689. * Apply options for a column
  1690. * @param {object} oSettings dataTables settings object
  1691. * @param {int} iCol column index to consider
  1692. * @param {object} oOptions object with sType, bVisible and bSearchable etc
  1693. * @memberof DataTable#oApi
  1694. */
  1695. function _fnColumnOptions(oSettings, iCol, oOptions) {
  1696. var oCol = oSettings.aoColumns[iCol];
  1697. var oClasses = oSettings.oClasses;
  1698. var th = $(oCol.nTh);
  1699. // Try to get width information from the DOM. We can't get it from CSS
  1700. // as we'd need to parse the CSS stylesheet. `width` option can override
  1701. if (!oCol.sWidthOrig) {
  1702. // Width attribute
  1703. oCol.sWidthOrig = th.attr('width') || null;
  1704. // Style attribute
  1705. var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
  1706. if (t) {
  1707. oCol.sWidthOrig = t[1];
  1708. }
  1709. }
  1710. /* User specified column options */
  1711. if (oOptions !== undefined && oOptions !== null) {
  1712. // Backwards compatibility
  1713. _fnCompatCols(oOptions);
  1714. // Map camel case parameters to their Hungarian counterparts
  1715. _fnCamelToHungarian(DataTable.defaults.column, oOptions, true);
  1716. /* Backwards compatibility for mDataProp */
  1717. if (oOptions.mDataProp !== undefined && !oOptions.mData) {
  1718. oOptions.mData = oOptions.mDataProp;
  1719. }
  1720. if (oOptions.sType) {
  1721. oCol._sManualType = oOptions.sType;
  1722. }
  1723. // `class` is a reserved word in Javascript, so we need to provide
  1724. // the ability to use a valid name for the camel case input
  1725. if (oOptions.className && !oOptions.sClass) {
  1726. oOptions.sClass = oOptions.className;
  1727. }
  1728. if (oOptions.sClass) {
  1729. th.addClass(oOptions.sClass);
  1730. }
  1731. $.extend(oCol, oOptions);
  1732. _fnMap(oCol, oOptions, "sWidth", "sWidthOrig");
  1733. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  1734. * priority if defined
  1735. */
  1736. if (oOptions.iDataSort !== undefined) {
  1737. oCol.aDataSort = [oOptions.iDataSort];
  1738. }
  1739. _fnMap(oCol, oOptions, "aDataSort");
  1740. }
  1741. /* Cache the data get and set functions for speed */
  1742. var mDataSrc = oCol.mData;
  1743. var mData = _fnGetObjectDataFn(mDataSrc);
  1744. var mRender = oCol.mRender ? _fnGetObjectDataFn(oCol.mRender) : null;
  1745. var attrTest = function (src) {
  1746. return typeof src === 'string' && src.indexOf('@') !== -1;
  1747. };
  1748. oCol._bAttrSrc = $.isPlainObject(mDataSrc) && (
  1749. attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter)
  1750. );
  1751. oCol._setter = null;
  1752. oCol.fnGetData = function (rowData, type, meta) {
  1753. var innerData = mData(rowData, type, undefined, meta);
  1754. return mRender && type ?
  1755. mRender(innerData, type, rowData, meta) :
  1756. innerData;
  1757. };
  1758. oCol.fnSetData = function (rowData, val, meta) {
  1759. return _fnSetObjectDataFn(mDataSrc)(rowData, val, meta);
  1760. };
  1761. // Indicate if DataTables should read DOM data as an object or array
  1762. // Used in _fnGetRowElements
  1763. if (typeof mDataSrc !== 'number') {
  1764. oSettings._rowReadObject = true;
  1765. }
  1766. /* Feature sorting overrides column specific when off */
  1767. if (!oSettings.oFeatures.bSort) {
  1768. oCol.bSortable = false;
  1769. th.addClass(oClasses.sSortableNone); // Have to add class here as order event isn't called
  1770. }
  1771. /* Check that the class assignment is correct for sorting */
  1772. var bAsc = $.inArray('asc', oCol.asSorting) !== -1;
  1773. var bDesc = $.inArray('desc', oCol.asSorting) !== -1;
  1774. if (!oCol.bSortable || (!bAsc && !bDesc)) {
  1775. oCol.sSortingClass = oClasses.sSortableNone;
  1776. oCol.sSortingClassJUI = "";
  1777. } else if (bAsc && !bDesc) {
  1778. oCol.sSortingClass = oClasses.sSortableAsc;
  1779. oCol.sSortingClassJUI = oClasses.sSortJUIAscAllowed;
  1780. } else if (!bAsc && bDesc) {
  1781. oCol.sSortingClass = oClasses.sSortableDesc;
  1782. oCol.sSortingClassJUI = oClasses.sSortJUIDescAllowed;
  1783. } else {
  1784. oCol.sSortingClass = oClasses.sSortable;
  1785. oCol.sSortingClassJUI = oClasses.sSortJUI;
  1786. }
  1787. }
  1788. /**
  1789. * Adjust the table column widths for new data. Note: you would probably want to
  1790. * do a redraw after calling this function!
  1791. * @param {object} settings dataTables settings object
  1792. * @memberof DataTable#oApi
  1793. */
  1794. function _fnAdjustColumnSizing(settings) {
  1795. /* Not interested in doing column width calculation if auto-width is disabled */
  1796. if (settings.oFeatures.bAutoWidth !== false) {
  1797. var columns = settings.aoColumns;
  1798. _fnCalculateColumnWidths(settings);
  1799. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  1800. columns[i].nTh.style.width = columns[i].sWidth;
  1801. }
  1802. }
  1803. var scroll = settings.oScroll;
  1804. if (scroll.sY !== '' || scroll.sX !== '') {
  1805. _fnScrollDraw(settings);
  1806. }
  1807. _fnCallbackFire(settings, null, 'column-sizing', [settings]);
  1808. }
  1809. /**
  1810. * Covert the index of a visible column to the index in the data array (take account
  1811. * of hidden columns)
  1812. * @param {object} oSettings dataTables settings object
  1813. * @param {int} iMatch Visible column index to lookup
  1814. * @returns {int} i the data index
  1815. * @memberof DataTable#oApi
  1816. */
  1817. function _fnVisibleToColumnIndex(oSettings, iMatch) {
  1818. var aiVis = _fnGetColumns(oSettings, 'bVisible');
  1819. return typeof aiVis[iMatch] === 'number' ?
  1820. aiVis[iMatch] :
  1821. null;
  1822. }
  1823. /**
  1824. * Covert the index of an index in the data array and convert it to the visible
  1825. * column index (take account of hidden columns)
  1826. * @param {int} iMatch Column index to lookup
  1827. * @param {object} oSettings dataTables settings object
  1828. * @returns {int} i the data index
  1829. * @memberof DataTable#oApi
  1830. */
  1831. function _fnColumnIndexToVisible(oSettings, iMatch) {
  1832. var aiVis = _fnGetColumns(oSettings, 'bVisible');
  1833. var iPos = $.inArray(iMatch, aiVis);
  1834. return iPos !== -1 ? iPos : null;
  1835. }
  1836. /**
  1837. * Get the number of visible columns
  1838. * @param {object} oSettings dataTables settings object
  1839. * @returns {int} i the number of visible columns
  1840. * @memberof DataTable#oApi
  1841. */
  1842. function _fnVisbleColumns(oSettings) {
  1843. var vis = 0;
  1844. // No reduce in IE8, use a loop for now
  1845. $.each(oSettings.aoColumns, function (i, col) {
  1846. if (col.bVisible && $(col.nTh).css('display') !== 'none') {
  1847. vis++;
  1848. }
  1849. });
  1850. return vis;
  1851. }
  1852. /**
  1853. * Get an array of column indexes that match a given property
  1854. * @param {object} oSettings dataTables settings object
  1855. * @param {string} sParam Parameter in aoColumns to look for - typically
  1856. * bVisible or bSearchable
  1857. * @returns {array} Array of indexes with matched properties
  1858. * @memberof DataTable#oApi
  1859. */
  1860. function _fnGetColumns(oSettings, sParam) {
  1861. var a = [];
  1862. $.map(oSettings.aoColumns, function (val, i) {
  1863. if (val[sParam]) {
  1864. a.push(i);
  1865. }
  1866. });
  1867. return a;
  1868. }
  1869. /**
  1870. * Calculate the 'type' of a column
  1871. * @param {object} settings dataTables settings object
  1872. * @memberof DataTable#oApi
  1873. */
  1874. function _fnColumnTypes(settings) {
  1875. var columns = settings.aoColumns;
  1876. var data = settings.aoData;
  1877. var types = DataTable.ext.type.detect;
  1878. var i, ien, j, jen, k, ken;
  1879. var col, cell, detectedType, cache;
  1880. // For each column, spin over the
  1881. for (i = 0, ien = columns.length; i < ien; i++) {
  1882. col = columns[i];
  1883. cache = [];
  1884. if (!col.sType && col._sManualType) {
  1885. col.sType = col._sManualType;
  1886. } else if (!col.sType) {
  1887. for (j = 0, jen = types.length; j < jen; j++) {
  1888. for (k = 0, ken = data.length; k < ken; k++) {
  1889. // Use a cache array so we only need to get the type data
  1890. // from the formatter once (when using multiple detectors)
  1891. if (cache[k] === undefined) {
  1892. cache[k] = _fnGetCellData(settings, k, i, 'type');
  1893. }
  1894. detectedType = types[j](cache[k], settings);
  1895. // If null, then this type can't apply to this column, so
  1896. // rather than testing all cells, break out. There is an
  1897. // exception for the last type which is `html`. We need to
  1898. // scan all rows since it is possible to mix string and HTML
  1899. // types
  1900. if (!detectedType && j !== types.length - 1) {
  1901. break;
  1902. }
  1903. // Only a single match is needed for html type since it is
  1904. // bottom of the pile and very similar to string
  1905. if (detectedType === 'html') {
  1906. break;
  1907. }
  1908. }
  1909. // Type is valid for all data points in the column - use this
  1910. // type
  1911. if (detectedType) {
  1912. col.sType = detectedType;
  1913. break;
  1914. }
  1915. }
  1916. // Fall back - if no type was detected, always use string
  1917. if (!col.sType) {
  1918. col.sType = 'string';
  1919. }
  1920. }
  1921. }
  1922. }
  1923. /**
  1924. * Take the column definitions and static columns arrays and calculate how
  1925. * they relate to column indexes. The callback function will then apply the
  1926. * definition found for a column to a suitable configuration object.
  1927. * @param {object} oSettings dataTables settings object
  1928. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  1929. * @param {array} aoCols The aoColumns array that defines columns individually
  1930. * @param {function} fn Callback function - takes two parameters, the calculated
  1931. * column index and the definition for that column.
  1932. * @memberof DataTable#oApi
  1933. */
  1934. function _fnApplyColumnDefs(oSettings, aoColDefs, aoCols, fn) {
  1935. var i, iLen, j, jLen, k, kLen, def;
  1936. var columns = oSettings.aoColumns;
  1937. // Column definitions with aTargets
  1938. if (aoColDefs) {
  1939. /* Loop over the definitions array - loop in reverse so first instance has priority */
  1940. for (i = aoColDefs.length - 1; i >= 0; i--) {
  1941. def = aoColDefs[i];
  1942. /* Each definition can target multiple columns, as it is an array */
  1943. var aTargets = def.targets !== undefined ?
  1944. def.targets :
  1945. def.aTargets;
  1946. if (!Array.isArray(aTargets)) {
  1947. aTargets = [aTargets];
  1948. }
  1949. for (j = 0, jLen = aTargets.length; j < jLen; j++) {
  1950. if (typeof aTargets[j] === 'number' && aTargets[j] >= 0) {
  1951. /* Add columns that we don't yet know about */
  1952. while (columns.length <= aTargets[j]) {
  1953. _fnAddColumn(oSettings);
  1954. }
  1955. /* Integer, basic index */
  1956. fn(aTargets[j], def);
  1957. } else if (typeof aTargets[j] === 'number' && aTargets[j] < 0) {
  1958. /* Negative integer, right to left column counting */
  1959. fn(columns.length + aTargets[j], def);
  1960. } else if (typeof aTargets[j] === 'string') {
  1961. /* Class name matching on TH element */
  1962. for (k = 0, kLen = columns.length; k < kLen; k++) {
  1963. if (aTargets[j] == "_all" ||
  1964. $(columns[k].nTh).hasClass(aTargets[j])) {
  1965. fn(k, def);
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. }
  1972. // Statically defined columns array
  1973. if (aoCols) {
  1974. for (i = 0, iLen = aoCols.length; i < iLen; i++) {
  1975. fn(i, aoCols[i]);
  1976. }
  1977. }
  1978. }
  1979. /**
  1980. * Add a data array to the table, creating DOM node etc. This is the parallel to
  1981. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  1982. * DOM source.
  1983. * @param {object} oSettings dataTables settings object
  1984. * @param {array} aData data array to be added
  1985. * @param {node} [nTr] TR element to add to the table - optional. If not given,
  1986. * DataTables will create a row automatically
  1987. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  1988. * if nTr is.
  1989. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  1990. * @memberof DataTable#oApi
  1991. */
  1992. function _fnAddData(oSettings, aDataIn, nTr, anTds) {
  1993. /* Create the object for storing information about this new row */
  1994. var iRow = oSettings.aoData.length;
  1995. var oData = $.extend(true, {}, DataTable.models.oRow, {
  1996. src: nTr ? 'dom' : 'data',
  1997. idx: iRow
  1998. });
  1999. oData._aData = aDataIn;
  2000. oSettings.aoData.push(oData);
  2001. /* Create the cells */
  2002. var nTd, sThisType;
  2003. var columns = oSettings.aoColumns;
  2004. // Invalidate the column types as the new data needs to be revalidated
  2005. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  2006. columns[i].sType = null;
  2007. }
  2008. /* Add to the display array */
  2009. oSettings.aiDisplayMaster.push(iRow);
  2010. var id = oSettings.rowIdFn(aDataIn);
  2011. if (id !== undefined) {
  2012. oSettings.aIds[id] = oData;
  2013. }
  2014. /* Create the DOM information, or register it if already present */
  2015. if (nTr || !oSettings.oFeatures.bDeferRender) {
  2016. _fnCreateTr(oSettings, iRow, nTr, anTds);
  2017. }
  2018. return iRow;
  2019. }
  2020. /**
  2021. * Add one or more TR elements to the table. Generally we'd expect to
  2022. * use this for reading data from a DOM sourced table, but it could be
  2023. * used for an TR element. Note that if a TR is given, it is used (i.e.
  2024. * it is not cloned).
  2025. * @param {object} settings dataTables settings object
  2026. * @param {array|node|jQuery} trs The TR element(s) to add to the table
  2027. * @returns {array} Array of indexes for the added rows
  2028. * @memberof DataTable#oApi
  2029. */
  2030. function _fnAddTr(settings, trs) {
  2031. var row;
  2032. // Allow an individual node to be passed in
  2033. if (!(trs instanceof $)) {
  2034. trs = $(trs);
  2035. }
  2036. return trs.map(function (i, el) {
  2037. row = _fnGetRowElements(settings, el);
  2038. return _fnAddData(settings, row.data, el, row.cells);
  2039. });
  2040. }
  2041. /**
  2042. * Take a TR element and convert it to an index in aoData
  2043. * @param {object} oSettings dataTables settings object
  2044. * @param {node} n the TR element to find
  2045. * @returns {int} index if the node is found, null if not
  2046. * @memberof DataTable#oApi
  2047. */
  2048. function _fnNodeToDataIndex(oSettings, n) {
  2049. return (n._DT_RowIndex !== undefined) ? n._DT_RowIndex : null;
  2050. }
  2051. /**
  2052. * Take a TD element and convert it into a column data index (not the visible index)
  2053. * @param {object} oSettings dataTables settings object
  2054. * @param {int} iRow The row number the TD/TH can be found in
  2055. * @param {node} n The TD/TH element to find
  2056. * @returns {int} index if the node is found, -1 if not
  2057. * @memberof DataTable#oApi
  2058. */
  2059. function _fnNodeToColumnIndex(oSettings, iRow, n) {
  2060. return $.inArray(n, oSettings.aoData[iRow].anCells);
  2061. }
  2062. /**
  2063. * Get the data for a given cell from the internal cache, taking into account data mapping
  2064. * @param {object} settings dataTables settings object
  2065. * @param {int} rowIdx aoData row id
  2066. * @param {int} colIdx Column index
  2067. * @param {string} type data get type ('display', 'type' 'filter' 'sort')
  2068. * @returns {*} Cell data
  2069. * @memberof DataTable#oApi
  2070. */
  2071. function _fnGetCellData(settings, rowIdx, colIdx, type) {
  2072. var draw = settings.iDraw;
  2073. var col = settings.aoColumns[colIdx];
  2074. var rowData = settings.aoData[rowIdx]._aData;
  2075. var defaultContent = col.sDefaultContent;
  2076. var cellData = col.fnGetData(rowData, type, {
  2077. settings: settings,
  2078. row: rowIdx,
  2079. col: colIdx
  2080. });
  2081. if (cellData === undefined) {
  2082. if (settings.iDrawError != draw && defaultContent === null) {
  2083. _fnLog(settings, 0, "Requested unknown parameter " +
  2084. (typeof col.mData == 'function' ? '{function}' : "'" + col.mData + "'") +
  2085. " for row " + rowIdx + ", column " + colIdx, 4);
  2086. settings.iDrawError = draw;
  2087. }
  2088. return defaultContent;
  2089. }
  2090. // When the data source is null and a specific data type is requested (i.e.
  2091. // not the original data), we can use default column data
  2092. if ((cellData === rowData || cellData === null) && defaultContent !== null && type !== undefined) {
  2093. cellData = defaultContent;
  2094. } else if (typeof cellData === 'function') {
  2095. // If the data source is a function, then we run it and use the return,
  2096. // executing in the scope of the data object (for instances)
  2097. return cellData.call(rowData);
  2098. }
  2099. if (cellData === null && type == 'display') {
  2100. return '';
  2101. }
  2102. return cellData;
  2103. }
  2104. /**
  2105. * Set the value for a specific cell, into the internal data cache
  2106. * @param {object} settings dataTables settings object
  2107. * @param {int} rowIdx aoData row id
  2108. * @param {int} colIdx Column index
  2109. * @param {*} val Value to set
  2110. * @memberof DataTable#oApi
  2111. */
  2112. function _fnSetCellData(settings, rowIdx, colIdx, val) {
  2113. var col = settings.aoColumns[colIdx];
  2114. var rowData = settings.aoData[rowIdx]._aData;
  2115. col.fnSetData(rowData, val, {
  2116. settings: settings,
  2117. row: rowIdx,
  2118. col: colIdx
  2119. });
  2120. }
  2121. // Private variable that is used to match action syntax in the data property object
  2122. var __reArray = /\[.*?\]$/;
  2123. var __reFn = /\(\)$/;
  2124. /**
  2125. * Split string on periods, taking into account escaped periods
  2126. * @param {string} str String to split
  2127. * @return {array} Split string
  2128. */
  2129. function _fnSplitObjNotation(str) {
  2130. return $.map(str.match(/(\\.|[^\.])+/g) || [''], function (s) {
  2131. return s.replace(/\\\./g, '.');
  2132. });
  2133. }
  2134. /**
  2135. * Return a function that can be used to get data from a source object, taking
  2136. * into account the ability to use nested objects as a source
  2137. * @param {string|int|function} mSource The data source for the object
  2138. * @returns {function} Data get function
  2139. * @memberof DataTable#oApi
  2140. */
  2141. function _fnGetObjectDataFn(mSource) {
  2142. if ($.isPlainObject(mSource)) {
  2143. /* Build an object of get functions, and wrap them in a single call */
  2144. var o = {};
  2145. $.each(mSource, function (key, val) {
  2146. if (val) {
  2147. o[key] = _fnGetObjectDataFn(val);
  2148. }
  2149. });
  2150. return function (data, type, row, meta) {
  2151. var t = o[type] || o._;
  2152. return t !== undefined ?
  2153. t(data, type, row, meta) :
  2154. data;
  2155. };
  2156. } else if (mSource === null) {
  2157. /* Give an empty string for rendering / sorting etc */
  2158. return function (data) { // type, row and meta also passed, but not used
  2159. return data;
  2160. };
  2161. } else if (typeof mSource === 'function') {
  2162. return function (data, type, row, meta) {
  2163. return mSource(data, type, row, meta);
  2164. };
  2165. } else if (typeof mSource === 'string' && (mSource.indexOf('.') !== -1 ||
  2166. mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1)) {
  2167. /* If there is a . in the source string then the data source is in a
  2168. * nested object so we loop over the data for each level to get the next
  2169. * level down. On each loop we test for undefined, and if found immediately
  2170. * return. This allows entire objects to be missing and sDefaultContent to
  2171. * be used if defined, rather than throwing an error
  2172. */
  2173. var fetchData = function (data, type, src) {
  2174. var arrayNotation, funcNotation, out, innerSrc;
  2175. if (src !== "") {
  2176. var a = _fnSplitObjNotation(src);
  2177. for (var i = 0, iLen = a.length; i < iLen; i++) {
  2178. // Check if we are dealing with special notation
  2179. arrayNotation = a[i].match(__reArray);
  2180. funcNotation = a[i].match(__reFn);
  2181. if (arrayNotation) {
  2182. // Array notation
  2183. a[i] = a[i].replace(__reArray, '');
  2184. // Condition allows simply [] to be passed in
  2185. if (a[i] !== "") {
  2186. data = data[a[i]];
  2187. }
  2188. out = [];
  2189. // Get the remainder of the nested object to get
  2190. a.splice(0, i + 1);
  2191. innerSrc = a.join('.');
  2192. // Traverse each entry in the array getting the properties requested
  2193. if (Array.isArray(data)) {
  2194. for (var j = 0, jLen = data.length; j < jLen; j++) {
  2195. out.push(fetchData(data[j], type, innerSrc));
  2196. }
  2197. }
  2198. // If a string is given in between the array notation indicators, that
  2199. // is used to join the strings together, otherwise an array is returned
  2200. var join = arrayNotation[0].substring(1, arrayNotation[0].length - 1);
  2201. data = (join === "") ? out : out.join(join);
  2202. // The inner call to fetchData has already traversed through the remainder
  2203. // of the source requested, so we exit from the loop
  2204. break;
  2205. } else if (funcNotation) {
  2206. // Function call
  2207. a[i] = a[i].replace(__reFn, '');
  2208. data = data[a[i]]();
  2209. continue;
  2210. }
  2211. if (data === null || data[a[i]] === undefined) {
  2212. return undefined;
  2213. }
  2214. data = data[a[i]];
  2215. }
  2216. }
  2217. return data;
  2218. };
  2219. return function (data, type) { // row and meta also passed, but not used
  2220. return fetchData(data, type, mSource);
  2221. };
  2222. } else {
  2223. /* Array or flat object mapping */
  2224. return function (data, type) { // row and meta also passed, but not used
  2225. return data[mSource];
  2226. };
  2227. }
  2228. }
  2229. /**
  2230. * Return a function that can be used to set data from a source object, taking
  2231. * into account the ability to use nested objects as a source
  2232. * @param {string|int|function} mSource The data source for the object
  2233. * @returns {function} Data set function
  2234. * @memberof DataTable#oApi
  2235. */
  2236. function _fnSetObjectDataFn(mSource) {
  2237. if ($.isPlainObject(mSource)) {
  2238. /* Unlike get, only the underscore (global) option is used for for
  2239. * setting data since we don't know the type here. This is why an object
  2240. * option is not documented for `mData` (which is read/write), but it is
  2241. * for `mRender` which is read only.
  2242. */
  2243. return _fnSetObjectDataFn(mSource._);
  2244. } else if (mSource === null) {
  2245. /* Nothing to do when the data source is null */
  2246. return function () {
  2247. };
  2248. } else if (typeof mSource === 'function') {
  2249. return function (data, val, meta) {
  2250. mSource(data, 'set', val, meta);
  2251. };
  2252. } else if (typeof mSource === 'string' && (mSource.indexOf('.') !== -1 ||
  2253. mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1)) {
  2254. /* Like the get, we need to get data from a nested object */
  2255. var setData = function (data, val, src) {
  2256. var a = _fnSplitObjNotation(src), b;
  2257. var aLast = a[a.length - 1];
  2258. var arrayNotation, funcNotation, o, innerSrc;
  2259. for (var i = 0, iLen = a.length - 1; i < iLen; i++) {
  2260. // Protect against prototype pollution
  2261. if (a[i] === '__proto__' || a[i] === 'constructor') {
  2262. throw new Error('Cannot set prototype values');
  2263. }
  2264. // Check if we are dealing with an array notation request
  2265. arrayNotation = a[i].match(__reArray);
  2266. funcNotation = a[i].match(__reFn);
  2267. if (arrayNotation) {
  2268. a[i] = a[i].replace(__reArray, '');
  2269. data[a[i]] = [];
  2270. // Get the remainder of the nested object to set so we can recurse
  2271. b = a.slice();
  2272. b.splice(0, i + 1);
  2273. innerSrc = b.join('.');
  2274. // Traverse each entry in the array setting the properties requested
  2275. if (Array.isArray(val)) {
  2276. for (var j = 0, jLen = val.length; j < jLen; j++) {
  2277. o = {};
  2278. setData(o, val[j], innerSrc);
  2279. data[a[i]].push(o);
  2280. }
  2281. } else {
  2282. // We've been asked to save data to an array, but it
  2283. // isn't array data to be saved. Best that can be done
  2284. // is to just save the value.
  2285. data[a[i]] = val;
  2286. }
  2287. // The inner call to setData has already traversed through the remainder
  2288. // of the source and has set the data, thus we can exit here
  2289. return;
  2290. } else if (funcNotation) {
  2291. // Function call
  2292. a[i] = a[i].replace(__reFn, '');
  2293. data = data[a[i]](val);
  2294. }
  2295. // If the nested object doesn't currently exist - since we are
  2296. // trying to set the value - create it
  2297. if (data[a[i]] === null || data[a[i]] === undefined) {
  2298. data[a[i]] = {};
  2299. }
  2300. data = data[a[i]];
  2301. }
  2302. // Last item in the input - i.e, the actual set
  2303. if (aLast.match(__reFn)) {
  2304. // Function call
  2305. data = data[aLast.replace(__reFn, '')](val);
  2306. } else {
  2307. // If array notation is used, we just want to strip it and use the property name
  2308. // and assign the value. If it isn't used, then we get the result we want anyway
  2309. data[aLast.replace(__reArray, '')] = val;
  2310. }
  2311. };
  2312. return function (data, val) { // meta is also passed in, but not used
  2313. return setData(data, val, mSource);
  2314. };
  2315. } else {
  2316. /* Array or flat object mapping */
  2317. return function (data, val) { // meta is also passed in, but not used
  2318. data[mSource] = val;
  2319. };
  2320. }
  2321. }
  2322. /**
  2323. * Return an array with the full table data
  2324. * @param {object} oSettings dataTables settings object
  2325. * @returns array {array} aData Master data array
  2326. * @memberof DataTable#oApi
  2327. */
  2328. function _fnGetDataMaster(settings) {
  2329. return _pluck(settings.aoData, '_aData');
  2330. }
  2331. /**
  2332. * Nuke the table
  2333. * @param {object} oSettings dataTables settings object
  2334. * @memberof DataTable#oApi
  2335. */
  2336. function _fnClearTable(settings) {
  2337. settings.aoData.length = 0;
  2338. settings.aiDisplayMaster.length = 0;
  2339. settings.aiDisplay.length = 0;
  2340. settings.aIds = {};
  2341. }
  2342. /**
  2343. * Take an array of integers (index array) and remove a target integer (value - not
  2344. * the key!)
  2345. * @param {array} a Index array to target
  2346. * @param {int} iTarget value to find
  2347. * @memberof DataTable#oApi
  2348. */
  2349. function _fnDeleteIndex(a, iTarget, splice) {
  2350. var iTargetIndex = -1;
  2351. for (var i = 0, iLen = a.length; i < iLen; i++) {
  2352. if (a[i] == iTarget) {
  2353. iTargetIndex = i;
  2354. } else if (a[i] > iTarget) {
  2355. a[i]--;
  2356. }
  2357. }
  2358. if (iTargetIndex != -1 && splice === undefined) {
  2359. a.splice(iTargetIndex, 1);
  2360. }
  2361. }
  2362. /**
  2363. * Mark cached data as invalid such that a re-read of the data will occur when
  2364. * the cached data is next requested. Also update from the data source object.
  2365. *
  2366. * @param {object} settings DataTables settings object
  2367. * @param {int} rowIdx Row index to invalidate
  2368. * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
  2369. * or 'data'
  2370. * @param {int} [colIdx] Column index to invalidate. If undefined the whole
  2371. * row will be invalidated
  2372. * @memberof DataTable#oApi
  2373. *
  2374. * @todo For the modularisation of v1.11 this will need to become a callback, so
  2375. * the sort and filter methods can subscribe to it. That will required
  2376. * initialisation options for sorting, which is why it is not already baked in
  2377. */
  2378. function _fnInvalidate(settings, rowIdx, src, colIdx) {
  2379. var row = settings.aoData[rowIdx];
  2380. var i, ien;
  2381. var cellWrite = function (cell, col) {
  2382. // This is very frustrating, but in IE if you just write directly
  2383. // to innerHTML, and elements that are overwritten are GC'ed,
  2384. // even if there is a reference to them elsewhere
  2385. while (cell.childNodes.length) {
  2386. cell.removeChild(cell.firstChild);
  2387. }
  2388. cell.innerHTML = _fnGetCellData(settings, rowIdx, col, 'display');
  2389. };
  2390. // Are we reading last data from DOM or the data object?
  2391. if (src === 'dom' || ((!src || src === 'auto') && row.src === 'dom')) {
  2392. // Read the data from the DOM
  2393. row._aData = _fnGetRowElements(
  2394. settings, row, colIdx, colIdx === undefined ? undefined : row._aData
  2395. )
  2396. .data;
  2397. } else {
  2398. // Reading from data object, update the DOM
  2399. var cells = row.anCells;
  2400. if (cells) {
  2401. if (colIdx !== undefined) {
  2402. cellWrite(cells[colIdx], colIdx);
  2403. } else {
  2404. for (i = 0, ien = cells.length; i < ien; i++) {
  2405. cellWrite(cells[i], i);
  2406. }
  2407. }
  2408. }
  2409. }
  2410. // For both row and cell invalidation, the cached data for sorting and
  2411. // filtering is nulled out
  2412. row._aSortData = null;
  2413. row._aFilterData = null;
  2414. // Invalidate the type for a specific column (if given) or all columns since
  2415. // the data might have changed
  2416. var cols = settings.aoColumns;
  2417. if (colIdx !== undefined) {
  2418. cols[colIdx].sType = null;
  2419. } else {
  2420. for (i = 0, ien = cols.length; i < ien; i++) {
  2421. cols[i].sType = null;
  2422. }
  2423. // Update DataTables special `DT_*` attributes for the row
  2424. _fnRowAttributes(settings, row);
  2425. }
  2426. }
  2427. /**
  2428. * Build a data source object from an HTML row, reading the contents of the
  2429. * cells that are in the row.
  2430. *
  2431. * @param {object} settings DataTables settings object
  2432. * @param {node|object} TR element from which to read data or existing row
  2433. * object from which to re-read the data from the cells
  2434. * @param {int} [colIdx] Optional column index
  2435. * @param {array|object} [d] Data source object. If `colIdx` is given then this
  2436. * parameter should also be given and will be used to write the data into.
  2437. * Only the column in question will be written
  2438. * @returns {object} Object with two parameters: `data` the data read, in
  2439. * document order, and `cells` and array of nodes (they can be useful to the
  2440. * caller, so rather than needing a second traversal to get them, just return
  2441. * them from here).
  2442. * @memberof DataTable#oApi
  2443. */
  2444. function _fnGetRowElements(settings, row, colIdx, d) {
  2445. var
  2446. tds = [],
  2447. td = row.firstChild,
  2448. name, col, o, i = 0, contents,
  2449. columns = settings.aoColumns,
  2450. objectRead = settings._rowReadObject;
  2451. // Allow the data object to be passed in, or construct
  2452. d = d !== undefined ?
  2453. d :
  2454. objectRead ?
  2455. {} :
  2456. [];
  2457. var attr = function (str, td) {
  2458. if (typeof str === 'string') {
  2459. var idx = str.indexOf('@');
  2460. if (idx !== -1) {
  2461. var attr = str.substring(idx + 1);
  2462. var setter = _fnSetObjectDataFn(str);
  2463. setter(d, td.getAttribute(attr));
  2464. }
  2465. }
  2466. };
  2467. // Read data from a cell and store into the data object
  2468. var cellProcess = function (cell) {
  2469. if (colIdx === undefined || colIdx === i) {
  2470. col = columns[i];
  2471. contents = (cell.innerHTML).trim();
  2472. if (col && col._bAttrSrc) {
  2473. var setter = _fnSetObjectDataFn(col.mData._);
  2474. setter(d, contents);
  2475. attr(col.mData.sort, cell);
  2476. attr(col.mData.type, cell);
  2477. attr(col.mData.filter, cell);
  2478. } else {
  2479. // Depending on the `data` option for the columns the data can
  2480. // be read to either an object or an array.
  2481. if (objectRead) {
  2482. if (!col._setter) {
  2483. // Cache the setter function
  2484. col._setter = _fnSetObjectDataFn(col.mData);
  2485. }
  2486. col._setter(d, contents);
  2487. } else {
  2488. d[i] = contents;
  2489. }
  2490. }
  2491. }
  2492. i++;
  2493. };
  2494. if (td) {
  2495. // `tr` element was passed in
  2496. while (td) {
  2497. name = td.nodeName.toUpperCase();
  2498. if (name == "TD" || name == "TH") {
  2499. cellProcess(td);
  2500. tds.push(td);
  2501. }
  2502. td = td.nextSibling;
  2503. }
  2504. } else {
  2505. // Existing row object passed in
  2506. tds = row.anCells;
  2507. for (var j = 0, jen = tds.length; j < jen; j++) {
  2508. cellProcess(tds[j]);
  2509. }
  2510. }
  2511. // Read the ID from the DOM if present
  2512. var rowNode = row.firstChild ? row : row.nTr;
  2513. if (rowNode) {
  2514. var id = rowNode.getAttribute('id');
  2515. if (id) {
  2516. _fnSetObjectDataFn(settings.rowId)(d, id);
  2517. }
  2518. }
  2519. return {
  2520. data: d,
  2521. cells: tds
  2522. };
  2523. }
  2524. /**
  2525. * Create a new TR element (and it's TD children) for a row
  2526. * @param {object} oSettings dataTables settings object
  2527. * @param {int} iRow Row to consider
  2528. * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
  2529. * DataTables will create a row automatically
  2530. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  2531. * if nTr is.
  2532. * @memberof DataTable#oApi
  2533. */
  2534. function _fnCreateTr(oSettings, iRow, nTrIn, anTds) {
  2535. var
  2536. row = oSettings.aoData[iRow],
  2537. rowData = row._aData,
  2538. cells = [],
  2539. nTr, nTd, oCol,
  2540. i, iLen, create;
  2541. if (row.nTr === null) {
  2542. nTr = nTrIn || document.createElement('tr');
  2543. row.nTr = nTr;
  2544. row.anCells = cells;
  2545. /* Use a private property on the node to allow reserve mapping from the node
  2546. * to the aoData array for fast look up
  2547. */
  2548. nTr._DT_RowIndex = iRow;
  2549. /* Special parameters can be given by the data source to be used on the row */
  2550. _fnRowAttributes(oSettings, row);
  2551. /* Process each column */
  2552. for (i = 0, iLen = oSettings.aoColumns.length; i < iLen; i++) {
  2553. oCol = oSettings.aoColumns[i];
  2554. create = nTrIn ? false : true;
  2555. nTd = create ? document.createElement(oCol.sCellType) : anTds[i];
  2556. nTd._DT_CellIndex = {
  2557. row: iRow,
  2558. column: i
  2559. };
  2560. cells.push(nTd);
  2561. // Need to create the HTML if new, or if a rendering function is defined
  2562. if (create || ((oCol.mRender || oCol.mData !== i) &&
  2563. (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i + '.display')
  2564. )) {
  2565. nTd.innerHTML = _fnGetCellData(oSettings, iRow, i, 'display');
  2566. }
  2567. /* Add user defined class */
  2568. if (oCol.sClass) {
  2569. nTd.className += ' ' + oCol.sClass;
  2570. }
  2571. // Visibility - add or remove as required
  2572. if (oCol.bVisible && !nTrIn) {
  2573. nTr.appendChild(nTd);
  2574. } else if (!oCol.bVisible && nTrIn) {
  2575. nTd.parentNode.removeChild(nTd);
  2576. }
  2577. if (oCol.fnCreatedCell) {
  2578. oCol.fnCreatedCell.call(oSettings.oInstance,
  2579. nTd, _fnGetCellData(oSettings, iRow, i), rowData, iRow, i
  2580. );
  2581. }
  2582. }
  2583. _fnCallbackFire(oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow, cells]);
  2584. }
  2585. }
  2586. /**
  2587. * Add attributes to a row based on the special `DT_*` parameters in a data
  2588. * source object.
  2589. * @param {object} settings DataTables settings object
  2590. * @param {object} DataTables row object for the row to be modified
  2591. * @memberof DataTable#oApi
  2592. */
  2593. function _fnRowAttributes(settings, row) {
  2594. var tr = row.nTr;
  2595. var data = row._aData;
  2596. if (tr) {
  2597. var id = settings.rowIdFn(data);
  2598. if (id) {
  2599. tr.id = id;
  2600. }
  2601. if (data.DT_RowClass) {
  2602. // Remove any classes added by DT_RowClass before
  2603. var a = data.DT_RowClass.split(' ');
  2604. row.__rowc = row.__rowc ?
  2605. _unique(row.__rowc.concat(a)) :
  2606. a;
  2607. $(tr)
  2608. .removeClass(row.__rowc.join(' '))
  2609. .addClass(data.DT_RowClass);
  2610. }
  2611. if (data.DT_RowAttr) {
  2612. $(tr).attr(data.DT_RowAttr);
  2613. }
  2614. if (data.DT_RowData) {
  2615. $(tr).data(data.DT_RowData);
  2616. }
  2617. }
  2618. }
  2619. /**
  2620. * Create the HTML header for the table
  2621. * @param {object} oSettings dataTables settings object
  2622. * @memberof DataTable#oApi
  2623. */
  2624. function _fnBuildHead(oSettings) {
  2625. var i, ien, cell, row, column;
  2626. var thead = oSettings.nTHead;
  2627. var tfoot = oSettings.nTFoot;
  2628. var createHeader = $('th, td', thead).length === 0;
  2629. var classes = oSettings.oClasses;
  2630. var columns = oSettings.aoColumns;
  2631. if (createHeader) {
  2632. row = $('<tr/>').appendTo(thead);
  2633. }
  2634. for (i = 0, ien = columns.length; i < ien; i++) {
  2635. column = columns[i];
  2636. cell = $(column.nTh).addClass(column.sClass);
  2637. if (createHeader) {
  2638. cell.appendTo(row);
  2639. }
  2640. // 1.11 move into sorting
  2641. if (oSettings.oFeatures.bSort) {
  2642. cell.addClass(column.sSortingClass);
  2643. if (column.bSortable !== false) {
  2644. cell
  2645. .attr('tabindex', oSettings.iTabIndex)
  2646. .attr('aria-controls', oSettings.sTableId);
  2647. _fnSortAttachListener(oSettings, column.nTh, i);
  2648. }
  2649. }
  2650. if (column.sTitle != cell[0].innerHTML) {
  2651. cell.html(column.sTitle);
  2652. }
  2653. _fnRenderer(oSettings, 'header')(
  2654. oSettings, cell, column, classes
  2655. );
  2656. }
  2657. if (createHeader) {
  2658. _fnDetectHeader(oSettings.aoHeader, thead);
  2659. }
  2660. /* ARIA role for the rows */
  2661. $(thead).children('tr').attr('role', 'row');
  2662. /* Deal with the footer - add classes if required */
  2663. $(thead).children('tr').children('th, td').addClass(classes.sHeaderTH);
  2664. $(tfoot).children('tr').children('th, td').addClass(classes.sFooterTH);
  2665. // Cache the footer cells. Note that we only take the cells from the first
  2666. // row in the footer. If there is more than one row the user wants to
  2667. // interact with, they need to use the table().foot() method. Note also this
  2668. // allows cells to be used for multiple columns using colspan
  2669. if (tfoot !== null) {
  2670. var cells = oSettings.aoFooter[0];
  2671. for (i = 0, ien = cells.length; i < ien; i++) {
  2672. column = columns[i];
  2673. column.nTf = cells[i].cell;
  2674. if (column.sClass) {
  2675. $(column.nTf).addClass(column.sClass);
  2676. }
  2677. }
  2678. }
  2679. }
  2680. /**
  2681. * Draw the header (or footer) element based on the column visibility states. The
  2682. * methodology here is to use the layout array from _fnDetectHeader, modified for
  2683. * the instantaneous column visibility, to construct the new layout. The grid is
  2684. * traversed over cell at a time in a rows x columns grid fashion, although each
  2685. * cell insert can cover multiple elements in the grid - which is tracks using the
  2686. * aApplied array. Cell inserts in the grid will only occur where there isn't
  2687. * already a cell in that position.
  2688. * @param {object} oSettings dataTables settings object
  2689. * @param array {objects} aoSource Layout array from _fnDetectHeader
  2690. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  2691. * @memberof DataTable#oApi
  2692. */
  2693. function _fnDrawHead(oSettings, aoSource, bIncludeHidden) {
  2694. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  2695. var aoLocal = [];
  2696. var aApplied = [];
  2697. var iColumns = oSettings.aoColumns.length;
  2698. var iRowspan, iColspan;
  2699. if (!aoSource) {
  2700. return;
  2701. }
  2702. if (bIncludeHidden === undefined) {
  2703. bIncludeHidden = false;
  2704. }
  2705. /* Make a copy of the master layout array, but without the visible columns in it */
  2706. for (i = 0, iLen = aoSource.length; i < iLen; i++) {
  2707. aoLocal[i] = aoSource[i].slice();
  2708. aoLocal[i].nTr = aoSource[i].nTr;
  2709. /* Remove any columns which are currently hidden */
  2710. for (j = iColumns - 1; j >= 0; j--) {
  2711. if (!oSettings.aoColumns[j].bVisible && !bIncludeHidden) {
  2712. aoLocal[i].splice(j, 1);
  2713. }
  2714. }
  2715. /* Prep the applied array - it needs an element for each row */
  2716. aApplied.push([]);
  2717. }
  2718. for (i = 0, iLen = aoLocal.length; i < iLen; i++) {
  2719. nLocalTr = aoLocal[i].nTr;
  2720. /* All cells are going to be replaced, so empty out the row */
  2721. if (nLocalTr) {
  2722. while ((n = nLocalTr.firstChild)) {
  2723. nLocalTr.removeChild(n);
  2724. }
  2725. }
  2726. for (j = 0, jLen = aoLocal[i].length; j < jLen; j++) {
  2727. iRowspan = 1;
  2728. iColspan = 1;
  2729. /* Check to see if there is already a cell (row/colspan) covering our target
  2730. * insert point. If there is, then there is nothing to do.
  2731. */
  2732. if (aApplied[i][j] === undefined) {
  2733. nLocalTr.appendChild(aoLocal[i][j].cell);
  2734. aApplied[i][j] = 1;
  2735. /* Expand the cell to cover as many rows as needed */
  2736. while (aoLocal[i + iRowspan] !== undefined &&
  2737. aoLocal[i][j].cell == aoLocal[i + iRowspan][j].cell) {
  2738. aApplied[i + iRowspan][j] = 1;
  2739. iRowspan++;
  2740. }
  2741. /* Expand the cell to cover as many columns as needed */
  2742. while (aoLocal[i][j + iColspan] !== undefined &&
  2743. aoLocal[i][j].cell == aoLocal[i][j + iColspan].cell) {
  2744. /* Must update the applied array over the rows for the columns */
  2745. for (k = 0; k < iRowspan; k++) {
  2746. aApplied[i + k][j + iColspan] = 1;
  2747. }
  2748. iColspan++;
  2749. }
  2750. /* Do the actual expansion in the DOM */
  2751. $(aoLocal[i][j].cell)
  2752. .attr('rowspan', iRowspan)
  2753. .attr('colspan', iColspan);
  2754. }
  2755. }
  2756. }
  2757. }
  2758. /**
  2759. * Insert the required TR nodes into the table for display
  2760. * @param {object} oSettings dataTables settings object
  2761. * @memberof DataTable#oApi
  2762. */
  2763. function _fnDraw(oSettings) {
  2764. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  2765. var aPreDraw = _fnCallbackFire(oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings]);
  2766. if ($.inArray(false, aPreDraw) !== -1) {
  2767. _fnProcessingDisplay(oSettings, false);
  2768. return;
  2769. }
  2770. var i, iLen, n;
  2771. var anRows = [];
  2772. var iRowCount = 0;
  2773. var asStripeClasses = oSettings.asStripeClasses;
  2774. var iStripes = asStripeClasses.length;
  2775. var iOpenRows = oSettings.aoOpenRows.length;
  2776. var oLang = oSettings.oLanguage;
  2777. var iInitDisplayStart = oSettings.iInitDisplayStart;
  2778. var bServerSide = _fnDataSource(oSettings) == 'ssp';
  2779. var aiDisplay = oSettings.aiDisplay;
  2780. oSettings.bDrawing = true;
  2781. /* Check and see if we have an initial draw position from state saving */
  2782. if (iInitDisplayStart !== undefined && iInitDisplayStart !== -1) {
  2783. oSettings._iDisplayStart = bServerSide ?
  2784. iInitDisplayStart :
  2785. iInitDisplayStart >= oSettings.fnRecordsDisplay() ?
  2786. 0 :
  2787. iInitDisplayStart;
  2788. oSettings.iInitDisplayStart = -1;
  2789. }
  2790. var iDisplayStart = oSettings._iDisplayStart;
  2791. var iDisplayEnd = oSettings.fnDisplayEnd();
  2792. /* Server-side processing draw intercept */
  2793. if (oSettings.bDeferLoading) {
  2794. oSettings.bDeferLoading = false;
  2795. oSettings.iDraw++;
  2796. _fnProcessingDisplay(oSettings, false);
  2797. } else if (!bServerSide) {
  2798. oSettings.iDraw++;
  2799. } else if (!oSettings.bDestroying && !_fnAjaxUpdate(oSettings)) {
  2800. return;
  2801. }
  2802. if (aiDisplay.length !== 0) {
  2803. var iStart = bServerSide ? 0 : iDisplayStart;
  2804. var iEnd = bServerSide ? oSettings.aoData.length : iDisplayEnd;
  2805. for (var j = iStart; j < iEnd; j++) {
  2806. var iDataIndex = aiDisplay[j];
  2807. var aoData = oSettings.aoData[iDataIndex];
  2808. if (aoData.nTr === null) {
  2809. _fnCreateTr(oSettings, iDataIndex);
  2810. }
  2811. var nRow = aoData.nTr;
  2812. /* Remove the old striping classes and then add the new one */
  2813. if (iStripes !== 0) {
  2814. var sStripe = asStripeClasses[iRowCount % iStripes];
  2815. if (aoData._sRowStripe != sStripe) {
  2816. $(nRow).removeClass(aoData._sRowStripe).addClass(sStripe);
  2817. aoData._sRowStripe = sStripe;
  2818. }
  2819. }
  2820. // Row callback functions - might want to manipulate the row
  2821. // iRowCount and j are not currently documented. Are they at all
  2822. // useful?
  2823. _fnCallbackFire(oSettings, 'aoRowCallback', null,
  2824. [nRow, aoData._aData, iRowCount, j, iDataIndex]);
  2825. anRows.push(nRow);
  2826. iRowCount++;
  2827. }
  2828. } else {
  2829. /* Table is empty - create a row with an empty message in it */
  2830. var sZero = oLang.sZeroRecords;
  2831. if (oSettings.iDraw == 1 && _fnDataSource(oSettings) == 'ajax') {
  2832. sZero = oLang.sLoadingRecords;
  2833. } else if (oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0) {
  2834. sZero = oLang.sEmptyTable;
  2835. }
  2836. anRows[0] = $('<tr/>', {'class': iStripes ? asStripeClasses[0] : ''})
  2837. .append($('<td />', {
  2838. 'valign': 'top',
  2839. 'colSpan': _fnVisbleColumns(oSettings),
  2840. 'class': oSettings.oClasses.sRowEmpty
  2841. }).html(sZero))[0];
  2842. }
  2843. /* Header and footer callbacks */
  2844. _fnCallbackFire(oSettings, 'aoHeaderCallback', 'header', [$(oSettings.nTHead).children('tr')[0],
  2845. _fnGetDataMaster(oSettings), iDisplayStart, iDisplayEnd, aiDisplay]);
  2846. _fnCallbackFire(oSettings, 'aoFooterCallback', 'footer', [$(oSettings.nTFoot).children('tr')[0],
  2847. _fnGetDataMaster(oSettings), iDisplayStart, iDisplayEnd, aiDisplay]);
  2848. var body = $(oSettings.nTBody);
  2849. body.children().detach();
  2850. body.append($(anRows));
  2851. /* Call all required callback functions for the end of a draw */
  2852. _fnCallbackFire(oSettings, 'aoDrawCallback', 'draw', [oSettings]);
  2853. /* Draw is complete, sorting and filtering must be as well */
  2854. oSettings.bSorted = false;
  2855. oSettings.bFiltered = false;
  2856. oSettings.bDrawing = false;
  2857. }
  2858. /**
  2859. * Redraw the table - taking account of the various features which are enabled
  2860. * @param {object} oSettings dataTables settings object
  2861. * @param {boolean} [holdPosition] Keep the current paging position. By default
  2862. * the paging is reset to the first page
  2863. * @memberof DataTable#oApi
  2864. */
  2865. function _fnReDraw(settings, holdPosition) {
  2866. var
  2867. features = settings.oFeatures,
  2868. sort = features.bSort,
  2869. filter = features.bFilter;
  2870. if (sort) {
  2871. _fnSort(settings);
  2872. }
  2873. if (filter) {
  2874. _fnFilterComplete(settings, settings.oPreviousSearch);
  2875. } else {
  2876. // No filtering, so we want to just use the display master
  2877. settings.aiDisplay = settings.aiDisplayMaster.slice();
  2878. }
  2879. if (holdPosition !== true) {
  2880. settings._iDisplayStart = 0;
  2881. }
  2882. // Let any modules know about the draw hold position state (used by
  2883. // scrolling internally)
  2884. settings._drawHold = holdPosition;
  2885. _fnDraw(settings);
  2886. settings._drawHold = false;
  2887. }
  2888. /**
  2889. * Add the options to the page HTML for the table
  2890. * @param {object} oSettings dataTables settings object
  2891. * @memberof DataTable#oApi
  2892. */
  2893. function _fnAddOptionsHtml(oSettings) {
  2894. var classes = oSettings.oClasses;
  2895. var table = $(oSettings.nTable);
  2896. var holding = $('<div/>').insertBefore(table); // Holding element for speed
  2897. var features = oSettings.oFeatures;
  2898. // All DataTables are wrapped in a div
  2899. var insert = $('<div/>', {
  2900. id: oSettings.sTableId + '_wrapper',
  2901. 'class': classes.sWrapper + (oSettings.nTFoot ? '' : ' ' + classes.sNoFooter)
  2902. });
  2903. oSettings.nHolding = holding[0];
  2904. oSettings.nTableWrapper = insert[0];
  2905. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  2906. /* Loop over the user set positioning and place the elements as needed */
  2907. var aDom = oSettings.sDom.split('');
  2908. var featureNode, cOption, nNewNode, cNext, sAttr, j;
  2909. for (var i = 0; i < aDom.length; i++) {
  2910. featureNode = null;
  2911. cOption = aDom[i];
  2912. if (cOption == '<') {
  2913. /* New container div */
  2914. nNewNode = $('<div/>')[0];
  2915. /* Check to see if we should append an id and/or a class name to the container */
  2916. cNext = aDom[i + 1];
  2917. if (cNext == "'" || cNext == '"') {
  2918. sAttr = "";
  2919. j = 2;
  2920. while (aDom[i + j] != cNext) {
  2921. sAttr += aDom[i + j];
  2922. j++;
  2923. }
  2924. /* Replace jQuery UI constants @todo depreciated */
  2925. if (sAttr == "H") {
  2926. sAttr = classes.sJUIHeader;
  2927. } else if (sAttr == "F") {
  2928. sAttr = classes.sJUIFooter;
  2929. }
  2930. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  2931. * breaks the string into parts and applies them as needed
  2932. */
  2933. if (sAttr.indexOf('.') != -1) {
  2934. var aSplit = sAttr.split('.');
  2935. nNewNode.id = aSplit[0].substr(1, aSplit[0].length - 1);
  2936. nNewNode.className = aSplit[1];
  2937. } else if (sAttr.charAt(0) == "#") {
  2938. nNewNode.id = sAttr.substr(1, sAttr.length - 1);
  2939. } else {
  2940. nNewNode.className = sAttr;
  2941. }
  2942. i += j; /* Move along the position array */
  2943. }
  2944. insert.append(nNewNode);
  2945. insert = $(nNewNode);
  2946. } else if (cOption == '>') {
  2947. /* End container div */
  2948. insert = insert.parent();
  2949. }
  2950. // @todo Move options into their own plugins?
  2951. else if (cOption == 'l' && features.bPaginate && features.bLengthChange) {
  2952. /* Length */
  2953. featureNode = _fnFeatureHtmlLength(oSettings);
  2954. } else if (cOption == 'f' && features.bFilter) {
  2955. /* Filter */
  2956. featureNode = _fnFeatureHtmlFilter(oSettings);
  2957. } else if (cOption == 'r' && features.bProcessing) {
  2958. /* pRocessing */
  2959. featureNode = _fnFeatureHtmlProcessing(oSettings);
  2960. } else if (cOption == 't') {
  2961. /* Table */
  2962. featureNode = _fnFeatureHtmlTable(oSettings);
  2963. } else if (cOption == 'i' && features.bInfo) {
  2964. /* Info */
  2965. featureNode = _fnFeatureHtmlInfo(oSettings);
  2966. } else if (cOption == 'p' && features.bPaginate) {
  2967. /* Pagination */
  2968. featureNode = _fnFeatureHtmlPaginate(oSettings);
  2969. } else if (DataTable.ext.feature.length !== 0) {
  2970. /* Plug-in features */
  2971. var aoFeatures = DataTable.ext.feature;
  2972. for (var k = 0, kLen = aoFeatures.length; k < kLen; k++) {
  2973. if (cOption == aoFeatures[k].cFeature) {
  2974. featureNode = aoFeatures[k].fnInit(oSettings);
  2975. break;
  2976. }
  2977. }
  2978. }
  2979. /* Add to the 2D features array */
  2980. if (featureNode) {
  2981. var aanFeatures = oSettings.aanFeatures;
  2982. if (!aanFeatures[cOption]) {
  2983. aanFeatures[cOption] = [];
  2984. }
  2985. aanFeatures[cOption].push(featureNode);
  2986. insert.append(featureNode);
  2987. }
  2988. }
  2989. /* Built our DOM structure - replace the holding div with what we want */
  2990. holding.replaceWith(insert);
  2991. oSettings.nHolding = null;
  2992. }
  2993. /**
  2994. * Use the DOM source to create up an array of header cells. The idea here is to
  2995. * create a layout grid (array) of rows x columns, which contains a reference
  2996. * to the cell that that point in the grid (regardless of col/rowspan), such that
  2997. * any column / row could be removed and the new grid constructed
  2998. * @param array {object} aLayout Array to store the calculated layout in
  2999. * @param {node} nThead The header/footer element for the table
  3000. * @memberof DataTable#oApi
  3001. */
  3002. function _fnDetectHeader(aLayout, nThead) {
  3003. var nTrs = $(nThead).children('tr');
  3004. var nTr, nCell;
  3005. var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
  3006. var bUnique;
  3007. var fnShiftCol = function (a, i, j) {
  3008. var k = a[i];
  3009. while (k[j]) {
  3010. j++;
  3011. }
  3012. return j;
  3013. };
  3014. aLayout.splice(0, aLayout.length);
  3015. /* We know how many rows there are in the layout - so prep it */
  3016. for (i = 0, iLen = nTrs.length; i < iLen; i++) {
  3017. aLayout.push([]);
  3018. }
  3019. /* Calculate a layout array */
  3020. for (i = 0, iLen = nTrs.length; i < iLen; i++) {
  3021. nTr = nTrs[i];
  3022. iColumn = 0;
  3023. /* For every cell in the row... */
  3024. nCell = nTr.firstChild;
  3025. while (nCell) {
  3026. if (nCell.nodeName.toUpperCase() == "TD" ||
  3027. nCell.nodeName.toUpperCase() == "TH") {
  3028. /* Get the col and rowspan attributes from the DOM and sanitise them */
  3029. iColspan = nCell.getAttribute('colspan') * 1;
  3030. iRowspan = nCell.getAttribute('rowspan') * 1;
  3031. iColspan = (!iColspan || iColspan === 0 || iColspan === 1) ? 1 : iColspan;
  3032. iRowspan = (!iRowspan || iRowspan === 0 || iRowspan === 1) ? 1 : iRowspan;
  3033. /* There might be colspan cells already in this row, so shift our target
  3034. * accordingly
  3035. */
  3036. iColShifted = fnShiftCol(aLayout, i, iColumn);
  3037. /* Cache calculation for unique columns */
  3038. bUnique = iColspan === 1 ? true : false;
  3039. /* If there is col / rowspan, copy the information into the layout grid */
  3040. for (l = 0; l < iColspan; l++) {
  3041. for (k = 0; k < iRowspan; k++) {
  3042. aLayout[i + k][iColShifted + l] = {
  3043. "cell": nCell,
  3044. "unique": bUnique
  3045. };
  3046. aLayout[i + k].nTr = nTr;
  3047. }
  3048. }
  3049. }
  3050. nCell = nCell.nextSibling;
  3051. }
  3052. }
  3053. }
  3054. /**
  3055. * Get an array of unique th elements, one for each column
  3056. * @param {object} oSettings dataTables settings object
  3057. * @param {node} nHeader automatically detect the layout from this node - optional
  3058. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  3059. * @returns array {node} aReturn list of unique th's
  3060. * @memberof DataTable#oApi
  3061. */
  3062. function _fnGetUniqueThs(oSettings, nHeader, aLayout) {
  3063. var aReturn = [];
  3064. if (!aLayout) {
  3065. aLayout = oSettings.aoHeader;
  3066. if (nHeader) {
  3067. aLayout = [];
  3068. _fnDetectHeader(aLayout, nHeader);
  3069. }
  3070. }
  3071. for (var i = 0, iLen = aLayout.length; i < iLen; i++) {
  3072. for (var j = 0, jLen = aLayout[i].length; j < jLen; j++) {
  3073. if (aLayout[i][j].unique &&
  3074. (!aReturn[j] || !oSettings.bSortCellsTop)) {
  3075. aReturn[j] = aLayout[i][j].cell;
  3076. }
  3077. }
  3078. }
  3079. return aReturn;
  3080. }
  3081. /**
  3082. * Create an Ajax call based on the table's settings, taking into account that
  3083. * parameters can have multiple forms, and backwards compatibility.
  3084. *
  3085. * @param {object} oSettings dataTables settings object
  3086. * @param {array} data Data to send to the server, required by
  3087. * DataTables - may be augmented by developer callbacks
  3088. * @param {function} fn Callback function to run when data is obtained
  3089. */
  3090. function _fnBuildAjax(oSettings, data, fn) {
  3091. // Compatibility with 1.9-, allow fnServerData and event to manipulate
  3092. _fnCallbackFire(oSettings, 'aoServerParams', 'serverParams', [data]);
  3093. // Convert to object based for 1.10+ if using the old array scheme which can
  3094. // come from server-side processing or serverParams
  3095. if (data && Array.isArray(data)) {
  3096. var tmp = {};
  3097. var rbracket = /(.*?)\[\]$/;
  3098. $.each(data, function (key, val) {
  3099. var match = val.name.match(rbracket);
  3100. if (match) {
  3101. // Support for arrays
  3102. var name = match[0];
  3103. if (!tmp[name]) {
  3104. tmp[name] = [];
  3105. }
  3106. tmp[name].push(val.value);
  3107. } else {
  3108. tmp[val.name] = val.value;
  3109. }
  3110. });
  3111. data = tmp;
  3112. }
  3113. var ajaxData;
  3114. var ajax = oSettings.ajax;
  3115. var instance = oSettings.oInstance;
  3116. var callback = function (json) {
  3117. _fnCallbackFire(oSettings, null, 'xhr', [oSettings, json, oSettings.jqXHR]);
  3118. fn(json);
  3119. };
  3120. if ($.isPlainObject(ajax) && ajax.data) {
  3121. ajaxData = ajax.data;
  3122. var newData = typeof ajaxData === 'function' ?
  3123. ajaxData(data, oSettings) : // fn can manipulate data or return
  3124. ajaxData; // an object object or array to merge
  3125. // If the function returned something, use that alone
  3126. data = typeof ajaxData === 'function' && newData ?
  3127. newData :
  3128. $.extend(true, data, newData);
  3129. // Remove the data property as we've resolved it already and don't want
  3130. // jQuery to do it again (it is restored at the end of the function)
  3131. delete ajax.data;
  3132. }
  3133. var baseAjax = {
  3134. "data": data,
  3135. "success": function (json) {
  3136. var error = json.error || json.sError;
  3137. if (error) {
  3138. _fnLog(oSettings, 0, error);
  3139. }
  3140. oSettings.json = json;
  3141. callback(json);
  3142. },
  3143. "dataType": "json",
  3144. "cache": false,
  3145. "type": oSettings.sServerMethod,
  3146. "error": function (xhr, error, thrown) {
  3147. var ret = _fnCallbackFire(oSettings, null, 'xhr', [oSettings, null, oSettings.jqXHR]);
  3148. if ($.inArray(true, ret) === -1) {
  3149. if (error == "parsererror") {
  3150. _fnLog(oSettings, 0, 'Invalid JSON response', 1);
  3151. } else if (xhr.readyState === 4) {
  3152. _fnLog(oSettings, 0, 'Ajax error', 7);
  3153. }
  3154. }
  3155. _fnProcessingDisplay(oSettings, false);
  3156. }
  3157. };
  3158. // Store the data submitted for the API
  3159. oSettings.oAjaxData = data;
  3160. // Allow plug-ins and external processes to modify the data
  3161. _fnCallbackFire(oSettings, null, 'preXhr', [oSettings, data]);
  3162. if (oSettings.fnServerData) {
  3163. // DataTables 1.9- compatibility
  3164. oSettings.fnServerData.call(instance,
  3165. oSettings.sAjaxSource,
  3166. $.map(data, function (val, key) { // Need to convert back to 1.9 trad format
  3167. return {name: key, value: val};
  3168. }),
  3169. callback,
  3170. oSettings
  3171. );
  3172. } else if (oSettings.sAjaxSource || typeof ajax === 'string') {
  3173. // DataTables 1.9- compatibility
  3174. oSettings.jqXHR = $.ajax($.extend(baseAjax, {
  3175. url: ajax || oSettings.sAjaxSource
  3176. }));
  3177. } else if (typeof ajax === 'function') {
  3178. // Is a function - let the caller define what needs to be done
  3179. oSettings.jqXHR = ajax.call(instance, data, callback, oSettings);
  3180. } else {
  3181. // Object to extend the base settings
  3182. oSettings.jqXHR = $.ajax($.extend(baseAjax, ajax));
  3183. // Restore for next time around
  3184. ajax.data = ajaxData;
  3185. }
  3186. }
  3187. /**
  3188. * Update the table using an Ajax call
  3189. * @param {object} settings dataTables settings object
  3190. * @returns {boolean} Block the table drawing or not
  3191. * @memberof DataTable#oApi
  3192. */
  3193. function _fnAjaxUpdate(settings) {
  3194. if (settings.bAjaxDataGet) {
  3195. settings.iDraw++;
  3196. _fnProcessingDisplay(settings, true);
  3197. _fnBuildAjax(
  3198. settings,
  3199. _fnAjaxParameters(settings),
  3200. function (json) {
  3201. _fnAjaxUpdateDraw(settings, json);
  3202. }
  3203. );
  3204. return false;
  3205. }
  3206. return true;
  3207. }
  3208. /**
  3209. * Build up the parameters in an object needed for a server-side processing
  3210. * request. Note that this is basically done twice, is different ways - a modern
  3211. * method which is used by default in DataTables 1.10 which uses objects and
  3212. * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
  3213. * the sAjaxSource option is used in the initialisation, or the legacyAjax
  3214. * option is set.
  3215. * @param {object} oSettings dataTables settings object
  3216. * @returns {bool} block the table drawing or not
  3217. * @memberof DataTable#oApi
  3218. */
  3219. function _fnAjaxParameters(settings) {
  3220. var
  3221. columns = settings.aoColumns,
  3222. columnCount = columns.length,
  3223. features = settings.oFeatures,
  3224. preSearch = settings.oPreviousSearch,
  3225. preColSearch = settings.aoPreSearchCols,
  3226. i, data = [], dataProp, column, columnSearch,
  3227. sort = _fnSortFlatten(settings),
  3228. displayStart = settings._iDisplayStart,
  3229. displayLength = features.bPaginate !== false ?
  3230. settings._iDisplayLength :
  3231. -1;
  3232. var param = function (name, value) {
  3233. data.push({'name': name, 'value': value});
  3234. };
  3235. // DataTables 1.9- compatible method
  3236. param('sEcho', settings.iDraw);
  3237. param('iColumns', columnCount);
  3238. param('sColumns', _pluck(columns, 'sName').join(','));
  3239. param('iDisplayStart', displayStart);
  3240. param('iDisplayLength', displayLength);
  3241. // DataTables 1.10+ method
  3242. var d = {
  3243. draw: settings.iDraw,
  3244. columns: [],
  3245. order: [],
  3246. start: displayStart,
  3247. length: displayLength,
  3248. search: {
  3249. value: preSearch.sSearch,
  3250. regex: preSearch.bRegex
  3251. }
  3252. };
  3253. for (i = 0; i < columnCount; i++) {
  3254. column = columns[i];
  3255. columnSearch = preColSearch[i];
  3256. dataProp = typeof column.mData == "function" ? 'function' : column.mData;
  3257. d.columns.push({
  3258. data: dataProp,
  3259. name: column.sName,
  3260. searchable: column.bSearchable,
  3261. orderable: column.bSortable,
  3262. search: {
  3263. value: columnSearch.sSearch,
  3264. regex: columnSearch.bRegex
  3265. }
  3266. });
  3267. param("mDataProp_" + i, dataProp);
  3268. if (features.bFilter) {
  3269. param('sSearch_' + i, columnSearch.sSearch);
  3270. param('bRegex_' + i, columnSearch.bRegex);
  3271. param('bSearchable_' + i, column.bSearchable);
  3272. }
  3273. if (features.bSort) {
  3274. param('bSortable_' + i, column.bSortable);
  3275. }
  3276. }
  3277. if (features.bFilter) {
  3278. param('sSearch', preSearch.sSearch);
  3279. param('bRegex', preSearch.bRegex);
  3280. }
  3281. if (features.bSort) {
  3282. $.each(sort, function (i, val) {
  3283. d.order.push({column: val.col, dir: val.dir});
  3284. param('iSortCol_' + i, val.col);
  3285. param('sSortDir_' + i, val.dir);
  3286. });
  3287. param('iSortingCols', sort.length);
  3288. }
  3289. // If the legacy.ajax parameter is null, then we automatically decide which
  3290. // form to use, based on sAjaxSource
  3291. var legacy = DataTable.ext.legacy.ajax;
  3292. if (legacy === null) {
  3293. return settings.sAjaxSource ? data : d;
  3294. }
  3295. // Otherwise, if legacy has been specified then we use that to decide on the
  3296. // form
  3297. return legacy ? data : d;
  3298. }
  3299. /**
  3300. * Data the data from the server (nuking the old) and redraw the table
  3301. * @param {object} oSettings dataTables settings object
  3302. * @param {object} json json data return from the server.
  3303. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  3304. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  3305. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  3306. * @param {array} json.aaData The data to display on this page
  3307. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  3308. * @memberof DataTable#oApi
  3309. */
  3310. function _fnAjaxUpdateDraw(settings, json) {
  3311. // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
  3312. // Support both
  3313. var compat = function (old, modern) {
  3314. return json[old] !== undefined ? json[old] : json[modern];
  3315. };
  3316. var data = _fnAjaxDataSrc(settings, json);
  3317. var draw = compat('sEcho', 'draw');
  3318. var recordsTotal = compat('iTotalRecords', 'recordsTotal');
  3319. var recordsFiltered = compat('iTotalDisplayRecords', 'recordsFiltered');
  3320. if (draw !== undefined) {
  3321. // Protect against out of sequence returns
  3322. if (draw * 1 < settings.iDraw) {
  3323. return;
  3324. }
  3325. settings.iDraw = draw * 1;
  3326. }
  3327. _fnClearTable(settings);
  3328. settings._iRecordsTotal = parseInt(recordsTotal, 10);
  3329. settings._iRecordsDisplay = parseInt(recordsFiltered, 10);
  3330. for (var i = 0, ien = data.length; i < ien; i++) {
  3331. _fnAddData(settings, data[i]);
  3332. }
  3333. settings.aiDisplay = settings.aiDisplayMaster.slice();
  3334. settings.bAjaxDataGet = false;
  3335. _fnDraw(settings);
  3336. if (!settings._bInitComplete) {
  3337. _fnInitComplete(settings, json);
  3338. }
  3339. settings.bAjaxDataGet = true;
  3340. _fnProcessingDisplay(settings, false);
  3341. }
  3342. /**
  3343. * Get the data from the JSON data source to use for drawing a table. Using
  3344. * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
  3345. * source object, or from a processing function.
  3346. * @param {object} oSettings dataTables settings object
  3347. * @param {object} json Data source object / array from the server
  3348. * @return {array} Array of data to use
  3349. */
  3350. function _fnAjaxDataSrc(oSettings, json) {
  3351. var dataSrc = $.isPlainObject(oSettings.ajax) && oSettings.ajax.dataSrc !== undefined ?
  3352. oSettings.ajax.dataSrc :
  3353. oSettings.sAjaxDataProp; // Compatibility with 1.9-.
  3354. // Compatibility with 1.9-. In order to read from aaData, check if the
  3355. // default has been changed, if not, check for aaData
  3356. if (dataSrc === 'data') {
  3357. return json.aaData || json[dataSrc];
  3358. }
  3359. return dataSrc !== "" ?
  3360. _fnGetObjectDataFn(dataSrc)(json) :
  3361. json;
  3362. }
  3363. /**
  3364. * Generate the node required for filtering text
  3365. * @returns {node} Filter control element
  3366. * @param {object} oSettings dataTables settings object
  3367. * @memberof DataTable#oApi
  3368. */
  3369. function _fnFeatureHtmlFilter(settings) {
  3370. var classes = settings.oClasses;
  3371. var tableId = settings.sTableId;
  3372. var language = settings.oLanguage;
  3373. var previousSearch = settings.oPreviousSearch;
  3374. var features = settings.aanFeatures;
  3375. var input = '<input type="search" class="' + classes.sFilterInput + '"/>';
  3376. var str = language.sSearch;
  3377. str = str.match(/_INPUT_/) ?
  3378. str.replace('_INPUT_', input) :
  3379. str + input;
  3380. var filter = $('<div/>', {
  3381. 'id': !features.f ? tableId + '_filter' : null,
  3382. 'class': classes.sFilter
  3383. })
  3384. .append($('<label/>').append(str));
  3385. var searchFn = function () {
  3386. /* Update all other filter input elements for the new display */
  3387. var n = features.f;
  3388. var val = !this.value ? "" : this.value; // mental IE8 fix :-(
  3389. /* Now do the filter */
  3390. if (val != previousSearch.sSearch) {
  3391. _fnFilterComplete(settings, {
  3392. "sSearch": val,
  3393. "bRegex": previousSearch.bRegex,
  3394. "bSmart": previousSearch.bSmart,
  3395. "bCaseInsensitive": previousSearch.bCaseInsensitive
  3396. });
  3397. // Need to redraw, without resorting
  3398. settings._iDisplayStart = 0;
  3399. _fnDraw(settings);
  3400. }
  3401. };
  3402. var searchDelay = settings.searchDelay !== null ?
  3403. settings.searchDelay :
  3404. _fnDataSource(settings) === 'ssp' ?
  3405. 400 :
  3406. 0;
  3407. var jqFilter = $('input', filter)
  3408. .val(previousSearch.sSearch)
  3409. .attr('placeholder', language.sSearchPlaceholder)
  3410. .on(
  3411. 'keyup.DT search.DT input.DT paste.DT cut.DT',
  3412. searchDelay ?
  3413. _fnThrottle(searchFn, searchDelay) :
  3414. searchFn
  3415. )
  3416. .on('mouseup', function (e) {
  3417. // Edge fix! Edge 17 does not trigger anything other than mouse events when clicking
  3418. // on the clear icon (Edge bug 17584515). This is safe in other browsers as `searchFn`
  3419. // checks the value to see if it has changed. In other browsers it won't have.
  3420. setTimeout(function () {
  3421. searchFn.call(jqFilter[0]);
  3422. }, 10);
  3423. })
  3424. .on('keypress.DT', function (e) {
  3425. /* Prevent form submission */
  3426. if (e.keyCode == 13) {
  3427. return false;
  3428. }
  3429. })
  3430. .attr('aria-controls', tableId);
  3431. // Update the input elements whenever the table is filtered
  3432. $(settings.nTable).on('search.dt.DT', function (ev, s) {
  3433. if (settings === s) {
  3434. // IE9 throws an 'unknown error' if document.activeElement is used
  3435. // inside an iframe or frame...
  3436. try {
  3437. if (jqFilter[0] !== document.activeElement) {
  3438. jqFilter.val(previousSearch.sSearch);
  3439. }
  3440. } catch (e) {
  3441. }
  3442. }
  3443. });
  3444. return filter[0];
  3445. }
  3446. /**
  3447. * Filter the table using both the global filter and column based filtering
  3448. * @param {object} oSettings dataTables settings object
  3449. * @param {object} oSearch search information
  3450. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  3451. * @memberof DataTable#oApi
  3452. */
  3453. function _fnFilterComplete(oSettings, oInput, iForce) {
  3454. var oPrevSearch = oSettings.oPreviousSearch;
  3455. var aoPrevSearch = oSettings.aoPreSearchCols;
  3456. var fnSaveFilter = function (oFilter) {
  3457. /* Save the filtering values */
  3458. oPrevSearch.sSearch = oFilter.sSearch;
  3459. oPrevSearch.bRegex = oFilter.bRegex;
  3460. oPrevSearch.bSmart = oFilter.bSmart;
  3461. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  3462. };
  3463. var fnRegex = function (o) {
  3464. // Backwards compatibility with the bEscapeRegex option
  3465. return o.bEscapeRegex !== undefined ? !o.bEscapeRegex : o.bRegex;
  3466. };
  3467. // Resolve any column types that are unknown due to addition or invalidation
  3468. // @todo As per sort - can this be moved into an event handler?
  3469. _fnColumnTypes(oSettings);
  3470. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  3471. if (_fnDataSource(oSettings) != 'ssp') {
  3472. /* Global filter */
  3473. _fnFilter(oSettings, oInput.sSearch, iForce, fnRegex(oInput), oInput.bSmart, oInput.bCaseInsensitive);
  3474. fnSaveFilter(oInput);
  3475. /* Now do the individual column filter */
  3476. for (var i = 0; i < aoPrevSearch.length; i++) {
  3477. _fnFilterColumn(oSettings, aoPrevSearch[i].sSearch, i, fnRegex(aoPrevSearch[i]),
  3478. aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive);
  3479. }
  3480. /* Custom filtering */
  3481. _fnFilterCustom(oSettings);
  3482. } else {
  3483. fnSaveFilter(oInput);
  3484. }
  3485. /* Tell the draw function we have been filtering */
  3486. oSettings.bFiltered = true;
  3487. _fnCallbackFire(oSettings, null, 'search', [oSettings]);
  3488. }
  3489. /**
  3490. * Apply custom filtering functions
  3491. * @param {object} oSettings dataTables settings object
  3492. * @memberof DataTable#oApi
  3493. */
  3494. function _fnFilterCustom(settings) {
  3495. var filters = DataTable.ext.search;
  3496. var displayRows = settings.aiDisplay;
  3497. var row, rowIdx;
  3498. for (var i = 0, ien = filters.length; i < ien; i++) {
  3499. var rows = [];
  3500. // Loop over each row and see if it should be included
  3501. for (var j = 0, jen = displayRows.length; j < jen; j++) {
  3502. rowIdx = displayRows[j];
  3503. row = settings.aoData[rowIdx];
  3504. if (filters[i](settings, row._aFilterData, rowIdx, row._aData, j)) {
  3505. rows.push(rowIdx);
  3506. }
  3507. }
  3508. // So the array reference doesn't break set the results into the
  3509. // existing array
  3510. displayRows.length = 0;
  3511. $.merge(displayRows, rows);
  3512. }
  3513. }
  3514. /**
  3515. * Filter the table on a per-column basis
  3516. * @param {object} oSettings dataTables settings object
  3517. * @param {string} sInput string to filter on
  3518. * @param {int} iColumn column to filter
  3519. * @param {bool} bRegex treat search string as a regular expression or not
  3520. * @param {bool} bSmart use smart filtering or not
  3521. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  3522. * @memberof DataTable#oApi
  3523. */
  3524. function _fnFilterColumn(settings, searchStr, colIdx, regex, smart, caseInsensitive) {
  3525. if (searchStr === '') {
  3526. return;
  3527. }
  3528. var data;
  3529. var out = [];
  3530. var display = settings.aiDisplay;
  3531. var rpSearch = _fnFilterCreateSearch(searchStr, regex, smart, caseInsensitive);
  3532. for (var i = 0; i < display.length; i++) {
  3533. data = settings.aoData[display[i]]._aFilterData[colIdx];
  3534. if (rpSearch.test(data)) {
  3535. out.push(display[i]);
  3536. }
  3537. }
  3538. settings.aiDisplay = out;
  3539. }
  3540. /**
  3541. * Filter the data table based on user input and draw the table
  3542. * @param {object} settings dataTables settings object
  3543. * @param {string} input string to filter on
  3544. * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
  3545. * @param {bool} regex treat as a regular expression or not
  3546. * @param {bool} smart perform smart filtering or not
  3547. * @param {bool} caseInsensitive Do case insenstive matching or not
  3548. * @memberof DataTable#oApi
  3549. */
  3550. function _fnFilter(settings, input, force, regex, smart, caseInsensitive) {
  3551. var rpSearch = _fnFilterCreateSearch(input, regex, smart, caseInsensitive);
  3552. var prevSearch = settings.oPreviousSearch.sSearch;
  3553. var displayMaster = settings.aiDisplayMaster;
  3554. var display, invalidated, i;
  3555. var filtered = [];
  3556. // Need to take account of custom filtering functions - always filter
  3557. if (DataTable.ext.search.length !== 0) {
  3558. force = true;
  3559. }
  3560. // Check if any of the rows were invalidated
  3561. invalidated = _fnFilterData(settings);
  3562. // If the input is blank - we just want the full data set
  3563. if (input.length <= 0) {
  3564. settings.aiDisplay = displayMaster.slice();
  3565. } else {
  3566. // New search - start from the master array
  3567. if (invalidated ||
  3568. force ||
  3569. regex ||
  3570. prevSearch.length > input.length ||
  3571. input.indexOf(prevSearch) !== 0 ||
  3572. settings.bSorted // On resort, the display master needs to be
  3573. // re-filtered since indexes will have changed
  3574. ) {
  3575. settings.aiDisplay = displayMaster.slice();
  3576. }
  3577. // Search the display array
  3578. display = settings.aiDisplay;
  3579. for (i = 0; i < display.length; i++) {
  3580. if (rpSearch.test(settings.aoData[display[i]]._sFilterRow)) {
  3581. filtered.push(display[i]);
  3582. }
  3583. }
  3584. settings.aiDisplay = filtered;
  3585. }
  3586. }
  3587. /**
  3588. * Build a regular expression object suitable for searching a table
  3589. * @param {string} sSearch string to search for
  3590. * @param {bool} bRegex treat as a regular expression or not
  3591. * @param {bool} bSmart perform smart filtering or not
  3592. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  3593. * @returns {RegExp} constructed object
  3594. * @memberof DataTable#oApi
  3595. */
  3596. function _fnFilterCreateSearch(search, regex, smart, caseInsensitive) {
  3597. search = regex ?
  3598. search :
  3599. _fnEscapeRegex(search);
  3600. if (smart) {
  3601. /* For smart filtering we want to allow the search to work regardless of
  3602. * word order. We also want double quoted text to be preserved, so word
  3603. * order is important - a la google. So this is what we want to
  3604. * generate:
  3605. *
  3606. * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
  3607. */
  3608. var a = $.map(search.match(/"[^"]+"|[^ ]+/g) || [''], function (word) {
  3609. if (word.charAt(0) === '"') {
  3610. var m = word.match(/^"(.*)"$/);
  3611. word = m ? m[1] : word;
  3612. }
  3613. return word.replace('"', '');
  3614. });
  3615. search = '^(?=.*?' + a.join(')(?=.*?') + ').*$';
  3616. }
  3617. return new RegExp(search, caseInsensitive ? 'i' : '');
  3618. }
  3619. /**
  3620. * Escape a string such that it can be used in a regular expression
  3621. * @param {string} sVal string to escape
  3622. * @returns {string} escaped string
  3623. * @memberof DataTable#oApi
  3624. */
  3625. var _fnEscapeRegex = DataTable.util.escapeRegex;
  3626. var __filter_div = $('<div>')[0];
  3627. var __filter_div_textContent = __filter_div.textContent !== undefined;
  3628. // Update the filtering data for each row if needed (by invalidation or first run)
  3629. function _fnFilterData(settings) {
  3630. var columns = settings.aoColumns;
  3631. var column;
  3632. var i, j, ien, jen, filterData, cellData, row;
  3633. var fomatters = DataTable.ext.type.search;
  3634. var wasInvalidated = false;
  3635. for (i = 0, ien = settings.aoData.length; i < ien; i++) {
  3636. row = settings.aoData[i];
  3637. if (!row._aFilterData) {
  3638. filterData = [];
  3639. for (j = 0, jen = columns.length; j < jen; j++) {
  3640. column = columns[j];
  3641. if (column.bSearchable) {
  3642. cellData = _fnGetCellData(settings, i, j, 'filter');
  3643. if (fomatters[column.sType]) {
  3644. cellData = fomatters[column.sType](cellData);
  3645. }
  3646. // Search in DataTables 1.10 is string based. In 1.11 this
  3647. // should be altered to also allow strict type checking.
  3648. if (cellData === null) {
  3649. cellData = '';
  3650. }
  3651. if (typeof cellData !== 'string' && cellData.toString) {
  3652. cellData = cellData.toString();
  3653. }
  3654. } else {
  3655. cellData = '';
  3656. }
  3657. // If it looks like there is an HTML entity in the string,
  3658. // attempt to decode it so sorting works as expected. Note that
  3659. // we could use a single line of jQuery to do this, but the DOM
  3660. // method used here is much faster http://jsperf.com/html-decode
  3661. if (cellData.indexOf && cellData.indexOf('&') !== -1) {
  3662. __filter_div.innerHTML = cellData;
  3663. cellData = __filter_div_textContent ?
  3664. __filter_div.textContent :
  3665. __filter_div.innerText;
  3666. }
  3667. if (cellData.replace) {
  3668. cellData = cellData.replace(/[\r\n\u2028]/g, '');
  3669. }
  3670. filterData.push(cellData);
  3671. }
  3672. row._aFilterData = filterData;
  3673. row._sFilterRow = filterData.join(' ');
  3674. wasInvalidated = true;
  3675. }
  3676. }
  3677. return wasInvalidated;
  3678. }
  3679. /**
  3680. * Convert from the internal Hungarian notation to camelCase for external
  3681. * interaction
  3682. * @param {object} obj Object to convert
  3683. * @returns {object} Inverted object
  3684. * @memberof DataTable#oApi
  3685. */
  3686. function _fnSearchToCamel(obj) {
  3687. return {
  3688. search: obj.sSearch,
  3689. smart: obj.bSmart,
  3690. regex: obj.bRegex,
  3691. caseInsensitive: obj.bCaseInsensitive
  3692. };
  3693. }
  3694. /**
  3695. * Convert from camelCase notation to the internal Hungarian. We could use the
  3696. * Hungarian convert function here, but this is cleaner
  3697. * @param {object} obj Object to convert
  3698. * @returns {object} Inverted object
  3699. * @memberof DataTable#oApi
  3700. */
  3701. function _fnSearchToHung(obj) {
  3702. return {
  3703. sSearch: obj.search,
  3704. bSmart: obj.smart,
  3705. bRegex: obj.regex,
  3706. bCaseInsensitive: obj.caseInsensitive
  3707. };
  3708. }
  3709. /**
  3710. * Generate the node required for the info display
  3711. * @param {object} oSettings dataTables settings object
  3712. * @returns {node} Information element
  3713. * @memberof DataTable#oApi
  3714. */
  3715. function _fnFeatureHtmlInfo(settings) {
  3716. var
  3717. tid = settings.sTableId,
  3718. nodes = settings.aanFeatures.i,
  3719. n = $('<div/>', {
  3720. 'class': settings.oClasses.sInfo,
  3721. 'id': !nodes ? tid + '_info' : null
  3722. });
  3723. if (!nodes) {
  3724. // Update display on each draw
  3725. settings.aoDrawCallback.push({
  3726. "fn": _fnUpdateInfo,
  3727. "sName": "information"
  3728. });
  3729. n
  3730. .attr('role', 'status')
  3731. .attr('aria-live', 'polite');
  3732. // Table is described by our info div
  3733. $(settings.nTable).attr('aria-describedby', tid + '_info');
  3734. }
  3735. return n[0];
  3736. }
  3737. /**
  3738. * Update the information elements in the display
  3739. * @param {object} settings dataTables settings object
  3740. * @memberof DataTable#oApi
  3741. */
  3742. function _fnUpdateInfo(settings) {
  3743. /* Show information about the table */
  3744. var nodes = settings.aanFeatures.i;
  3745. if (nodes.length === 0) {
  3746. return;
  3747. }
  3748. var
  3749. lang = settings.oLanguage,
  3750. start = settings._iDisplayStart + 1,
  3751. end = settings.fnDisplayEnd(),
  3752. max = settings.fnRecordsTotal(),
  3753. total = settings.fnRecordsDisplay(),
  3754. out = total ?
  3755. lang.sInfo :
  3756. lang.sInfoEmpty;
  3757. if (total !== max) {
  3758. /* Record set after filtering */
  3759. out += ' ' + lang.sInfoFiltered;
  3760. }
  3761. // Convert the macros
  3762. out += lang.sInfoPostFix;
  3763. out = _fnInfoMacros(settings, out);
  3764. var callback = lang.fnInfoCallback;
  3765. if (callback !== null) {
  3766. out = callback.call(settings.oInstance,
  3767. settings, start, end, max, total, out
  3768. );
  3769. }
  3770. $(nodes).html(out);
  3771. }
  3772. function _fnInfoMacros(settings, str) {
  3773. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  3774. // internally
  3775. var
  3776. formatter = settings.fnFormatNumber,
  3777. start = settings._iDisplayStart + 1,
  3778. len = settings._iDisplayLength,
  3779. vis = settings.fnRecordsDisplay(),
  3780. all = len === -1;
  3781. return str.replace(/_START_/g, formatter.call(settings, start)).replace(/_END_/g, formatter.call(settings, settings.fnDisplayEnd())).replace(/_MAX_/g, formatter.call(settings, settings.fnRecordsTotal())).replace(/_TOTAL_/g, formatter.call(settings, vis)).replace(/_PAGE_/g, formatter.call(settings, all ? 1 : Math.ceil(start / len))).replace(/_PAGES_/g, formatter.call(settings, all ? 1 : Math.ceil(vis / len)));
  3782. }
  3783. /**
  3784. * Draw the table for the first time, adding all required features
  3785. * @param {object} settings dataTables settings object
  3786. * @memberof DataTable#oApi
  3787. */
  3788. function _fnInitialise(settings) {
  3789. var i, iLen, iAjaxStart = settings.iInitDisplayStart;
  3790. var columns = settings.aoColumns, column;
  3791. var features = settings.oFeatures;
  3792. var deferLoading = settings.bDeferLoading; // value modified by the draw
  3793. /* Ensure that the table data is fully initialised */
  3794. if (!settings.bInitialised) {
  3795. setTimeout(function () {
  3796. _fnInitialise(settings);
  3797. }, 200);
  3798. return;
  3799. }
  3800. /* Show the display HTML options */
  3801. _fnAddOptionsHtml(settings);
  3802. /* Build and draw the header / footer for the table */
  3803. _fnBuildHead(settings);
  3804. _fnDrawHead(settings, settings.aoHeader);
  3805. _fnDrawHead(settings, settings.aoFooter);
  3806. /* Okay to show that something is going on now */
  3807. _fnProcessingDisplay(settings, true);
  3808. /* Calculate sizes for columns */
  3809. if (features.bAutoWidth) {
  3810. _fnCalculateColumnWidths(settings);
  3811. }
  3812. for (i = 0, iLen = columns.length; i < iLen; i++) {
  3813. column = columns[i];
  3814. if (column.sWidth) {
  3815. column.nTh.style.width = _fnStringToCss(column.sWidth);
  3816. }
  3817. }
  3818. _fnCallbackFire(settings, null, 'preInit', [settings]);
  3819. // If there is default sorting required - let's do it. The sort function
  3820. // will do the drawing for us. Otherwise we draw the table regardless of the
  3821. // Ajax source - this allows the table to look initialised for Ajax sourcing
  3822. // data (show 'loading' message possibly)
  3823. _fnReDraw(settings);
  3824. // Server-side processing init complete is done by _fnAjaxUpdateDraw
  3825. var dataSrc = _fnDataSource(settings);
  3826. if (dataSrc != 'ssp' || deferLoading) {
  3827. // if there is an ajax source load the data
  3828. if (dataSrc == 'ajax') {
  3829. _fnBuildAjax(settings, [], function (json) {
  3830. var aData = _fnAjaxDataSrc(settings, json);
  3831. // Got the data - add it to the table
  3832. for (i = 0; i < aData.length; i++) {
  3833. _fnAddData(settings, aData[i]);
  3834. }
  3835. // Reset the init display for cookie saving. We've already done
  3836. // a filter, and therefore cleared it before. So we need to make
  3837. // it appear 'fresh'
  3838. settings.iInitDisplayStart = iAjaxStart;
  3839. _fnReDraw(settings);
  3840. _fnProcessingDisplay(settings, false);
  3841. _fnInitComplete(settings, json);
  3842. }, settings);
  3843. } else {
  3844. _fnProcessingDisplay(settings, false);
  3845. _fnInitComplete(settings);
  3846. }
  3847. }
  3848. }
  3849. /**
  3850. * Draw the table for the first time, adding all required features
  3851. * @param {object} oSettings dataTables settings object
  3852. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  3853. * with client-side processing (optional)
  3854. * @memberof DataTable#oApi
  3855. */
  3856. function _fnInitComplete(settings, json) {
  3857. settings._bInitComplete = true;
  3858. // When data was added after the initialisation (data or Ajax) we need to
  3859. // calculate the column sizing
  3860. if (json || settings.oInit.aaData) {
  3861. _fnAdjustColumnSizing(settings);
  3862. }
  3863. _fnCallbackFire(settings, null, 'plugin-init', [settings, json]);
  3864. _fnCallbackFire(settings, 'aoInitComplete', 'init', [settings, json]);
  3865. }
  3866. function _fnLengthChange(settings, val) {
  3867. var len = parseInt(val, 10);
  3868. settings._iDisplayLength = len;
  3869. _fnLengthOverflow(settings);
  3870. // Fire length change event
  3871. _fnCallbackFire(settings, null, 'length', [settings, len]);
  3872. }
  3873. /**
  3874. * Generate the node required for user display length changing
  3875. * @param {object} settings dataTables settings object
  3876. * @returns {node} Display length feature node
  3877. * @memberof DataTable#oApi
  3878. */
  3879. function _fnFeatureHtmlLength(settings) {
  3880. var
  3881. classes = settings.oClasses,
  3882. tableId = settings.sTableId,
  3883. menu = settings.aLengthMenu,
  3884. d2 = Array.isArray(menu[0]),
  3885. lengths = d2 ? menu[0] : menu,
  3886. language = d2 ? menu[1] : menu;
  3887. var select = $('<select/>', {
  3888. 'name': tableId + '_length',
  3889. 'aria-controls': tableId,
  3890. 'class': classes.sLengthSelect
  3891. });
  3892. for (var i = 0, ien = lengths.length; i < ien; i++) {
  3893. select[0][i] = new Option(
  3894. typeof language[i] === 'number' ?
  3895. settings.fnFormatNumber(language[i]) :
  3896. language[i],
  3897. lengths[i]
  3898. );
  3899. }
  3900. var div = $('<div><label/></div>').addClass(classes.sLength);
  3901. if (!settings.aanFeatures.l) {
  3902. div[0].id = tableId + '_length';
  3903. }
  3904. div.children().append(
  3905. settings.oLanguage.sLengthMenu.replace('_MENU_', select[0].outerHTML)
  3906. );
  3907. // Can't use `select` variable as user might provide their own and the
  3908. // reference is broken by the use of outerHTML
  3909. $('select', div)
  3910. .val(settings._iDisplayLength)
  3911. .on('change.DT', function (e) {
  3912. _fnLengthChange(settings, $(this).val());
  3913. _fnDraw(settings);
  3914. });
  3915. // Update node value whenever anything changes the table's length
  3916. $(settings.nTable).on('length.dt.DT', function (e, s, len) {
  3917. if (settings === s) {
  3918. $('select', div).val(len);
  3919. }
  3920. });
  3921. return div[0];
  3922. }
  3923. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3924. * Note that most of the paging logic is done in
  3925. * DataTable.ext.pager
  3926. */
  3927. /**
  3928. * Generate the node required for default pagination
  3929. * @param {object} oSettings dataTables settings object
  3930. * @returns {node} Pagination feature node
  3931. * @memberof DataTable#oApi
  3932. */
  3933. function _fnFeatureHtmlPaginate(settings) {
  3934. var
  3935. type = settings.sPaginationType,
  3936. plugin = DataTable.ext.pager[type],
  3937. modern = typeof plugin === 'function',
  3938. redraw = function (settings) {
  3939. _fnDraw(settings);
  3940. },
  3941. node = $('<div/>').addClass(settings.oClasses.sPaging + type)[0],
  3942. features = settings.aanFeatures;
  3943. if (!modern) {
  3944. plugin.fnInit(settings, node, redraw);
  3945. }
  3946. /* Add a draw callback for the pagination on first instance, to update the paging display */
  3947. if (!features.p) {
  3948. node.id = settings.sTableId + '_paginate';
  3949. settings.aoDrawCallback.push({
  3950. "fn": function (settings) {
  3951. if (modern) {
  3952. var
  3953. start = settings._iDisplayStart,
  3954. len = settings._iDisplayLength,
  3955. visRecords = settings.fnRecordsDisplay(),
  3956. all = len === -1,
  3957. page = all ? 0 : Math.ceil(start / len),
  3958. pages = all ? 1 : Math.ceil(visRecords / len),
  3959. buttons = plugin(page, pages),
  3960. i, ien;
  3961. for (i = 0, ien = features.p.length; i < ien; i++) {
  3962. _fnRenderer(settings, 'pageButton')(
  3963. settings, features.p[i], i, buttons, page, pages
  3964. );
  3965. }
  3966. } else {
  3967. plugin.fnUpdate(settings, redraw);
  3968. }
  3969. },
  3970. "sName": "pagination"
  3971. });
  3972. }
  3973. return node;
  3974. }
  3975. /**
  3976. * Alter the display settings to change the page
  3977. * @param {object} settings DataTables settings object
  3978. * @param {string|int} action Paging action to take: "first", "previous",
  3979. * "next" or "last" or page number to jump to (integer)
  3980. * @param [bool] redraw Automatically draw the update or not
  3981. * @returns {bool} true page has changed, false - no change
  3982. * @memberof DataTable#oApi
  3983. */
  3984. function _fnPageChange(settings, action, redraw) {
  3985. var
  3986. start = settings._iDisplayStart,
  3987. len = settings._iDisplayLength,
  3988. records = settings.fnRecordsDisplay();
  3989. if (records === 0 || len === -1) {
  3990. start = 0;
  3991. } else if (typeof action === "number") {
  3992. start = action * len;
  3993. if (start > records) {
  3994. start = 0;
  3995. }
  3996. } else if (action == "first") {
  3997. start = 0;
  3998. } else if (action == "previous") {
  3999. start = len >= 0 ?
  4000. start - len :
  4001. 0;
  4002. if (start < 0) {
  4003. start = 0;
  4004. }
  4005. } else if (action == "next") {
  4006. if (start + len < records) {
  4007. start += len;
  4008. }
  4009. } else if (action == "last") {
  4010. start = Math.floor((records - 1) / len) * len;
  4011. } else {
  4012. _fnLog(settings, 0, "Unknown paging action: " + action, 5);
  4013. }
  4014. var changed = settings._iDisplayStart !== start;
  4015. settings._iDisplayStart = start;
  4016. if (changed) {
  4017. _fnCallbackFire(settings, null, 'page', [settings]);
  4018. if (redraw) {
  4019. _fnDraw(settings);
  4020. }
  4021. }
  4022. return changed;
  4023. }
  4024. /**
  4025. * Generate the node required for the processing node
  4026. * @param {object} settings dataTables settings object
  4027. * @returns {node} Processing element
  4028. * @memberof DataTable#oApi
  4029. */
  4030. function _fnFeatureHtmlProcessing(settings) {
  4031. return $('<div/>', {
  4032. 'id': !settings.aanFeatures.r ? settings.sTableId + '_processing' : null,
  4033. 'class': settings.oClasses.sProcessing
  4034. })
  4035. .html(settings.oLanguage.sProcessing)
  4036. .insertBefore(settings.nTable)[0];
  4037. }
  4038. /**
  4039. * Display or hide the processing indicator
  4040. * @param {object} settings dataTables settings object
  4041. * @param {bool} show Show the processing indicator (true) or not (false)
  4042. * @memberof DataTable#oApi
  4043. */
  4044. function _fnProcessingDisplay(settings, show) {
  4045. if (settings.oFeatures.bProcessing) {
  4046. $(settings.aanFeatures.r).css('display', show ? 'block' : 'none');
  4047. }
  4048. _fnCallbackFire(settings, null, 'processing', [settings, show]);
  4049. }
  4050. /**
  4051. * Add any control elements for the table - specifically scrolling
  4052. * @param {object} settings dataTables settings object
  4053. * @returns {node} Node to add to the DOM
  4054. * @memberof DataTable#oApi
  4055. */
  4056. function _fnFeatureHtmlTable(settings) {
  4057. var table = $(settings.nTable);
  4058. // Add the ARIA grid role to the table
  4059. table.attr('role', 'grid');
  4060. // Scrolling from here on in
  4061. var scroll = settings.oScroll;
  4062. if (scroll.sX === '' && scroll.sY === '') {
  4063. return settings.nTable;
  4064. }
  4065. var scrollX = scroll.sX;
  4066. var scrollY = scroll.sY;
  4067. var classes = settings.oClasses;
  4068. var caption = table.children('caption');
  4069. var captionSide = caption.length ? caption[0]._captionSide : null;
  4070. var headerClone = $(table[0].cloneNode(false));
  4071. var footerClone = $(table[0].cloneNode(false));
  4072. var footer = table.children('tfoot');
  4073. var _div = '<div/>';
  4074. var size = function (s) {
  4075. return !s ? null : _fnStringToCss(s);
  4076. };
  4077. if (!footer.length) {
  4078. footer = null;
  4079. }
  4080. /*
  4081. * The HTML structure that we want to generate in this function is:
  4082. * div - scroller
  4083. * div - scroll head
  4084. * div - scroll head inner
  4085. * table - scroll head table
  4086. * thead - thead
  4087. * div - scroll body
  4088. * table - table (master table)
  4089. * thead - thead clone for sizing
  4090. * tbody - tbody
  4091. * div - scroll foot
  4092. * div - scroll foot inner
  4093. * table - scroll foot table
  4094. * tfoot - tfoot
  4095. */
  4096. var scroller = $(_div, {'class': classes.sScrollWrapper})
  4097. .append(
  4098. $(_div, {'class': classes.sScrollHead})
  4099. .css({
  4100. overflow: 'hidden',
  4101. position: 'relative',
  4102. border: 0,
  4103. width: scrollX ? size(scrollX) : '100%'
  4104. })
  4105. .append(
  4106. $(_div, {'class': classes.sScrollHeadInner})
  4107. .css({
  4108. 'box-sizing': 'content-box',
  4109. width: scroll.sXInner || '100%'
  4110. })
  4111. .append(
  4112. headerClone
  4113. .removeAttr('id')
  4114. .css('margin-left', 0)
  4115. .append(captionSide === 'top' ? caption : null)
  4116. .append(
  4117. table.children('thead')
  4118. )
  4119. )
  4120. )
  4121. )
  4122. .append(
  4123. $(_div, {'class': classes.sScrollBody})
  4124. .css({
  4125. position: 'relative',
  4126. overflow: 'auto',
  4127. width: size(scrollX)
  4128. })
  4129. .append(table)
  4130. );
  4131. if (footer) {
  4132. scroller.append(
  4133. $(_div, {'class': classes.sScrollFoot})
  4134. .css({
  4135. overflow: 'hidden',
  4136. border: 0,
  4137. width: scrollX ? size(scrollX) : '100%'
  4138. })
  4139. .append(
  4140. $(_div, {'class': classes.sScrollFootInner})
  4141. .append(
  4142. footerClone
  4143. .removeAttr('id')
  4144. .css('margin-left', 0)
  4145. .append(captionSide === 'bottom' ? caption : null)
  4146. .append(
  4147. table.children('tfoot')
  4148. )
  4149. )
  4150. )
  4151. );
  4152. }
  4153. var children = scroller.children();
  4154. var scrollHead = children[0];
  4155. var scrollBody = children[1];
  4156. var scrollFoot = footer ? children[2] : null;
  4157. // When the body is scrolled, then we also want to scroll the headers
  4158. if (scrollX) {
  4159. $(scrollBody).on('scroll.DT', function (e) {
  4160. var scrollLeft = this.scrollLeft;
  4161. scrollHead.scrollLeft = scrollLeft;
  4162. if (footer) {
  4163. scrollFoot.scrollLeft = scrollLeft;
  4164. }
  4165. });
  4166. }
  4167. $(scrollBody).css('max-height', scrollY);
  4168. if (!scroll.bCollapse) {
  4169. $(scrollBody).css('height', scrollY);
  4170. }
  4171. settings.nScrollHead = scrollHead;
  4172. settings.nScrollBody = scrollBody;
  4173. settings.nScrollFoot = scrollFoot;
  4174. // On redraw - align columns
  4175. settings.aoDrawCallback.push({
  4176. "fn": _fnScrollDraw,
  4177. "sName": "scrolling"
  4178. });
  4179. return scroller[0];
  4180. }
  4181. /**
  4182. * Update the header, footer and body tables for resizing - i.e. column
  4183. * alignment.
  4184. *
  4185. * Welcome to the most horrible function DataTables. The process that this
  4186. * function follows is basically:
  4187. * 1. Re-create the table inside the scrolling div
  4188. * 2. Take live measurements from the DOM
  4189. * 3. Apply the measurements to align the columns
  4190. * 4. Clean up
  4191. *
  4192. * @param {object} settings dataTables settings object
  4193. * @memberof DataTable#oApi
  4194. */
  4195. function _fnScrollDraw(settings) {
  4196. // Given that this is such a monster function, a lot of variables are use
  4197. // to try and keep the minimised size as small as possible
  4198. var
  4199. scroll = settings.oScroll,
  4200. scrollX = scroll.sX,
  4201. scrollXInner = scroll.sXInner,
  4202. scrollY = scroll.sY,
  4203. barWidth = scroll.iBarWidth,
  4204. divHeader = $(settings.nScrollHead),
  4205. divHeaderStyle = divHeader[0].style,
  4206. divHeaderInner = divHeader.children('div'),
  4207. divHeaderInnerStyle = divHeaderInner[0].style,
  4208. divHeaderTable = divHeaderInner.children('table'),
  4209. divBodyEl = settings.nScrollBody,
  4210. divBody = $(divBodyEl),
  4211. divBodyStyle = divBodyEl.style,
  4212. divFooter = $(settings.nScrollFoot),
  4213. divFooterInner = divFooter.children('div'),
  4214. divFooterTable = divFooterInner.children('table'),
  4215. header = $(settings.nTHead),
  4216. table = $(settings.nTable),
  4217. tableEl = table[0],
  4218. tableStyle = tableEl.style,
  4219. footer = settings.nTFoot ? $(settings.nTFoot) : null,
  4220. browser = settings.oBrowser,
  4221. ie67 = browser.bScrollOversize,
  4222. dtHeaderCells = _pluck(settings.aoColumns, 'nTh'),
  4223. headerTrgEls, footerTrgEls,
  4224. headerSrcEls, footerSrcEls,
  4225. headerCopy, footerCopy,
  4226. headerWidths = [], footerWidths = [],
  4227. headerContent = [], footerContent = [],
  4228. idx, correction, sanityWidth,
  4229. zeroOut = function (nSizer) {
  4230. var style = nSizer.style;
  4231. style.paddingTop = "0";
  4232. style.paddingBottom = "0";
  4233. style.borderTopWidth = "0";
  4234. style.borderBottomWidth = "0";
  4235. style.height = 0;
  4236. };
  4237. // If the scrollbar visibility has changed from the last draw, we need to
  4238. // adjust the column sizes as the table width will have changed to account
  4239. // for the scrollbar
  4240. var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
  4241. if (settings.scrollBarVis !== scrollBarVis && settings.scrollBarVis !== undefined) {
  4242. settings.scrollBarVis = scrollBarVis;
  4243. _fnAdjustColumnSizing(settings);
  4244. return; // adjust column sizing will call this function again
  4245. } else {
  4246. settings.scrollBarVis = scrollBarVis;
  4247. }
  4248. /*
  4249. * 1. Re-create the table inside the scrolling div
  4250. */
  4251. // Remove the old minimised thead and tfoot elements in the inner table
  4252. table.children('thead, tfoot').remove();
  4253. if (footer) {
  4254. footerCopy = footer.clone().prependTo(table);
  4255. footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized
  4256. footerSrcEls = footerCopy.find('tr');
  4257. }
  4258. // Clone the current header and footer elements and then place it into the inner table
  4259. headerCopy = header.clone().prependTo(table);
  4260. headerTrgEls = header.find('tr'); // original header is in its own table
  4261. headerSrcEls = headerCopy.find('tr');
  4262. headerCopy.find('th, td').removeAttr('tabindex');
  4263. /*
  4264. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  4265. */
  4266. // Remove old sizing and apply the calculated column widths
  4267. // Get the unique column headers in the newly created (cloned) header. We want to apply the
  4268. // calculated sizes to this header
  4269. if (!scrollX) {
  4270. divBodyStyle.width = '100%';
  4271. divHeader[0].style.width = '100%';
  4272. }
  4273. $.each(_fnGetUniqueThs(settings, headerCopy), function (i, el) {
  4274. idx = _fnVisibleToColumnIndex(settings, i);
  4275. el.style.width = settings.aoColumns[idx].sWidth;
  4276. });
  4277. if (footer) {
  4278. _fnApplyToChildren(function (n) {
  4279. n.style.width = "";
  4280. }, footerSrcEls);
  4281. }
  4282. // Size the table as a whole
  4283. sanityWidth = table.outerWidth();
  4284. if (scrollX === "") {
  4285. // No x scrolling
  4286. tableStyle.width = "100%";
  4287. // IE7 will make the width of the table when 100% include the scrollbar
  4288. // - which is shouldn't. When there is a scrollbar we need to take this
  4289. // into account.
  4290. if (ie67 && (table.find('tbody').height() > divBodyEl.offsetHeight ||
  4291. divBody.css('overflow-y') == "scroll")
  4292. ) {
  4293. tableStyle.width = _fnStringToCss(table.outerWidth() - barWidth);
  4294. }
  4295. // Recalculate the sanity width
  4296. sanityWidth = table.outerWidth();
  4297. } else if (scrollXInner !== "") {
  4298. // legacy x scroll inner has been given - use it
  4299. tableStyle.width = _fnStringToCss(scrollXInner);
  4300. // Recalculate the sanity width
  4301. sanityWidth = table.outerWidth();
  4302. }
  4303. // Hidden header should have zero height, so remove padding and borders. Then
  4304. // set the width based on the real headers
  4305. // Apply all styles in one pass
  4306. _fnApplyToChildren(zeroOut, headerSrcEls);
  4307. // Read all widths in next pass
  4308. _fnApplyToChildren(function (nSizer) {
  4309. headerContent.push(nSizer.innerHTML);
  4310. headerWidths.push(_fnStringToCss($(nSizer).css('width')));
  4311. }, headerSrcEls);
  4312. // Apply all widths in final pass
  4313. _fnApplyToChildren(function (nToSize, i) {
  4314. // Only apply widths to the DataTables detected header cells - this
  4315. // prevents complex headers from having contradictory sizes applied
  4316. if ($.inArray(nToSize, dtHeaderCells) !== -1) {
  4317. nToSize.style.width = headerWidths[i];
  4318. }
  4319. }, headerTrgEls);
  4320. $(headerSrcEls).height(0);
  4321. /* Same again with the footer if we have one */
  4322. if (footer) {
  4323. _fnApplyToChildren(zeroOut, footerSrcEls);
  4324. _fnApplyToChildren(function (nSizer) {
  4325. footerContent.push(nSizer.innerHTML);
  4326. footerWidths.push(_fnStringToCss($(nSizer).css('width')));
  4327. }, footerSrcEls);
  4328. _fnApplyToChildren(function (nToSize, i) {
  4329. nToSize.style.width = footerWidths[i];
  4330. }, footerTrgEls);
  4331. $(footerSrcEls).height(0);
  4332. }
  4333. /*
  4334. * 3. Apply the measurements
  4335. */
  4336. // "Hide" the header and footer that we used for the sizing. We need to keep
  4337. // the content of the cell so that the width applied to the header and body
  4338. // both match, but we want to hide it completely. We want to also fix their
  4339. // width to what they currently are
  4340. _fnApplyToChildren(function (nSizer, i) {
  4341. nSizer.innerHTML = '<div class="dataTables_sizing">' + headerContent[i] + '</div>';
  4342. nSizer.childNodes[0].style.height = "0";
  4343. nSizer.childNodes[0].style.overflow = "hidden";
  4344. nSizer.style.width = headerWidths[i];
  4345. }, headerSrcEls);
  4346. if (footer) {
  4347. _fnApplyToChildren(function (nSizer, i) {
  4348. nSizer.innerHTML = '<div class="dataTables_sizing">' + footerContent[i] + '</div>';
  4349. nSizer.childNodes[0].style.height = "0";
  4350. nSizer.childNodes[0].style.overflow = "hidden";
  4351. nSizer.style.width = footerWidths[i];
  4352. }, footerSrcEls);
  4353. }
  4354. // Sanity check that the table is of a sensible width. If not then we are going to get
  4355. // misalignment - try to prevent this by not allowing the table to shrink below its min width
  4356. if (table.outerWidth() < sanityWidth) {
  4357. // The min width depends upon if we have a vertical scrollbar visible or not */
  4358. correction = ((divBodyEl.scrollHeight > divBodyEl.offsetHeight ||
  4359. divBody.css('overflow-y') == "scroll")) ?
  4360. sanityWidth + barWidth :
  4361. sanityWidth;
  4362. // IE6/7 are a law unto themselves...
  4363. if (ie67 && (divBodyEl.scrollHeight >
  4364. divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")
  4365. ) {
  4366. tableStyle.width = _fnStringToCss(correction - barWidth);
  4367. }
  4368. // And give the user a warning that we've stopped the table getting too small
  4369. if (scrollX === "" || scrollXInner !== "") {
  4370. _fnLog(settings, 1, 'Possible column misalignment', 6);
  4371. }
  4372. } else {
  4373. correction = '100%';
  4374. }
  4375. // Apply to the container elements
  4376. divBodyStyle.width = _fnStringToCss(correction);
  4377. divHeaderStyle.width = _fnStringToCss(correction);
  4378. if (footer) {
  4379. settings.nScrollFoot.style.width = _fnStringToCss(correction);
  4380. }
  4381. /*
  4382. * 4. Clean up
  4383. */
  4384. if (!scrollY) {
  4385. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  4386. * the scrollbar height from the visible display, rather than adding it on. We need to
  4387. * set the height in order to sort this. Don't want to do it in any other browsers.
  4388. */
  4389. if (ie67) {
  4390. divBodyStyle.height = _fnStringToCss(tableEl.offsetHeight + barWidth);
  4391. }
  4392. }
  4393. /* Finally set the width's of the header and footer tables */
  4394. var iOuterWidth = table.outerWidth();
  4395. divHeaderTable[0].style.width = _fnStringToCss(iOuterWidth);
  4396. divHeaderInnerStyle.width = _fnStringToCss(iOuterWidth);
  4397. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  4398. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  4399. var bScrolling = table.height() > divBodyEl.clientHeight || divBody.css('overflow-y') == "scroll";
  4400. var padding = 'padding' + (browser.bScrollbarLeft ? 'Left' : 'Right');
  4401. divHeaderInnerStyle[padding] = bScrolling ? barWidth + "px" : "0px";
  4402. if (footer) {
  4403. divFooterTable[0].style.width = _fnStringToCss(iOuterWidth);
  4404. divFooterInner[0].style.width = _fnStringToCss(iOuterWidth);
  4405. divFooterInner[0].style[padding] = bScrolling ? barWidth + "px" : "0px";
  4406. }
  4407. // Correct DOM ordering for colgroup - comes before the thead
  4408. table.children('colgroup').insertBefore(table.children('thead'));
  4409. /* Adjust the position of the header in case we loose the y-scrollbar */
  4410. divBody.trigger('scroll');
  4411. // If sorting or filtering has occurred, jump the scrolling back to the top
  4412. // only if we aren't holding the position
  4413. if ((settings.bSorted || settings.bFiltered) && !settings._drawHold) {
  4414. divBodyEl.scrollTop = 0;
  4415. }
  4416. }
  4417. /**
  4418. * Apply a given function to the display child nodes of an element array (typically
  4419. * TD children of TR rows
  4420. * @param {function} fn Method to apply to the objects
  4421. * @param array {nodes} an1 List of elements to look through for display children
  4422. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  4423. * @memberof DataTable#oApi
  4424. */
  4425. function _fnApplyToChildren(fn, an1, an2) {
  4426. var index = 0, i = 0, iLen = an1.length;
  4427. var nNode1, nNode2;
  4428. while (i < iLen) {
  4429. nNode1 = an1[i].firstChild;
  4430. nNode2 = an2 ? an2[i].firstChild : null;
  4431. while (nNode1) {
  4432. if (nNode1.nodeType === 1) {
  4433. if (an2) {
  4434. fn(nNode1, nNode2, index);
  4435. } else {
  4436. fn(nNode1, index);
  4437. }
  4438. index++;
  4439. }
  4440. nNode1 = nNode1.nextSibling;
  4441. nNode2 = an2 ? nNode2.nextSibling : null;
  4442. }
  4443. i++;
  4444. }
  4445. }
  4446. var __re_html_remove = /<.*?>/g;
  4447. /**
  4448. * Calculate the width of columns for the table
  4449. * @param {object} oSettings dataTables settings object
  4450. * @memberof DataTable#oApi
  4451. */
  4452. function _fnCalculateColumnWidths(oSettings) {
  4453. var
  4454. table = oSettings.nTable,
  4455. columns = oSettings.aoColumns,
  4456. scroll = oSettings.oScroll,
  4457. scrollY = scroll.sY,
  4458. scrollX = scroll.sX,
  4459. scrollXInner = scroll.sXInner,
  4460. columnCount = columns.length,
  4461. visibleColumns = _fnGetColumns(oSettings, 'bVisible'),
  4462. headerCells = $('th', oSettings.nTHead),
  4463. tableWidthAttr = table.getAttribute('width'), // from DOM element
  4464. tableContainer = table.parentNode,
  4465. userInputs = false,
  4466. i, column, columnIdx, width, outerWidth,
  4467. browser = oSettings.oBrowser,
  4468. ie67 = browser.bScrollOversize;
  4469. var styleWidth = table.style.width;
  4470. if (styleWidth && styleWidth.indexOf('%') !== -1) {
  4471. tableWidthAttr = styleWidth;
  4472. }
  4473. /* Convert any user input sizes into pixel sizes */
  4474. for (i = 0; i < visibleColumns.length; i++) {
  4475. column = columns[visibleColumns[i]];
  4476. if (column.sWidth !== null) {
  4477. column.sWidth = _fnConvertToWidth(column.sWidthOrig, tableContainer);
  4478. userInputs = true;
  4479. }
  4480. }
  4481. /* If the number of columns in the DOM equals the number that we have to
  4482. * process in DataTables, then we can use the offsets that are created by
  4483. * the web- browser. No custom sizes can be set in order for this to happen,
  4484. * nor scrolling used
  4485. */
  4486. if (ie67 || !userInputs && !scrollX && !scrollY &&
  4487. columnCount == _fnVisbleColumns(oSettings) &&
  4488. columnCount == headerCells.length
  4489. ) {
  4490. for (i = 0; i < columnCount; i++) {
  4491. var colIdx = _fnVisibleToColumnIndex(oSettings, i);
  4492. if (colIdx !== null) {
  4493. columns[colIdx].sWidth = _fnStringToCss(headerCells.eq(i).width());
  4494. }
  4495. }
  4496. } else {
  4497. // Otherwise construct a single row, worst case, table with the widest
  4498. // node in the data, assign any user defined widths, then insert it into
  4499. // the DOM and allow the browser to do all the hard work of calculating
  4500. // table widths
  4501. var tmpTable = $(table).clone() // don't use cloneNode - IE8 will remove events on the main table
  4502. .css('visibility', 'hidden')
  4503. .removeAttr('id');
  4504. // Clean up the table body
  4505. tmpTable.find('tbody tr').remove();
  4506. var tr = $('<tr/>').appendTo(tmpTable.find('tbody'));
  4507. // Clone the table header and footer - we can't use the header / footer
  4508. // from the cloned table, since if scrolling is active, the table's
  4509. // real header and footer are contained in different table tags
  4510. tmpTable.find('thead, tfoot').remove();
  4511. tmpTable
  4512. .append($(oSettings.nTHead).clone())
  4513. .append($(oSettings.nTFoot).clone());
  4514. // Remove any assigned widths from the footer (from scrolling)
  4515. tmpTable.find('tfoot th, tfoot td').css('width', '');
  4516. // Apply custom sizing to the cloned header
  4517. headerCells = _fnGetUniqueThs(oSettings, tmpTable.find('thead')[0]);
  4518. for (i = 0; i < visibleColumns.length; i++) {
  4519. column = columns[visibleColumns[i]];
  4520. headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ?
  4521. _fnStringToCss(column.sWidthOrig) :
  4522. '';
  4523. // For scrollX we need to force the column width otherwise the
  4524. // browser will collapse it. If this width is smaller than the
  4525. // width the column requires, then it will have no effect
  4526. if (column.sWidthOrig && scrollX) {
  4527. $(headerCells[i]).append($('<div/>').css({
  4528. width: column.sWidthOrig,
  4529. margin: 0,
  4530. padding: 0,
  4531. border: 0,
  4532. height: 1
  4533. }));
  4534. }
  4535. }
  4536. // Find the widest cell for each column and put it into the table
  4537. if (oSettings.aoData.length) {
  4538. for (i = 0; i < visibleColumns.length; i++) {
  4539. columnIdx = visibleColumns[i];
  4540. column = columns[columnIdx];
  4541. $(_fnGetWidestNode(oSettings, columnIdx))
  4542. .clone(false)
  4543. .append(column.sContentPadding)
  4544. .appendTo(tr);
  4545. }
  4546. }
  4547. // Tidy the temporary table - remove name attributes so there aren't
  4548. // duplicated in the dom (radio elements for example)
  4549. $('[name]', tmpTable).removeAttr('name');
  4550. // Table has been built, attach to the document so we can work with it.
  4551. // A holding element is used, positioned at the top of the container
  4552. // with minimal height, so it has no effect on if the container scrolls
  4553. // or not. Otherwise it might trigger scrolling when it actually isn't
  4554. // needed
  4555. var holder = $('<div/>').css(scrollX || scrollY ?
  4556. {
  4557. position: 'absolute',
  4558. top: 0,
  4559. left: 0,
  4560. height: 1,
  4561. right: 0,
  4562. overflow: 'hidden'
  4563. } :
  4564. {}
  4565. )
  4566. .append(tmpTable)
  4567. .appendTo(tableContainer);
  4568. // When scrolling (X or Y) we want to set the width of the table as
  4569. // appropriate. However, when not scrolling leave the table width as it
  4570. // is. This results in slightly different, but I think correct behaviour
  4571. if (scrollX && scrollXInner) {
  4572. tmpTable.width(scrollXInner);
  4573. } else if (scrollX) {
  4574. tmpTable.css('width', 'auto');
  4575. tmpTable.removeAttr('width');
  4576. // If there is no width attribute or style, then allow the table to
  4577. // collapse
  4578. if (tmpTable.width() < tableContainer.clientWidth && tableWidthAttr) {
  4579. tmpTable.width(tableContainer.clientWidth);
  4580. }
  4581. } else if (scrollY) {
  4582. tmpTable.width(tableContainer.clientWidth);
  4583. } else if (tableWidthAttr) {
  4584. tmpTable.width(tableWidthAttr);
  4585. }
  4586. // Get the width of each column in the constructed table - we need to
  4587. // know the inner width (so it can be assigned to the other table's
  4588. // cells) and the outer width so we can calculate the full width of the
  4589. // table. This is safe since DataTables requires a unique cell for each
  4590. // column, but if ever a header can span multiple columns, this will
  4591. // need to be modified.
  4592. var total = 0;
  4593. for (i = 0; i < visibleColumns.length; i++) {
  4594. var cell = $(headerCells[i]);
  4595. var border = cell.outerWidth() - cell.width();
  4596. // Use getBounding... where possible (not IE8-) because it can give
  4597. // sub-pixel accuracy, which we then want to round up!
  4598. var bounding = browser.bBounding ?
  4599. Math.ceil(headerCells[i].getBoundingClientRect().width) :
  4600. cell.outerWidth();
  4601. // Total is tracked to remove any sub-pixel errors as the outerWidth
  4602. // of the table might not equal the total given here (IE!).
  4603. total += bounding;
  4604. // Width for each column to use
  4605. columns[visibleColumns[i]].sWidth = _fnStringToCss(bounding - border);
  4606. }
  4607. table.style.width = _fnStringToCss(total);
  4608. // Finished with the table - ditch it
  4609. holder.remove();
  4610. }
  4611. // If there is a width attr, we want to attach an event listener which
  4612. // allows the table sizing to automatically adjust when the window is
  4613. // resized. Use the width attr rather than CSS, since we can't know if the
  4614. // CSS is a relative value or absolute - DOM read is always px.
  4615. if (tableWidthAttr) {
  4616. table.style.width = _fnStringToCss(tableWidthAttr);
  4617. }
  4618. if ((tableWidthAttr || scrollX) && !oSettings._reszEvt) {
  4619. var bindResize = function () {
  4620. $(window).on('resize.DT-' + oSettings.sInstance, _fnThrottle(function () {
  4621. _fnAdjustColumnSizing(oSettings);
  4622. }));
  4623. };
  4624. // IE6/7 will crash if we bind a resize event handler on page load.
  4625. // To be removed in 1.11 which drops IE6/7 support
  4626. if (ie67) {
  4627. setTimeout(bindResize, 1000);
  4628. } else {
  4629. bindResize();
  4630. }
  4631. oSettings._reszEvt = true;
  4632. }
  4633. }
  4634. /**
  4635. * Throttle the calls to a function. Arguments and context are maintained for
  4636. * the throttled function
  4637. * @param {function} fn Function to be called
  4638. * @param {int} [freq=200] call frequency in mS
  4639. * @returns {function} wrapped function
  4640. * @memberof DataTable#oApi
  4641. */
  4642. var _fnThrottle = DataTable.util.throttle;
  4643. /**
  4644. * Convert a CSS unit width to pixels (e.g. 2em)
  4645. * @param {string} width width to be converted
  4646. * @param {node} parent parent to get the with for (required for relative widths) - optional
  4647. * @returns {int} width in pixels
  4648. * @memberof DataTable#oApi
  4649. */
  4650. function _fnConvertToWidth(width, parent) {
  4651. if (!width) {
  4652. return 0;
  4653. }
  4654. var n = $('<div/>')
  4655. .css('width', _fnStringToCss(width))
  4656. .appendTo(parent || document.body);
  4657. var val = n[0].offsetWidth;
  4658. n.remove();
  4659. return val;
  4660. }
  4661. /**
  4662. * Get the widest node
  4663. * @param {object} settings dataTables settings object
  4664. * @param {int} colIdx column of interest
  4665. * @returns {node} widest table node
  4666. * @memberof DataTable#oApi
  4667. */
  4668. function _fnGetWidestNode(settings, colIdx) {
  4669. var idx = _fnGetMaxLenString(settings, colIdx);
  4670. if (idx < 0) {
  4671. return null;
  4672. }
  4673. var data = settings.aoData[idx];
  4674. return !data.nTr ? // Might not have been created when deferred rendering
  4675. $('<td/>').html(_fnGetCellData(settings, idx, colIdx, 'display'))[0] :
  4676. data.anCells[colIdx];
  4677. }
  4678. /**
  4679. * Get the maximum strlen for each data column
  4680. * @param {object} settings dataTables settings object
  4681. * @param {int} colIdx column of interest
  4682. * @returns {string} max string length for each column
  4683. * @memberof DataTable#oApi
  4684. */
  4685. function _fnGetMaxLenString(settings, colIdx) {
  4686. var s, max = -1, maxIdx = -1;
  4687. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  4688. s = _fnGetCellData(settings, i, colIdx, 'display') + '';
  4689. s = s.replace(__re_html_remove, '');
  4690. s = s.replace(/&nbsp;/g, ' ');
  4691. if (s.length > max) {
  4692. max = s.length;
  4693. maxIdx = i;
  4694. }
  4695. }
  4696. return maxIdx;
  4697. }
  4698. /**
  4699. * Append a CSS unit (only if required) to a string
  4700. * @param {string} value to css-ify
  4701. * @returns {string} value with css unit
  4702. * @memberof DataTable#oApi
  4703. */
  4704. function _fnStringToCss(s) {
  4705. if (s === null) {
  4706. return '0px';
  4707. }
  4708. if (typeof s == 'number') {
  4709. return s < 0 ?
  4710. '0px' :
  4711. s + 'px';
  4712. }
  4713. // Check it has a unit character already
  4714. return s.match(/\d$/) ?
  4715. s + 'px' :
  4716. s;
  4717. }
  4718. function _fnSortFlatten(settings) {
  4719. var
  4720. i, iLen, k, kLen,
  4721. aSort = [],
  4722. aiOrig = [],
  4723. aoColumns = settings.aoColumns,
  4724. aDataSort, iCol, sType, srcCol,
  4725. fixed = settings.aaSortingFixed,
  4726. fixedObj = $.isPlainObject(fixed),
  4727. nestedSort = [],
  4728. add = function (a) {
  4729. if (a.length && !Array.isArray(a[0])) {
  4730. // 1D array
  4731. nestedSort.push(a);
  4732. } else {
  4733. // 2D array
  4734. $.merge(nestedSort, a);
  4735. }
  4736. };
  4737. // Build the sort array, with pre-fix and post-fix options if they have been
  4738. // specified
  4739. if (Array.isArray(fixed)) {
  4740. add(fixed);
  4741. }
  4742. if (fixedObj && fixed.pre) {
  4743. add(fixed.pre);
  4744. }
  4745. add(settings.aaSorting);
  4746. if (fixedObj && fixed.post) {
  4747. add(fixed.post);
  4748. }
  4749. for (i = 0; i < nestedSort.length; i++) {
  4750. srcCol = nestedSort[i][0];
  4751. aDataSort = aoColumns[srcCol].aDataSort;
  4752. for (k = 0, kLen = aDataSort.length; k < kLen; k++) {
  4753. iCol = aDataSort[k];
  4754. sType = aoColumns[iCol].sType || 'string';
  4755. if (nestedSort[i]._idx === undefined) {
  4756. nestedSort[i]._idx = $.inArray(nestedSort[i][1], aoColumns[iCol].asSorting);
  4757. }
  4758. aSort.push({
  4759. src: srcCol,
  4760. col: iCol,
  4761. dir: nestedSort[i][1],
  4762. index: nestedSort[i]._idx,
  4763. type: sType,
  4764. formatter: DataTable.ext.type.order[sType + "-pre"]
  4765. });
  4766. }
  4767. }
  4768. return aSort;
  4769. }
  4770. /**
  4771. * Change the order of the table
  4772. * @param {object} oSettings dataTables settings object
  4773. * @memberof DataTable#oApi
  4774. * @todo This really needs split up!
  4775. */
  4776. function _fnSort(oSettings) {
  4777. var
  4778. i, ien, iLen, j, jLen, k, kLen,
  4779. sDataType, nTh,
  4780. aiOrig = [],
  4781. oExtSort = DataTable.ext.type.order,
  4782. aoData = oSettings.aoData,
  4783. aoColumns = oSettings.aoColumns,
  4784. aDataSort, data, iCol, sType, oSort,
  4785. formatters = 0,
  4786. sortCol,
  4787. displayMaster = oSettings.aiDisplayMaster,
  4788. aSort;
  4789. // Resolve any column types that are unknown due to addition or invalidation
  4790. // @todo Can this be moved into a 'data-ready' handler which is called when
  4791. // data is going to be used in the table?
  4792. _fnColumnTypes(oSettings);
  4793. aSort = _fnSortFlatten(oSettings);
  4794. for (i = 0, ien = aSort.length; i < ien; i++) {
  4795. sortCol = aSort[i];
  4796. // Track if we can use the fast sort algorithm
  4797. if (sortCol.formatter) {
  4798. formatters++;
  4799. }
  4800. // Load the data needed for the sort, for each cell
  4801. _fnSortData(oSettings, sortCol.col);
  4802. }
  4803. /* No sorting required if server-side or no sorting array */
  4804. if (_fnDataSource(oSettings) != 'ssp' && aSort.length !== 0) {
  4805. // Create a value - key array of the current row positions such that we can use their
  4806. // current position during the sort, if values match, in order to perform stable sorting
  4807. for (i = 0, iLen = displayMaster.length; i < iLen; i++) {
  4808. aiOrig[displayMaster[i]] = i;
  4809. }
  4810. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  4811. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  4812. * follow on it's own, but this is what we want (example two column sorting):
  4813. * fnLocalSorting = function(a,b){
  4814. * var iTest;
  4815. * iTest = oSort['string-asc']('data11', 'data12');
  4816. * if (iTest !== 0)
  4817. * return iTest;
  4818. * iTest = oSort['numeric-desc']('data21', 'data22');
  4819. * if (iTest !== 0)
  4820. * return iTest;
  4821. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  4822. * }
  4823. * Basically we have a test for each sorting column, if the data in that column is equal,
  4824. * test the next column. If all columns match, then we use a numeric sort on the row
  4825. * positions in the original data array to provide a stable sort.
  4826. *
  4827. * Note - I know it seems excessive to have two sorting methods, but the first is around
  4828. * 15% faster, so the second is only maintained for backwards compatibility with sorting
  4829. * methods which do not have a pre-sort formatting function.
  4830. */
  4831. if (formatters === aSort.length) {
  4832. // All sort types have formatting functions
  4833. displayMaster.sort(function (a, b) {
  4834. var
  4835. x, y, k, test, sort,
  4836. len = aSort.length,
  4837. dataA = aoData[a]._aSortData,
  4838. dataB = aoData[b]._aSortData;
  4839. for (k = 0; k < len; k++) {
  4840. sort = aSort[k];
  4841. x = dataA[sort.col];
  4842. y = dataB[sort.col];
  4843. test = x < y ? -1 : x > y ? 1 : 0;
  4844. if (test !== 0) {
  4845. return sort.dir === 'asc' ? test : -test;
  4846. }
  4847. }
  4848. x = aiOrig[a];
  4849. y = aiOrig[b];
  4850. return x < y ? -1 : x > y ? 1 : 0;
  4851. });
  4852. } else {
  4853. // Depreciated - remove in 1.11 (providing a plug-in option)
  4854. // Not all sort types have formatting methods, so we have to call their sorting
  4855. // methods.
  4856. displayMaster.sort(function (a, b) {
  4857. var
  4858. x, y, k, l, test, sort, fn,
  4859. len = aSort.length,
  4860. dataA = aoData[a]._aSortData,
  4861. dataB = aoData[b]._aSortData;
  4862. for (k = 0; k < len; k++) {
  4863. sort = aSort[k];
  4864. x = dataA[sort.col];
  4865. y = dataB[sort.col];
  4866. fn = oExtSort[sort.type + "-" + sort.dir] || oExtSort["string-" + sort.dir];
  4867. test = fn(x, y);
  4868. if (test !== 0) {
  4869. return test;
  4870. }
  4871. }
  4872. x = aiOrig[a];
  4873. y = aiOrig[b];
  4874. return x < y ? -1 : x > y ? 1 : 0;
  4875. });
  4876. }
  4877. }
  4878. /* Tell the draw function that we have sorted the data */
  4879. oSettings.bSorted = true;
  4880. }
  4881. function _fnSortAria(settings) {
  4882. var label;
  4883. var nextSort;
  4884. var columns = settings.aoColumns;
  4885. var aSort = _fnSortFlatten(settings);
  4886. var oAria = settings.oLanguage.oAria;
  4887. // ARIA attributes - need to loop all columns, to update all (removing old
  4888. // attributes as needed)
  4889. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  4890. var col = columns[i];
  4891. var asSorting = col.asSorting;
  4892. var sTitle = col.sTitle.replace(/<.*?>/g, "");
  4893. var th = col.nTh;
  4894. // IE7 is throwing an error when setting these properties with jQuery's
  4895. // attr() and removeAttr() methods...
  4896. th.removeAttribute('aria-sort');
  4897. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  4898. if (col.bSortable) {
  4899. if (aSort.length > 0 && aSort[0].col == i) {
  4900. th.setAttribute('aria-sort', aSort[0].dir == "asc" ? "ascending" : "descending");
  4901. nextSort = asSorting[aSort[0].index + 1] || asSorting[0];
  4902. } else {
  4903. nextSort = asSorting[0];
  4904. }
  4905. label = sTitle + (nextSort === "asc" ?
  4906. oAria.sSortAscending :
  4907. oAria.sSortDescending
  4908. );
  4909. } else {
  4910. label = sTitle;
  4911. }
  4912. th.setAttribute('aria-label', label);
  4913. }
  4914. }
  4915. /**
  4916. * Function to run on user sort request
  4917. * @param {object} settings dataTables settings object
  4918. * @param {node} attachTo node to attach the handler to
  4919. * @param {int} colIdx column sorting index
  4920. * @param {boolean} [append=false] Append the requested sort to the existing
  4921. * sort if true (i.e. multi-column sort)
  4922. * @param {function} [callback] callback function
  4923. * @memberof DataTable#oApi
  4924. */
  4925. function _fnSortListener(settings, colIdx, append, callback) {
  4926. var col = settings.aoColumns[colIdx];
  4927. var sorting = settings.aaSorting;
  4928. var asSorting = col.asSorting;
  4929. var nextSortIdx;
  4930. var next = function (a, overflow) {
  4931. var idx = a._idx;
  4932. if (idx === undefined) {
  4933. idx = $.inArray(a[1], asSorting);
  4934. }
  4935. return idx + 1 < asSorting.length ?
  4936. idx + 1 :
  4937. overflow ?
  4938. null :
  4939. 0;
  4940. };
  4941. // Convert to 2D array if needed
  4942. if (typeof sorting[0] === 'number') {
  4943. sorting = settings.aaSorting = [sorting];
  4944. }
  4945. // If appending the sort then we are multi-column sorting
  4946. if (append && settings.oFeatures.bSortMulti) {
  4947. // Are we already doing some kind of sort on this column?
  4948. var sortIdx = $.inArray(colIdx, _pluck(sorting, '0'));
  4949. if (sortIdx !== -1) {
  4950. // Yes, modify the sort
  4951. nextSortIdx = next(sorting[sortIdx], true);
  4952. if (nextSortIdx === null && sorting.length === 1) {
  4953. nextSortIdx = 0; // can't remove sorting completely
  4954. }
  4955. if (nextSortIdx === null) {
  4956. sorting.splice(sortIdx, 1);
  4957. } else {
  4958. sorting[sortIdx][1] = asSorting[nextSortIdx];
  4959. sorting[sortIdx]._idx = nextSortIdx;
  4960. }
  4961. } else {
  4962. // No sort on this column yet
  4963. sorting.push([colIdx, asSorting[0], 0]);
  4964. sorting[sorting.length - 1]._idx = 0;
  4965. }
  4966. } else if (sorting.length && sorting[0][0] == colIdx) {
  4967. // Single column - already sorting on this column, modify the sort
  4968. nextSortIdx = next(sorting[0]);
  4969. sorting.length = 1;
  4970. sorting[0][1] = asSorting[nextSortIdx];
  4971. sorting[0]._idx = nextSortIdx;
  4972. } else {
  4973. // Single column - sort only on this column
  4974. sorting.length = 0;
  4975. sorting.push([colIdx, asSorting[0]]);
  4976. sorting[0]._idx = 0;
  4977. }
  4978. // Run the sort by calling a full redraw
  4979. _fnReDraw(settings);
  4980. // callback used for async user interaction
  4981. if (typeof callback == 'function') {
  4982. callback(settings);
  4983. }
  4984. }
  4985. /**
  4986. * Attach a sort handler (click) to a node
  4987. * @param {object} settings dataTables settings object
  4988. * @param {node} attachTo node to attach the handler to
  4989. * @param {int} colIdx column sorting index
  4990. * @param {function} [callback] callback function
  4991. * @memberof DataTable#oApi
  4992. */
  4993. function _fnSortAttachListener(settings, attachTo, colIdx, callback) {
  4994. var col = settings.aoColumns[colIdx];
  4995. _fnBindAction(attachTo, {}, function (e) {
  4996. /* If the column is not sortable - don't to anything */
  4997. if (col.bSortable === false) {
  4998. return;
  4999. }
  5000. // If processing is enabled use a timeout to allow the processing
  5001. // display to be shown - otherwise to it synchronously
  5002. if (settings.oFeatures.bProcessing) {
  5003. _fnProcessingDisplay(settings, true);
  5004. setTimeout(function () {
  5005. _fnSortListener(settings, colIdx, e.shiftKey, callback);
  5006. // In server-side processing, the draw callback will remove the
  5007. // processing display
  5008. if (_fnDataSource(settings) !== 'ssp') {
  5009. _fnProcessingDisplay(settings, false);
  5010. }
  5011. }, 0);
  5012. } else {
  5013. _fnSortListener(settings, colIdx, e.shiftKey, callback);
  5014. }
  5015. });
  5016. }
  5017. /**
  5018. * Set the sorting classes on table's body, Note: it is safe to call this function
  5019. * when bSort and bSortClasses are false
  5020. * @param {object} oSettings dataTables settings object
  5021. * @memberof DataTable#oApi
  5022. */
  5023. function _fnSortingClasses(settings) {
  5024. var oldSort = settings.aLastSort;
  5025. var sortClass = settings.oClasses.sSortColumn;
  5026. var sort = _fnSortFlatten(settings);
  5027. var features = settings.oFeatures;
  5028. var i, ien, colIdx;
  5029. if (features.bSort && features.bSortClasses) {
  5030. // Remove old sorting classes
  5031. for (i = 0, ien = oldSort.length; i < ien; i++) {
  5032. colIdx = oldSort[i].src;
  5033. // Remove column sorting
  5034. $(_pluck(settings.aoData, 'anCells', colIdx))
  5035. .removeClass(sortClass + (i < 2 ? i + 1 : 3));
  5036. }
  5037. // Add new column sorting
  5038. for (i = 0, ien = sort.length; i < ien; i++) {
  5039. colIdx = sort[i].src;
  5040. $(_pluck(settings.aoData, 'anCells', colIdx))
  5041. .addClass(sortClass + (i < 2 ? i + 1 : 3));
  5042. }
  5043. }
  5044. settings.aLastSort = sort;
  5045. }
  5046. // Get the data to sort a column, be it from cache, fresh (populating the
  5047. // cache), or from a sort formatter
  5048. function _fnSortData(settings, idx) {
  5049. // Custom sorting function - provided by the sort data type
  5050. var column = settings.aoColumns[idx];
  5051. var customSort = DataTable.ext.order[column.sSortDataType];
  5052. var customData;
  5053. if (customSort) {
  5054. customData = customSort.call(settings.oInstance, settings, idx,
  5055. _fnColumnIndexToVisible(settings, idx)
  5056. );
  5057. }
  5058. // Use / populate cache
  5059. var row, cellData;
  5060. var formatter = DataTable.ext.type.order[column.sType + "-pre"];
  5061. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  5062. row = settings.aoData[i];
  5063. if (!row._aSortData) {
  5064. row._aSortData = [];
  5065. }
  5066. if (!row._aSortData[idx] || customSort) {
  5067. cellData = customSort ?
  5068. customData[i] : // If there was a custom sort function, use data from there
  5069. _fnGetCellData(settings, i, idx, 'sort');
  5070. row._aSortData[idx] = formatter ?
  5071. formatter(cellData) :
  5072. cellData;
  5073. }
  5074. }
  5075. }
  5076. /**
  5077. * Save the state of a table
  5078. * @param {object} oSettings dataTables settings object
  5079. * @memberof DataTable#oApi
  5080. */
  5081. function _fnSaveState(settings) {
  5082. if (!settings.oFeatures.bStateSave || settings.bDestroying) {
  5083. return;
  5084. }
  5085. /* Store the interesting variables */
  5086. var state = {
  5087. time: +new Date(),
  5088. start: settings._iDisplayStart,
  5089. length: settings._iDisplayLength,
  5090. order: $.extend(true, [], settings.aaSorting),
  5091. search: _fnSearchToCamel(settings.oPreviousSearch),
  5092. columns: $.map(settings.aoColumns, function (col, i) {
  5093. return {
  5094. visible: col.bVisible,
  5095. search: _fnSearchToCamel(settings.aoPreSearchCols[i])
  5096. };
  5097. })
  5098. };
  5099. _fnCallbackFire(settings, "aoStateSaveParams", 'stateSaveParams', [settings, state]);
  5100. settings.oSavedState = state;
  5101. settings.fnStateSaveCallback.call(settings.oInstance, settings, state);
  5102. }
  5103. /**
  5104. * Attempt to load a saved table state
  5105. * @param {object} oSettings dataTables settings object
  5106. * @param {object} oInit DataTables init object so we can override settings
  5107. * @param {function} callback Callback to execute when the state has been loaded
  5108. * @memberof DataTable#oApi
  5109. */
  5110. function _fnLoadState(settings, oInit, callback) {
  5111. var i, ien;
  5112. var columns = settings.aoColumns;
  5113. var loaded = function (s) {
  5114. if (!s || !s.time) {
  5115. callback();
  5116. return;
  5117. }
  5118. // Allow custom and plug-in manipulation functions to alter the saved data set and
  5119. // cancelling of loading by returning false
  5120. var abStateLoad = _fnCallbackFire(settings, 'aoStateLoadParams', 'stateLoadParams', [settings, s]);
  5121. if ($.inArray(false, abStateLoad) !== -1) {
  5122. callback();
  5123. return;
  5124. }
  5125. // Reject old data
  5126. var duration = settings.iStateDuration;
  5127. if (duration > 0 && s.time < +new Date() - (duration * 1000)) {
  5128. callback();
  5129. return;
  5130. }
  5131. // Number of columns have changed - all bets are off, no restore of settings
  5132. if (s.columns && columns.length !== s.columns.length) {
  5133. callback();
  5134. return;
  5135. }
  5136. // Store the saved state so it might be accessed at any time
  5137. settings.oLoadedState = $.extend(true, {}, s);
  5138. // Restore key features - todo - for 1.11 this needs to be done by
  5139. // subscribed events
  5140. if (s.start !== undefined) {
  5141. settings._iDisplayStart = s.start;
  5142. settings.iInitDisplayStart = s.start;
  5143. }
  5144. if (s.length !== undefined) {
  5145. settings._iDisplayLength = s.length;
  5146. }
  5147. // Order
  5148. if (s.order !== undefined) {
  5149. settings.aaSorting = [];
  5150. $.each(s.order, function (i, col) {
  5151. settings.aaSorting.push(col[0] >= columns.length ?
  5152. [0, col[1]] :
  5153. col
  5154. );
  5155. });
  5156. }
  5157. // Search
  5158. if (s.search !== undefined) {
  5159. $.extend(settings.oPreviousSearch, _fnSearchToHung(s.search));
  5160. }
  5161. // Columns
  5162. //
  5163. if (s.columns) {
  5164. for (i = 0, ien = s.columns.length; i < ien; i++) {
  5165. var col = s.columns[i];
  5166. // Visibility
  5167. if (col.visible !== undefined) {
  5168. columns[i].bVisible = col.visible;
  5169. }
  5170. // Search
  5171. if (col.search !== undefined) {
  5172. $.extend(settings.aoPreSearchCols[i], _fnSearchToHung(col.search));
  5173. }
  5174. }
  5175. }
  5176. _fnCallbackFire(settings, 'aoStateLoaded', 'stateLoaded', [settings, s]);
  5177. callback();
  5178. };
  5179. if (!settings.oFeatures.bStateSave) {
  5180. callback();
  5181. return;
  5182. }
  5183. var state = settings.fnStateLoadCallback.call(settings.oInstance, settings, loaded);
  5184. if (state !== undefined) {
  5185. loaded(state);
  5186. }
  5187. // otherwise, wait for the loaded callback to be executed
  5188. }
  5189. /**
  5190. * Return the settings object for a particular table
  5191. * @param {node} table table we are using as a dataTable
  5192. * @returns {object} Settings object - or null if not found
  5193. * @memberof DataTable#oApi
  5194. */
  5195. function _fnSettingsFromNode(table) {
  5196. var settings = DataTable.settings;
  5197. var idx = $.inArray(table, _pluck(settings, 'nTable'));
  5198. return idx !== -1 ?
  5199. settings[idx] :
  5200. null;
  5201. }
  5202. /**
  5203. * Log an error message
  5204. * @param {object} settings dataTables settings object
  5205. * @param {int} level log error messages, or display them to the user
  5206. * @param {string} msg error message
  5207. * @param {int} tn Technical note id to get more information about the error.
  5208. * @memberof DataTable#oApi
  5209. */
  5210. function _fnLog(settings, level, msg, tn) {
  5211. msg = 'DataTables warning: ' +
  5212. (settings ? 'table id=' + settings.sTableId + ' - ' : '') + msg;
  5213. if (tn) {
  5214. msg += '. For more information about this error, please see ' +
  5215. 'http://datatables.net/tn/' + tn;
  5216. }
  5217. if (!level) {
  5218. // Backwards compatibility pre 1.10
  5219. var ext = DataTable.ext;
  5220. var type = ext.sErrMode || ext.errMode;
  5221. if (settings) {
  5222. _fnCallbackFire(settings, null, 'error', [settings, tn, msg]);
  5223. }
  5224. if (type == 'alert') {
  5225. alert(msg);
  5226. } else if (type == 'throw') {
  5227. throw new Error(msg);
  5228. } else if (typeof type == 'function') {
  5229. type(settings, tn, msg);
  5230. }
  5231. } else if (window.console && console.log) {
  5232. console.log(msg);
  5233. }
  5234. }
  5235. /**
  5236. * See if a property is defined on one object, if so assign it to the other object
  5237. * @param {object} ret target object
  5238. * @param {object} src source object
  5239. * @param {string} name property
  5240. * @param {string} [mappedName] name to map too - optional, name used if not given
  5241. * @memberof DataTable#oApi
  5242. */
  5243. function _fnMap(ret, src, name, mappedName) {
  5244. if (Array.isArray(name)) {
  5245. $.each(name, function (i, val) {
  5246. if (Array.isArray(val)) {
  5247. _fnMap(ret, src, val[0], val[1]);
  5248. } else {
  5249. _fnMap(ret, src, val);
  5250. }
  5251. });
  5252. return;
  5253. }
  5254. if (mappedName === undefined) {
  5255. mappedName = name;
  5256. }
  5257. if (src[name] !== undefined) {
  5258. ret[mappedName] = src[name];
  5259. }
  5260. }
  5261. /**
  5262. * Extend objects - very similar to jQuery.extend, but deep copy objects, and
  5263. * shallow copy arrays. The reason we need to do this, is that we don't want to
  5264. * deep copy array init values (such as aaSorting) since the dev wouldn't be
  5265. * able to override them, but we do want to deep copy arrays.
  5266. * @param {object} out Object to extend
  5267. * @param {object} extender Object from which the properties will be applied to
  5268. * out
  5269. * @param {boolean} breakRefs If true, then arrays will be sliced to take an
  5270. * independent copy with the exception of the `data` or `aaData` parameters
  5271. * if they are present. This is so you can pass in a collection to
  5272. * DataTables and have that used as your data source without breaking the
  5273. * references
  5274. * @returns {object} out Reference, just for convenience - out === the return.
  5275. * @memberof DataTable#oApi
  5276. * @todo This doesn't take account of arrays inside the deep copied objects.
  5277. */
  5278. function _fnExtend(out, extender, breakRefs) {
  5279. var val;
  5280. for (var prop in extender) {
  5281. if (extender.hasOwnProperty(prop)) {
  5282. val = extender[prop];
  5283. if ($.isPlainObject(val)) {
  5284. if (!$.isPlainObject(out[prop])) {
  5285. out[prop] = {};
  5286. }
  5287. $.extend(true, out[prop], val);
  5288. } else if (breakRefs && prop !== 'data' && prop !== 'aaData' && Array.isArray(val)) {
  5289. out[prop] = val.slice();
  5290. } else {
  5291. out[prop] = val;
  5292. }
  5293. }
  5294. }
  5295. return out;
  5296. }
  5297. /**
  5298. * Bind an event handers to allow a click or return key to activate the callback.
  5299. * This is good for accessibility since a return on the keyboard will have the
  5300. * same effect as a click, if the element has focus.
  5301. * @param {element} n Element to bind the action to
  5302. * @param {object} oData Data object to pass to the triggered function
  5303. * @param {function} fn Callback function for when the event is triggered
  5304. * @memberof DataTable#oApi
  5305. */
  5306. function _fnBindAction(n, oData, fn) {
  5307. $(n)
  5308. .on('click.DT', oData, function (e) {
  5309. $(n).trigger('blur'); // Remove focus outline for mouse users
  5310. fn(e);
  5311. })
  5312. .on('keypress.DT', oData, function (e) {
  5313. if (e.which === 13) {
  5314. e.preventDefault();
  5315. fn(e);
  5316. }
  5317. })
  5318. .on('selectstart.DT', function () {
  5319. /* Take the brutal approach to cancelling text selection */
  5320. return false;
  5321. });
  5322. }
  5323. /**
  5324. * Register a callback function. Easily allows a callback function to be added to
  5325. * an array store of callback functions that can then all be called together.
  5326. * @param {object} oSettings dataTables settings object
  5327. * @param {string} sStore Name of the array storage for the callbacks in oSettings
  5328. * @param {function} fn Function to be called back
  5329. * @param {string} sName Identifying name for the callback (i.e. a label)
  5330. * @memberof DataTable#oApi
  5331. */
  5332. function _fnCallbackReg(oSettings, sStore, fn, sName) {
  5333. if (fn) {
  5334. oSettings[sStore].push({
  5335. "fn": fn,
  5336. "sName": sName
  5337. });
  5338. }
  5339. }
  5340. /**
  5341. * Fire callback functions and trigger events. Note that the loop over the
  5342. * callback array store is done backwards! Further note that you do not want to
  5343. * fire off triggers in time sensitive applications (for example cell creation)
  5344. * as its slow.
  5345. * @param {object} settings dataTables settings object
  5346. * @param {string} callbackArr Name of the array storage for the callbacks in
  5347. * oSettings
  5348. * @param {string} eventName Name of the jQuery custom event to trigger. If
  5349. * null no trigger is fired
  5350. * @param {array} args Array of arguments to pass to the callback function /
  5351. * trigger
  5352. * @memberof DataTable#oApi
  5353. */
  5354. function _fnCallbackFire(settings, callbackArr, eventName, args) {
  5355. var ret = [];
  5356. if (callbackArr) {
  5357. ret = $.map(settings[callbackArr].slice().reverse(), function (val, i) {
  5358. return val.fn.apply(settings.oInstance, args);
  5359. });
  5360. }
  5361. if (eventName !== null) {
  5362. var e = $.Event(eventName + '.dt');
  5363. $(settings.nTable).trigger(e, args);
  5364. ret.push(e.result);
  5365. }
  5366. return ret;
  5367. }
  5368. function _fnLengthOverflow(settings) {
  5369. var
  5370. start = settings._iDisplayStart,
  5371. end = settings.fnDisplayEnd(),
  5372. len = settings._iDisplayLength;
  5373. /* If we have space to show extra rows (backing up from the end point - then do so */
  5374. if (start >= end) {
  5375. start = end - len;
  5376. }
  5377. // Keep the start record on the current page
  5378. start -= (start % len);
  5379. if (len === -1 || start < 0) {
  5380. start = 0;
  5381. }
  5382. settings._iDisplayStart = start;
  5383. }
  5384. function _fnRenderer(settings, type) {
  5385. var renderer = settings.renderer;
  5386. var host = DataTable.ext.renderer[type];
  5387. if ($.isPlainObject(renderer) && renderer[type]) {
  5388. // Specific renderer for this type. If available use it, otherwise use
  5389. // the default.
  5390. return host[renderer[type]] || host._;
  5391. } else if (typeof renderer === 'string') {
  5392. // Common renderer - if there is one available for this type use it,
  5393. // otherwise use the default
  5394. return host[renderer] || host._;
  5395. }
  5396. // Use the default
  5397. return host._;
  5398. }
  5399. /**
  5400. * Detect the data source being used for the table. Used to simplify the code
  5401. * a little (ajax) and to make it compress a little smaller.
  5402. *
  5403. * @param {object} settings dataTables settings object
  5404. * @returns {string} Data source
  5405. * @memberof DataTable#oApi
  5406. */
  5407. function _fnDataSource(settings) {
  5408. if (settings.oFeatures.bServerSide) {
  5409. return 'ssp';
  5410. } else if (settings.ajax || settings.sAjaxSource) {
  5411. return 'ajax';
  5412. }
  5413. return 'dom';
  5414. }
  5415. /**
  5416. * Computed structure of the DataTables API, defined by the options passed to
  5417. * `DataTable.Api.register()` when building the API.
  5418. *
  5419. * The structure is built in order to speed creation and extension of the Api
  5420. * objects since the extensions are effectively pre-parsed.
  5421. *
  5422. * The array is an array of objects with the following structure, where this
  5423. * base array represents the Api prototype base:
  5424. *
  5425. * [
  5426. * {
  5427. * name: 'data' -- string - Property name
  5428. * val: function () {}, -- function - Api method (or undefined if just an object
  5429. * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  5430. * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  5431. * },
  5432. * {
  5433. * name: 'row'
  5434. * val: {},
  5435. * methodExt: [ ... ],
  5436. * propExt: [
  5437. * {
  5438. * name: 'data'
  5439. * val: function () {},
  5440. * methodExt: [ ... ],
  5441. * propExt: [ ... ]
  5442. * },
  5443. * ...
  5444. * ]
  5445. * }
  5446. * ]
  5447. *
  5448. * @type {Array}
  5449. * @ignore
  5450. */
  5451. var __apiStruct = [];
  5452. /**
  5453. * `Array.prototype` reference.
  5454. *
  5455. * @type object
  5456. * @ignore
  5457. */
  5458. var __arrayProto = Array.prototype;
  5459. /**
  5460. * Abstraction for `context` parameter of the `Api` constructor to allow it to
  5461. * take several different forms for ease of use.
  5462. *
  5463. * Each of the input parameter types will be converted to a DataTables settings
  5464. * object where possible.
  5465. *
  5466. * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
  5467. * of:
  5468. *
  5469. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5470. * with be found and used.
  5471. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5472. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5473. * * `object` - DataTables settings object
  5474. * * `DataTables.Api` - API instance
  5475. * @return {array|null} Matching DataTables settings objects. `null` or
  5476. * `undefined` is returned if no matching DataTable is found.
  5477. * @ignore
  5478. */
  5479. var _toSettings = function (mixed) {
  5480. var idx, jq;
  5481. var settings = DataTable.settings;
  5482. var tables = $.map(settings, function (el, i) {
  5483. return el.nTable;
  5484. });
  5485. if (!mixed) {
  5486. return [];
  5487. } else if (mixed.nTable && mixed.oApi) {
  5488. // DataTables settings object
  5489. return [mixed];
  5490. } else if (mixed.nodeName && mixed.nodeName.toLowerCase() === 'table') {
  5491. // Table node
  5492. idx = $.inArray(mixed, tables);
  5493. return idx !== -1 ? [settings[idx]] : null;
  5494. } else if (mixed && typeof mixed.settings === 'function') {
  5495. return mixed.settings().toArray();
  5496. } else if (typeof mixed === 'string') {
  5497. // jQuery selector
  5498. jq = $(mixed);
  5499. } else if (mixed instanceof $) {
  5500. // jQuery object (also DataTables instance)
  5501. jq = mixed;
  5502. }
  5503. if (jq) {
  5504. return jq.map(function (i) {
  5505. idx = $.inArray(this, tables);
  5506. return idx !== -1 ? settings[idx] : null;
  5507. }).toArray();
  5508. }
  5509. };
  5510. /**
  5511. * DataTables API class - used to control and interface with one or more
  5512. * DataTables enhanced tables.
  5513. *
  5514. * The API class is heavily based on jQuery, presenting a chainable interface
  5515. * that you can use to interact with tables. Each instance of the API class has
  5516. * a "context" - i.e. the tables that it will operate on. This could be a single
  5517. * table, all tables on a page or a sub-set thereof.
  5518. *
  5519. * Additionally the API is designed to allow you to easily work with the data in
  5520. * the tables, retrieving and manipulating it as required. This is done by
  5521. * presenting the API class as an array like interface. The contents of the
  5522. * array depend upon the actions requested by each method (for example
  5523. * `rows().nodes()` will return an array of nodes, while `rows().data()` will
  5524. * return an array of objects or arrays depending upon your table's
  5525. * configuration). The API object has a number of array like methods (`push`,
  5526. * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
  5527. * `unique` etc) to assist your working with the data held in a table.
  5528. *
  5529. * Most methods (those which return an Api instance) are chainable, which means
  5530. * the return from a method call also has all of the methods available that the
  5531. * top level object had. For example, these two calls are equivalent:
  5532. *
  5533. * // Not chained
  5534. * api.row.add( {...} );
  5535. * api.draw();
  5536. *
  5537. * // Chained
  5538. * api.row.add( {...} ).draw();
  5539. *
  5540. * @class DataTable.Api
  5541. * @param {array|object|string|jQuery} context DataTable identifier. This is
  5542. * used to define which DataTables enhanced tables this API will operate on.
  5543. * Can be one of:
  5544. *
  5545. * * `string` - jQuery selector. Any DataTables' matching the given selector
  5546. * with be found and used.
  5547. * * `node` - `TABLE` node which has already been formed into a DataTable.
  5548. * * `jQuery` - A jQuery object of `TABLE` nodes.
  5549. * * `object` - DataTables settings object
  5550. * @param {array} [data] Data to initialise the Api instance with.
  5551. *
  5552. * @example
  5553. * // Direct initialisation during DataTables construction
  5554. * var api = $('#example').DataTable();
  5555. *
  5556. * @example
  5557. * // Initialisation using a DataTables jQuery object
  5558. * var api = $('#example').dataTable().api();
  5559. *
  5560. * @example
  5561. * // Initialisation as a constructor
  5562. * var api = new $.fn.DataTable.Api( 'table.dataTable' );
  5563. */
  5564. _Api = function (context, data) {
  5565. if (!(this instanceof _Api)) {
  5566. return new _Api(context, data);
  5567. }
  5568. var settings = [];
  5569. var ctxSettings = function (o) {
  5570. var a = _toSettings(o);
  5571. if (a) {
  5572. settings.push.apply(settings, a);
  5573. }
  5574. };
  5575. if (Array.isArray(context)) {
  5576. for (var i = 0, ien = context.length; i < ien; i++) {
  5577. ctxSettings(context[i]);
  5578. }
  5579. } else {
  5580. ctxSettings(context);
  5581. }
  5582. // Remove duplicates
  5583. this.context = _unique(settings);
  5584. // Initial data
  5585. if (data) {
  5586. $.merge(this, data);
  5587. }
  5588. // selector
  5589. this.selector = {
  5590. rows: null,
  5591. cols: null,
  5592. opts: null
  5593. };
  5594. _Api.extend(this, this, __apiStruct);
  5595. };
  5596. DataTable.Api = _Api;
  5597. // Don't destroy the existing prototype, just extend it. Required for jQuery 2's
  5598. // isPlainObject.
  5599. $.extend(_Api.prototype, {
  5600. any: function () {
  5601. return this.count() !== 0;
  5602. },
  5603. concat: __arrayProto.concat,
  5604. context: [], // array of table settings objects
  5605. count: function () {
  5606. return this.flatten().length;
  5607. },
  5608. each: function (fn) {
  5609. for (var i = 0, ien = this.length; i < ien; i++) {
  5610. fn.call(this, this[i], i, this);
  5611. }
  5612. return this;
  5613. },
  5614. eq: function (idx) {
  5615. var ctx = this.context;
  5616. return ctx.length > idx ?
  5617. new _Api(ctx[idx], this[idx]) :
  5618. null;
  5619. },
  5620. filter: function (fn) {
  5621. var a = [];
  5622. if (__arrayProto.filter) {
  5623. a = __arrayProto.filter.call(this, fn, this);
  5624. } else {
  5625. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  5626. for (var i = 0, ien = this.length; i < ien; i++) {
  5627. if (fn.call(this, this[i], i, this)) {
  5628. a.push(this[i]);
  5629. }
  5630. }
  5631. }
  5632. return new _Api(this.context, a);
  5633. },
  5634. flatten: function () {
  5635. var a = [];
  5636. return new _Api(this.context, a.concat.apply(a, this.toArray()));
  5637. },
  5638. join: __arrayProto.join,
  5639. indexOf: __arrayProto.indexOf || function (obj, start) {
  5640. for (var i = (start || 0), ien = this.length; i < ien; i++) {
  5641. if (this[i] === obj) {
  5642. return i;
  5643. }
  5644. }
  5645. return -1;
  5646. },
  5647. iterator: function (flatten, type, fn, alwaysNew) {
  5648. var
  5649. a = [], ret,
  5650. i, ien, j, jen,
  5651. context = this.context,
  5652. rows, items, item,
  5653. selector = this.selector;
  5654. // Argument shifting
  5655. if (typeof flatten === 'string') {
  5656. alwaysNew = fn;
  5657. fn = type;
  5658. type = flatten;
  5659. flatten = false;
  5660. }
  5661. for (i = 0, ien = context.length; i < ien; i++) {
  5662. var apiInst = new _Api(context[i]);
  5663. if (type === 'table') {
  5664. ret = fn.call(apiInst, context[i], i);
  5665. if (ret !== undefined) {
  5666. a.push(ret);
  5667. }
  5668. } else if (type === 'columns' || type === 'rows') {
  5669. // this has same length as context - one entry for each table
  5670. ret = fn.call(apiInst, context[i], this[i], i);
  5671. if (ret !== undefined) {
  5672. a.push(ret);
  5673. }
  5674. } else if (type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell') {
  5675. // columns and rows share the same structure.
  5676. // 'this' is an array of column indexes for each context
  5677. items = this[i];
  5678. if (type === 'column-rows') {
  5679. rows = _selector_row_indexes(context[i], selector.opts);
  5680. }
  5681. for (j = 0, jen = items.length; j < jen; j++) {
  5682. item = items[j];
  5683. if (type === 'cell') {
  5684. ret = fn.call(apiInst, context[i], item.row, item.column, i, j);
  5685. } else {
  5686. ret = fn.call(apiInst, context[i], item, i, j, rows);
  5687. }
  5688. if (ret !== undefined) {
  5689. a.push(ret);
  5690. }
  5691. }
  5692. }
  5693. }
  5694. if (a.length || alwaysNew) {
  5695. var api = new _Api(context, flatten ? a.concat.apply([], a) : a);
  5696. var apiSelector = api.selector;
  5697. apiSelector.rows = selector.rows;
  5698. apiSelector.cols = selector.cols;
  5699. apiSelector.opts = selector.opts;
  5700. return api;
  5701. }
  5702. return this;
  5703. },
  5704. lastIndexOf: __arrayProto.lastIndexOf || function (obj, start) {
  5705. // Bit cheeky...
  5706. return this.indexOf.apply(this.toArray.reverse(), arguments);
  5707. },
  5708. length: 0,
  5709. map: function (fn) {
  5710. var a = [];
  5711. if (__arrayProto.map) {
  5712. a = __arrayProto.map.call(this, fn, this);
  5713. } else {
  5714. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  5715. for (var i = 0, ien = this.length; i < ien; i++) {
  5716. a.push(fn.call(this, this[i], i));
  5717. }
  5718. }
  5719. return new _Api(this.context, a);
  5720. },
  5721. pluck: function (prop) {
  5722. return this.map(function (el) {
  5723. return el[prop];
  5724. });
  5725. },
  5726. pop: __arrayProto.pop,
  5727. push: __arrayProto.push,
  5728. // Does not return an API instance
  5729. reduce: __arrayProto.reduce || function (fn, init) {
  5730. return _fnReduce(this, fn, init, 0, this.length, 1);
  5731. },
  5732. reduceRight: __arrayProto.reduceRight || function (fn, init) {
  5733. return _fnReduce(this, fn, init, this.length - 1, -1, -1);
  5734. },
  5735. reverse: __arrayProto.reverse,
  5736. // Object with rows, columns and opts
  5737. selector: null,
  5738. shift: __arrayProto.shift,
  5739. slice: function () {
  5740. return new _Api(this.context, this);
  5741. },
  5742. sort: __arrayProto.sort, // ? name - order?
  5743. splice: __arrayProto.splice,
  5744. toArray: function () {
  5745. return __arrayProto.slice.call(this);
  5746. },
  5747. to$: function () {
  5748. return $(this);
  5749. },
  5750. toJQuery: function () {
  5751. return $(this);
  5752. },
  5753. unique: function () {
  5754. return new _Api(this.context, _unique(this));
  5755. },
  5756. unshift: __arrayProto.unshift
  5757. });
  5758. _Api.extend = function (scope, obj, ext) {
  5759. // Only extend API instances and static properties of the API
  5760. if (!ext.length || !obj || (!(obj instanceof _Api) && !obj.__dt_wrapper)) {
  5761. return;
  5762. }
  5763. var
  5764. i, ien,
  5765. struct,
  5766. methodScoping = function (scope, fn, struc) {
  5767. return function () {
  5768. var ret = fn.apply(scope, arguments);
  5769. // Method extension
  5770. _Api.extend(ret, ret, struc.methodExt);
  5771. return ret;
  5772. };
  5773. };
  5774. for (i = 0, ien = ext.length; i < ien; i++) {
  5775. struct = ext[i];
  5776. // Value
  5777. obj[struct.name] = struct.type === 'function' ?
  5778. methodScoping(scope, struct.val, struct) :
  5779. struct.type === 'object' ?
  5780. {} :
  5781. struct.val;
  5782. obj[struct.name].__dt_wrapper = true;
  5783. // Property extension
  5784. _Api.extend(scope, obj[struct.name], struct.propExt);
  5785. }
  5786. };
  5787. // @todo - Is there need for an augment function?
  5788. // _Api.augment = function ( inst, name )
  5789. // {
  5790. // // Find src object in the structure from the name
  5791. // var parts = name.split('.');
  5792. // _Api.extend( inst, obj );
  5793. // };
  5794. // [
  5795. // {
  5796. // name: 'data' -- string - Property name
  5797. // val: function () {}, -- function - Api method (or undefined if just an object
  5798. // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  5799. // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  5800. // },
  5801. // {
  5802. // name: 'row'
  5803. // val: {},
  5804. // methodExt: [ ... ],
  5805. // propExt: [
  5806. // {
  5807. // name: 'data'
  5808. // val: function () {},
  5809. // methodExt: [ ... ],
  5810. // propExt: [ ... ]
  5811. // },
  5812. // ...
  5813. // ]
  5814. // }
  5815. // ]
  5816. _Api.register = _api_register = function (name, val) {
  5817. if (Array.isArray(name)) {
  5818. for (var j = 0, jen = name.length; j < jen; j++) {
  5819. _Api.register(name[j], val);
  5820. }
  5821. return;
  5822. }
  5823. var
  5824. i, ien,
  5825. heir = name.split('.'),
  5826. struct = __apiStruct,
  5827. key, method;
  5828. var find = function (src, name) {
  5829. for (var i = 0, ien = src.length; i < ien; i++) {
  5830. if (src[i].name === name) {
  5831. return src[i];
  5832. }
  5833. }
  5834. return null;
  5835. };
  5836. for (i = 0, ien = heir.length; i < ien; i++) {
  5837. method = heir[i].indexOf('()') !== -1;
  5838. key = method ?
  5839. heir[i].replace('()', '') :
  5840. heir[i];
  5841. var src = find(struct, key);
  5842. if (!src) {
  5843. src = {
  5844. name: key,
  5845. val: {},
  5846. methodExt: [],
  5847. propExt: [],
  5848. type: 'object'
  5849. };
  5850. struct.push(src);
  5851. }
  5852. if (i === ien - 1) {
  5853. src.val = val;
  5854. src.type = typeof val === 'function' ?
  5855. 'function' :
  5856. $.isPlainObject(val) ?
  5857. 'object' :
  5858. 'other';
  5859. } else {
  5860. struct = method ?
  5861. src.methodExt :
  5862. src.propExt;
  5863. }
  5864. }
  5865. };
  5866. _Api.registerPlural = _api_registerPlural = function (pluralName, singularName, val) {
  5867. _Api.register(pluralName, val);
  5868. _Api.register(singularName, function () {
  5869. var ret = val.apply(this, arguments);
  5870. if (ret === this) {
  5871. // Returned item is the API instance that was passed in, return it
  5872. return this;
  5873. } else if (ret instanceof _Api) {
  5874. // New API instance returned, want the value from the first item
  5875. // in the returned array for the singular result.
  5876. return ret.length ?
  5877. Array.isArray(ret[0]) ?
  5878. new _Api(ret.context, ret[0]) : // Array results are 'enhanced'
  5879. ret[0] :
  5880. undefined;
  5881. }
  5882. // Non-API return - just fire it back
  5883. return ret;
  5884. });
  5885. };
  5886. /**
  5887. * Selector for HTML tables. Apply the given selector to the give array of
  5888. * DataTables settings objects.
  5889. *
  5890. * @param {string|integer} [selector] jQuery selector string or integer
  5891. * @param {array} Array of DataTables settings objects to be filtered
  5892. * @return {array}
  5893. * @ignore
  5894. */
  5895. var __table_selector = function (selector, a) {
  5896. if (Array.isArray(selector)) {
  5897. return $.map(selector, function (item) {
  5898. return __table_selector(item, a);
  5899. });
  5900. }
  5901. // Integer is used to pick out a table by index
  5902. if (typeof selector === 'number') {
  5903. return [a[selector]];
  5904. }
  5905. // Perform a jQuery selector on the table nodes
  5906. var nodes = $.map(a, function (el, i) {
  5907. return el.nTable;
  5908. });
  5909. return $(nodes)
  5910. .filter(selector)
  5911. .map(function (i) {
  5912. // Need to translate back from the table node to the settings
  5913. var idx = $.inArray(this, nodes);
  5914. return a[idx];
  5915. })
  5916. .toArray();
  5917. };
  5918. /**
  5919. * Context selector for the API's context (i.e. the tables the API instance
  5920. * refers to.
  5921. *
  5922. * @name DataTable.Api#tables
  5923. * @param {string|integer} [selector] Selector to pick which tables the iterator
  5924. * should operate on. If not given, all tables in the current context are
  5925. * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
  5926. * select multiple tables or as an integer to select a single table.
  5927. * @returns {DataTable.Api} Returns a new API instance if a selector is given.
  5928. */
  5929. _api_register('tables()', function (selector) {
  5930. // A new instance is created if there was a selector specified
  5931. return selector !== undefined && selector !== null ?
  5932. new _Api(__table_selector(selector, this.context)) :
  5933. this;
  5934. });
  5935. _api_register('table()', function (selector) {
  5936. var tables = this.tables(selector);
  5937. var ctx = tables.context;
  5938. // Truncate to the first matched table
  5939. return ctx.length ?
  5940. new _Api(ctx[0]) :
  5941. tables;
  5942. });
  5943. _api_registerPlural('tables().nodes()', 'table().node()', function () {
  5944. return this.iterator('table', function (ctx) {
  5945. return ctx.nTable;
  5946. }, 1);
  5947. });
  5948. _api_registerPlural('tables().body()', 'table().body()', function () {
  5949. return this.iterator('table', function (ctx) {
  5950. return ctx.nTBody;
  5951. }, 1);
  5952. });
  5953. _api_registerPlural('tables().header()', 'table().header()', function () {
  5954. return this.iterator('table', function (ctx) {
  5955. return ctx.nTHead;
  5956. }, 1);
  5957. });
  5958. _api_registerPlural('tables().footer()', 'table().footer()', function () {
  5959. return this.iterator('table', function (ctx) {
  5960. return ctx.nTFoot;
  5961. }, 1);
  5962. });
  5963. _api_registerPlural('tables().containers()', 'table().container()', function () {
  5964. return this.iterator('table', function (ctx) {
  5965. return ctx.nTableWrapper;
  5966. }, 1);
  5967. });
  5968. /**
  5969. * Redraw the tables in the current context.
  5970. */
  5971. _api_register('draw()', function (paging) {
  5972. return this.iterator('table', function (settings) {
  5973. if (paging === 'page') {
  5974. _fnDraw(settings);
  5975. } else {
  5976. if (typeof paging === 'string') {
  5977. paging = paging === 'full-hold' ?
  5978. false :
  5979. true;
  5980. }
  5981. _fnReDraw(settings, paging === false);
  5982. }
  5983. });
  5984. });
  5985. /**
  5986. * Get the current page index.
  5987. *
  5988. * @return {integer} Current page index (zero based)
  5989. */
  5990. /**
  5991. * Set the current page.
  5992. *
  5993. * Note that if you attempt to show a page which does not exist, DataTables will
  5994. * not throw an error, but rather reset the paging.
  5995. *
  5996. * @param {integer|string} action The paging action to take. This can be one of:
  5997. * * `integer` - The page index to jump to
  5998. * * `string` - An action to take:
  5999. * * `first` - Jump to first page.
  6000. * * `next` - Jump to the next page
  6001. * * `previous` - Jump to previous page
  6002. * * `last` - Jump to the last page.
  6003. * @returns {DataTables.Api} this
  6004. */
  6005. _api_register('page()', function (action) {
  6006. if (action === undefined) {
  6007. return this.page.info().page; // not an expensive call
  6008. }
  6009. // else, have an action to take on all tables
  6010. return this.iterator('table', function (settings) {
  6011. _fnPageChange(settings, action);
  6012. });
  6013. });
  6014. /**
  6015. * Paging information for the first table in the current context.
  6016. *
  6017. * If you require paging information for another table, use the `table()` method
  6018. * with a suitable selector.
  6019. *
  6020. * @return {object} Object with the following properties set:
  6021. * * `page` - Current page index (zero based - i.e. the first page is `0`)
  6022. * * `pages` - Total number of pages
  6023. * * `start` - Display index for the first record shown on the current page
  6024. * * `end` - Display index for the last record shown on the current page
  6025. * * `length` - Display length (number of records). Note that generally `start
  6026. * + length = end`, but this is not always true, for example if there are
  6027. * only 2 records to show on the final page, with a length of 10.
  6028. * * `recordsTotal` - Full data set length
  6029. * * `recordsDisplay` - Data set length once the current filtering criterion
  6030. * are applied.
  6031. */
  6032. _api_register('page.info()', function (action) {
  6033. if (this.context.length === 0) {
  6034. return undefined;
  6035. }
  6036. var
  6037. settings = this.context[0],
  6038. start = settings._iDisplayStart,
  6039. len = settings.oFeatures.bPaginate ? settings._iDisplayLength : -1,
  6040. visRecords = settings.fnRecordsDisplay(),
  6041. all = len === -1;
  6042. return {
  6043. "page": all ? 0 : Math.floor(start / len),
  6044. "pages": all ? 1 : Math.ceil(visRecords / len),
  6045. "start": start,
  6046. "end": settings.fnDisplayEnd(),
  6047. "length": len,
  6048. "recordsTotal": settings.fnRecordsTotal(),
  6049. "recordsDisplay": visRecords,
  6050. "serverSide": _fnDataSource(settings) === 'ssp'
  6051. };
  6052. });
  6053. /**
  6054. * Get the current page length.
  6055. *
  6056. * @return {integer} Current page length. Note `-1` indicates that all records
  6057. * are to be shown.
  6058. */
  6059. /**
  6060. * Set the current page length.
  6061. *
  6062. * @param {integer} Page length to set. Use `-1` to show all records.
  6063. * @returns {DataTables.Api} this
  6064. */
  6065. _api_register('page.len()', function (len) {
  6066. // Note that we can't call this function 'length()' because `length`
  6067. // is a Javascript property of functions which defines how many arguments
  6068. // the function expects.
  6069. if (len === undefined) {
  6070. return this.context.length !== 0 ?
  6071. this.context[0]._iDisplayLength :
  6072. undefined;
  6073. }
  6074. // else, set the page length
  6075. return this.iterator('table', function (settings) {
  6076. _fnLengthChange(settings, len);
  6077. });
  6078. });
  6079. var __reload = function (settings, holdPosition, callback) {
  6080. // Use the draw event to trigger a callback
  6081. if (callback) {
  6082. var api = new _Api(settings);
  6083. api.one('draw', function () {
  6084. callback(api.ajax.json());
  6085. });
  6086. }
  6087. if (_fnDataSource(settings) == 'ssp') {
  6088. _fnReDraw(settings, holdPosition);
  6089. } else {
  6090. _fnProcessingDisplay(settings, true);
  6091. // Cancel an existing request
  6092. var xhr = settings.jqXHR;
  6093. if (xhr && xhr.readyState !== 4) {
  6094. xhr.abort();
  6095. }
  6096. // Trigger xhr
  6097. _fnBuildAjax(settings, [], function (json) {
  6098. _fnClearTable(settings);
  6099. var data = _fnAjaxDataSrc(settings, json);
  6100. for (var i = 0, ien = data.length; i < ien; i++) {
  6101. _fnAddData(settings, data[i]);
  6102. }
  6103. _fnReDraw(settings, holdPosition);
  6104. _fnProcessingDisplay(settings, false);
  6105. });
  6106. }
  6107. };
  6108. /**
  6109. * Get the JSON response from the last Ajax request that DataTables made to the
  6110. * server. Note that this returns the JSON from the first table in the current
  6111. * context.
  6112. *
  6113. * @return {object} JSON received from the server.
  6114. */
  6115. _api_register('ajax.json()', function () {
  6116. var ctx = this.context;
  6117. if (ctx.length > 0) {
  6118. return ctx[0].json;
  6119. }
  6120. // else return undefined;
  6121. });
  6122. /**
  6123. * Get the data submitted in the last Ajax request
  6124. */
  6125. _api_register('ajax.params()', function () {
  6126. var ctx = this.context;
  6127. if (ctx.length > 0) {
  6128. return ctx[0].oAjaxData;
  6129. }
  6130. // else return undefined;
  6131. });
  6132. /**
  6133. * Reload tables from the Ajax data source. Note that this function will
  6134. * automatically re-draw the table when the remote data has been loaded.
  6135. *
  6136. * @param {boolean} [reset=true] Reset (default) or hold the current paging
  6137. * position. A full re-sort and re-filter is performed when this method is
  6138. * called, which is why the pagination reset is the default action.
  6139. * @returns {DataTables.Api} this
  6140. */
  6141. _api_register('ajax.reload()', function (callback, resetPaging) {
  6142. return this.iterator('table', function (settings) {
  6143. __reload(settings, resetPaging === false, callback);
  6144. });
  6145. });
  6146. /**
  6147. * Get the current Ajax URL. Note that this returns the URL from the first
  6148. * table in the current context.
  6149. *
  6150. * @return {string} Current Ajax source URL
  6151. */
  6152. /**
  6153. * Set the Ajax URL. Note that this will set the URL for all tables in the
  6154. * current context.
  6155. *
  6156. * @param {string} url URL to set.
  6157. * @returns {DataTables.Api} this
  6158. */
  6159. _api_register('ajax.url()', function (url) {
  6160. var ctx = this.context;
  6161. if (url === undefined) {
  6162. // get
  6163. if (ctx.length === 0) {
  6164. return undefined;
  6165. }
  6166. ctx = ctx[0];
  6167. return ctx.ajax ?
  6168. $.isPlainObject(ctx.ajax) ?
  6169. ctx.ajax.url :
  6170. ctx.ajax :
  6171. ctx.sAjaxSource;
  6172. }
  6173. // set
  6174. return this.iterator('table', function (settings) {
  6175. if ($.isPlainObject(settings.ajax)) {
  6176. settings.ajax.url = url;
  6177. } else {
  6178. settings.ajax = url;
  6179. }
  6180. // No need to consider sAjaxSource here since DataTables gives priority
  6181. // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
  6182. // value of `sAjaxSource` redundant.
  6183. });
  6184. });
  6185. /**
  6186. * Load data from the newly set Ajax URL. Note that this method is only
  6187. * available when `ajax.url()` is used to set a URL. Additionally, this method
  6188. * has the same effect as calling `ajax.reload()` but is provided for
  6189. * convenience when setting a new URL. Like `ajax.reload()` it will
  6190. * automatically redraw the table once the remote data has been loaded.
  6191. *
  6192. * @returns {DataTables.Api} this
  6193. */
  6194. _api_register('ajax.url().load()', function (callback, resetPaging) {
  6195. // Same as a reload, but makes sense to present it for easy access after a
  6196. // url change
  6197. return this.iterator('table', function (ctx) {
  6198. __reload(ctx, resetPaging === false, callback);
  6199. });
  6200. });
  6201. var _selector_run = function (type, selector, selectFn, settings, opts) {
  6202. var
  6203. out = [], res,
  6204. a, i, ien, j, jen,
  6205. selectorType = typeof selector;
  6206. // Can't just check for isArray here, as an API or jQuery instance might be
  6207. // given with their array like look
  6208. if (!selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined) {
  6209. selector = [selector];
  6210. }
  6211. for (i = 0, ien = selector.length; i < ien; i++) {
  6212. // Only split on simple strings - complex expressions will be jQuery selectors
  6213. a = selector[i] && selector[i].split && !selector[i].match(/[\[\(:]/) ?
  6214. selector[i].split(',') :
  6215. [selector[i]];
  6216. for (j = 0, jen = a.length; j < jen; j++) {
  6217. res = selectFn(typeof a[j] === 'string' ? (a[j]).trim() : a[j]);
  6218. if (res && res.length) {
  6219. out = out.concat(res);
  6220. }
  6221. }
  6222. }
  6223. // selector extensions
  6224. var ext = _ext.selector[type];
  6225. if (ext.length) {
  6226. for (i = 0, ien = ext.length; i < ien; i++) {
  6227. out = ext[i](settings, opts, out);
  6228. }
  6229. }
  6230. return _unique(out);
  6231. };
  6232. var _selector_opts = function (opts) {
  6233. if (!opts) {
  6234. opts = {};
  6235. }
  6236. // Backwards compatibility for 1.9- which used the terminology filter rather
  6237. // than search
  6238. if (opts.filter && opts.search === undefined) {
  6239. opts.search = opts.filter;
  6240. }
  6241. return $.extend({
  6242. search: 'none',
  6243. order: 'current',
  6244. page: 'all'
  6245. }, opts);
  6246. };
  6247. var _selector_first = function (inst) {
  6248. // Reduce the API instance to the first item found
  6249. for (var i = 0, ien = inst.length; i < ien; i++) {
  6250. if (inst[i].length > 0) {
  6251. // Assign the first element to the first item in the instance
  6252. // and truncate the instance and context
  6253. inst[0] = inst[i];
  6254. inst[0].length = 1;
  6255. inst.length = 1;
  6256. inst.context = [inst.context[i]];
  6257. return inst;
  6258. }
  6259. }
  6260. // Not found - return an empty instance
  6261. inst.length = 0;
  6262. return inst;
  6263. };
  6264. var _selector_row_indexes = function (settings, opts) {
  6265. var
  6266. i, ien, tmp, a = [],
  6267. displayFiltered = settings.aiDisplay,
  6268. displayMaster = settings.aiDisplayMaster;
  6269. var
  6270. search = opts.search, // none, applied, removed
  6271. order = opts.order, // applied, current, index (original - compatibility with 1.9)
  6272. page = opts.page; // all, current
  6273. if (_fnDataSource(settings) == 'ssp') {
  6274. // In server-side processing mode, most options are irrelevant since
  6275. // rows not shown don't exist and the index order is the applied order
  6276. // Removed is a special case - for consistency just return an empty
  6277. // array
  6278. return search === 'removed' ?
  6279. [] :
  6280. _range(0, displayMaster.length);
  6281. } else if (page == 'current') {
  6282. // Current page implies that order=current and fitler=applied, since it is
  6283. // fairly senseless otherwise, regardless of what order and search actually
  6284. // are
  6285. for (i = settings._iDisplayStart, ien = settings.fnDisplayEnd(); i < ien; i++) {
  6286. a.push(displayFiltered[i]);
  6287. }
  6288. } else if (order == 'current' || order == 'applied') {
  6289. if (search == 'none') {
  6290. a = displayMaster.slice();
  6291. } else if (search == 'applied') {
  6292. a = displayFiltered.slice();
  6293. } else if (search == 'removed') {
  6294. // O(n+m) solution by creating a hash map
  6295. var displayFilteredMap = {};
  6296. for (var i = 0, ien = displayFiltered.length; i < ien; i++) {
  6297. displayFilteredMap[displayFiltered[i]] = null;
  6298. }
  6299. a = $.map(displayMaster, function (el) {
  6300. return !displayFilteredMap.hasOwnProperty(el) ?
  6301. el :
  6302. null;
  6303. });
  6304. }
  6305. } else if (order == 'index' || order == 'original') {
  6306. for (i = 0, ien = settings.aoData.length; i < ien; i++) {
  6307. if (search == 'none') {
  6308. a.push(i);
  6309. } else { // applied | removed
  6310. tmp = $.inArray(i, displayFiltered);
  6311. if ((tmp === -1 && search == 'removed') ||
  6312. (tmp >= 0 && search == 'applied')) {
  6313. a.push(i);
  6314. }
  6315. }
  6316. }
  6317. }
  6318. return a;
  6319. };
  6320. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  6321. * Rows
  6322. *
  6323. * {} - no selector - use all available rows
  6324. * {integer} - row aoData index
  6325. * {node} - TR node
  6326. * {string} - jQuery selector to apply to the TR elements
  6327. * {array} - jQuery array of nodes, or simply an array of TR nodes
  6328. *
  6329. */
  6330. var __row_selector = function (settings, selector, opts) {
  6331. var rows;
  6332. var run = function (sel) {
  6333. var selInt = _intVal(sel);
  6334. var i, ien;
  6335. var aoData = settings.aoData;
  6336. // Short cut - selector is a number and no options provided (default is
  6337. // all records, so no need to check if the index is in there, since it
  6338. // must be - dev error if the index doesn't exist).
  6339. if (selInt !== null && !opts) {
  6340. return [selInt];
  6341. }
  6342. if (!rows) {
  6343. rows = _selector_row_indexes(settings, opts);
  6344. }
  6345. if (selInt !== null && $.inArray(selInt, rows) !== -1) {
  6346. // Selector - integer
  6347. return [selInt];
  6348. } else if (sel === null || sel === undefined || sel === '') {
  6349. // Selector - none
  6350. return rows;
  6351. }
  6352. // Selector - function
  6353. if (typeof sel === 'function') {
  6354. return $.map(rows, function (idx) {
  6355. var row = aoData[idx];
  6356. return sel(idx, row._aData, row.nTr) ? idx : null;
  6357. });
  6358. }
  6359. // Selector - node
  6360. if (sel.nodeName) {
  6361. var rowIdx = sel._DT_RowIndex; // Property added by DT for fast lookup
  6362. var cellIdx = sel._DT_CellIndex;
  6363. if (rowIdx !== undefined) {
  6364. // Make sure that the row is actually still present in the table
  6365. return aoData[rowIdx] && aoData[rowIdx].nTr === sel ?
  6366. [rowIdx] :
  6367. [];
  6368. } else if (cellIdx) {
  6369. return aoData[cellIdx.row] && aoData[cellIdx.row].nTr === sel.parentNode ?
  6370. [cellIdx.row] :
  6371. [];
  6372. } else {
  6373. var host = $(sel).closest('*[data-dt-row]');
  6374. return host.length ?
  6375. [host.data('dt-row')] :
  6376. [];
  6377. }
  6378. }
  6379. // ID selector. Want to always be able to select rows by id, regardless
  6380. // of if the tr element has been created or not, so can't rely upon
  6381. // jQuery here - hence a custom implementation. This does not match
  6382. // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
  6383. // but to select it using a CSS selector engine (like Sizzle or
  6384. // querySelect) it would need to need to be escaped for some characters.
  6385. // DataTables simplifies this for row selectors since you can select
  6386. // only a row. A # indicates an id any anything that follows is the id -
  6387. // unescaped.
  6388. if (typeof sel === 'string' && sel.charAt(0) === '#') {
  6389. // get row index from id
  6390. var rowObj = settings.aIds[sel.replace(/^#/, '')];
  6391. if (rowObj !== undefined) {
  6392. return [rowObj.idx];
  6393. }
  6394. // need to fall through to jQuery in case there is DOM id that
  6395. // matches
  6396. }
  6397. // Get nodes in the order from the `rows` array with null values removed
  6398. var nodes = _removeEmpty(
  6399. _pluck_order(settings.aoData, rows, 'nTr')
  6400. );
  6401. // Selector - jQuery selector string, array of nodes or jQuery object/
  6402. // As jQuery's .filter() allows jQuery objects to be passed in filter,
  6403. // it also allows arrays, so this will cope with all three options
  6404. return $(nodes)
  6405. .filter(sel)
  6406. .map(function () {
  6407. return this._DT_RowIndex;
  6408. })
  6409. .toArray();
  6410. };
  6411. return _selector_run('row', selector, run, settings, opts);
  6412. };
  6413. _api_register('rows()', function (selector, opts) {
  6414. // argument shifting
  6415. if (selector === undefined) {
  6416. selector = '';
  6417. } else if ($.isPlainObject(selector)) {
  6418. opts = selector;
  6419. selector = '';
  6420. }
  6421. opts = _selector_opts(opts);
  6422. var inst = this.iterator('table', function (settings) {
  6423. return __row_selector(settings, selector, opts);
  6424. }, 1);
  6425. // Want argument shifting here and in __row_selector?
  6426. inst.selector.rows = selector;
  6427. inst.selector.opts = opts;
  6428. return inst;
  6429. });
  6430. _api_register('rows().nodes()', function () {
  6431. return this.iterator('row', function (settings, row) {
  6432. return settings.aoData[row].nTr || undefined;
  6433. }, 1);
  6434. });
  6435. _api_register('rows().data()', function () {
  6436. return this.iterator(true, 'rows', function (settings, rows) {
  6437. return _pluck_order(settings.aoData, rows, '_aData');
  6438. }, 1);
  6439. });
  6440. _api_registerPlural('rows().cache()', 'row().cache()', function (type) {
  6441. return this.iterator('row', function (settings, row) {
  6442. var r = settings.aoData[row];
  6443. return type === 'search' ? r._aFilterData : r._aSortData;
  6444. }, 1);
  6445. });
  6446. _api_registerPlural('rows().invalidate()', 'row().invalidate()', function (src) {
  6447. return this.iterator('row', function (settings, row) {
  6448. _fnInvalidate(settings, row, src);
  6449. });
  6450. });
  6451. _api_registerPlural('rows().indexes()', 'row().index()', function () {
  6452. return this.iterator('row', function (settings, row) {
  6453. return row;
  6454. }, 1);
  6455. });
  6456. _api_registerPlural('rows().ids()', 'row().id()', function (hash) {
  6457. var a = [];
  6458. var context = this.context;
  6459. // `iterator` will drop undefined values, but in this case we want them
  6460. for (var i = 0, ien = context.length; i < ien; i++) {
  6461. for (var j = 0, jen = this[i].length; j < jen; j++) {
  6462. var id = context[i].rowIdFn(context[i].aoData[this[i][j]]._aData);
  6463. a.push((hash === true ? '#' : '') + id);
  6464. }
  6465. }
  6466. return new _Api(context, a);
  6467. });
  6468. _api_registerPlural('rows().remove()', 'row().remove()', function () {
  6469. var that = this;
  6470. this.iterator('row', function (settings, row, thatIdx) {
  6471. var data = settings.aoData;
  6472. var rowData = data[row];
  6473. var i, ien, j, jen;
  6474. var loopRow, loopCells;
  6475. data.splice(row, 1);
  6476. // Update the cached indexes
  6477. for (i = 0, ien = data.length; i < ien; i++) {
  6478. loopRow = data[i];
  6479. loopCells = loopRow.anCells;
  6480. // Rows
  6481. if (loopRow.nTr !== null) {
  6482. loopRow.nTr._DT_RowIndex = i;
  6483. }
  6484. // Cells
  6485. if (loopCells !== null) {
  6486. for (j = 0, jen = loopCells.length; j < jen; j++) {
  6487. loopCells[j]._DT_CellIndex.row = i;
  6488. }
  6489. }
  6490. }
  6491. // Delete from the display arrays
  6492. _fnDeleteIndex(settings.aiDisplayMaster, row);
  6493. _fnDeleteIndex(settings.aiDisplay, row);
  6494. _fnDeleteIndex(that[thatIdx], row, false); // maintain local indexes
  6495. // For server-side processing tables - subtract the deleted row from the count
  6496. if (settings._iRecordsDisplay > 0) {
  6497. settings._iRecordsDisplay--;
  6498. }
  6499. // Check for an 'overflow' they case for displaying the table
  6500. _fnLengthOverflow(settings);
  6501. // Remove the row's ID reference if there is one
  6502. var id = settings.rowIdFn(rowData._aData);
  6503. if (id !== undefined) {
  6504. delete settings.aIds[id];
  6505. }
  6506. });
  6507. this.iterator('table', function (settings) {
  6508. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  6509. settings.aoData[i].idx = i;
  6510. }
  6511. });
  6512. return this;
  6513. });
  6514. _api_register('rows.add()', function (rows) {
  6515. var newRows = this.iterator('table', function (settings) {
  6516. var row, i, ien;
  6517. var out = [];
  6518. for (i = 0, ien = rows.length; i < ien; i++) {
  6519. row = rows[i];
  6520. if (row.nodeName && row.nodeName.toUpperCase() === 'TR') {
  6521. out.push(_fnAddTr(settings, row)[0]);
  6522. } else {
  6523. out.push(_fnAddData(settings, row));
  6524. }
  6525. }
  6526. return out;
  6527. }, 1);
  6528. // Return an Api.rows() extended instance, so rows().nodes() etc can be used
  6529. var modRows = this.rows(-1);
  6530. modRows.pop();
  6531. $.merge(modRows, newRows);
  6532. return modRows;
  6533. });
  6534. /**
  6535. *
  6536. */
  6537. _api_register('row()', function (selector, opts) {
  6538. return _selector_first(this.rows(selector, opts));
  6539. });
  6540. _api_register('row().data()', function (data) {
  6541. var ctx = this.context;
  6542. if (data === undefined) {
  6543. // Get
  6544. return ctx.length && this.length ?
  6545. ctx[0].aoData[this[0]]._aData :
  6546. undefined;
  6547. }
  6548. // Set
  6549. var row = ctx[0].aoData[this[0]];
  6550. row._aData = data;
  6551. // If the DOM has an id, and the data source is an array
  6552. if (Array.isArray(data) && row.nTr && row.nTr.id) {
  6553. _fnSetObjectDataFn(ctx[0].rowId)(data, row.nTr.id);
  6554. }
  6555. // Automatically invalidate
  6556. _fnInvalidate(ctx[0], this[0], 'data');
  6557. return this;
  6558. });
  6559. _api_register('row().node()', function () {
  6560. var ctx = this.context;
  6561. return ctx.length && this.length ?
  6562. ctx[0].aoData[this[0]].nTr || null :
  6563. null;
  6564. });
  6565. _api_register('row.add()', function (row) {
  6566. // Allow a jQuery object to be passed in - only a single row is added from
  6567. // it though - the first element in the set
  6568. if (row instanceof $ && row.length) {
  6569. row = row[0];
  6570. }
  6571. var rows = this.iterator('table', function (settings) {
  6572. if (row.nodeName && row.nodeName.toUpperCase() === 'TR') {
  6573. return _fnAddTr(settings, row)[0];
  6574. }
  6575. return _fnAddData(settings, row);
  6576. });
  6577. // Return an Api.rows() extended instance, with the newly added row selected
  6578. return this.row(rows[0]);
  6579. });
  6580. var __details_add = function (ctx, row, data, klass) {
  6581. // Convert to array of TR elements
  6582. var rows = [];
  6583. var addRow = function (r, k) {
  6584. // Recursion to allow for arrays of jQuery objects
  6585. if (Array.isArray(r) || r instanceof $) {
  6586. for (var i = 0, ien = r.length; i < ien; i++) {
  6587. addRow(r[i], k);
  6588. }
  6589. return;
  6590. }
  6591. // If we get a TR element, then just add it directly - up to the dev
  6592. // to add the correct number of columns etc
  6593. if (r.nodeName && r.nodeName.toLowerCase() === 'tr') {
  6594. rows.push(r);
  6595. } else {
  6596. // Otherwise create a row with a wrapper
  6597. var created = $('<tr><td></td></tr>').addClass(k);
  6598. $('td', created)
  6599. .addClass(k)
  6600. .html(r)
  6601. [0].colSpan = _fnVisbleColumns(ctx);
  6602. rows.push(created[0]);
  6603. }
  6604. };
  6605. addRow(data, klass);
  6606. if (row._details) {
  6607. row._details.detach();
  6608. }
  6609. row._details = $(rows);
  6610. // If the children were already shown, that state should be retained
  6611. if (row._detailsShow) {
  6612. row._details.insertAfter(row.nTr);
  6613. }
  6614. };
  6615. var __details_remove = function (api, idx) {
  6616. var ctx = api.context;
  6617. if (ctx.length) {
  6618. var row = ctx[0].aoData[idx !== undefined ? idx : api[0]];
  6619. if (row && row._details) {
  6620. row._details.remove();
  6621. row._detailsShow = undefined;
  6622. row._details = undefined;
  6623. }
  6624. }
  6625. };
  6626. var __details_display = function (api, show) {
  6627. var ctx = api.context;
  6628. if (ctx.length && api.length) {
  6629. var row = ctx[0].aoData[api[0]];
  6630. if (row._details) {
  6631. row._detailsShow = show;
  6632. if (show) {
  6633. row._details.insertAfter(row.nTr);
  6634. } else {
  6635. row._details.detach();
  6636. }
  6637. __details_events(ctx[0]);
  6638. }
  6639. }
  6640. };
  6641. var __details_events = function (settings) {
  6642. var api = new _Api(settings);
  6643. var namespace = '.dt.DT_details';
  6644. var drawEvent = 'draw' + namespace;
  6645. var colvisEvent = 'column-visibility' + namespace;
  6646. var destroyEvent = 'destroy' + namespace;
  6647. var data = settings.aoData;
  6648. api.off(drawEvent + ' ' + colvisEvent + ' ' + destroyEvent);
  6649. if (_pluck(data, '_details').length > 0) {
  6650. // On each draw, insert the required elements into the document
  6651. api.on(drawEvent, function (e, ctx) {
  6652. if (settings !== ctx) {
  6653. return;
  6654. }
  6655. api.rows({page: 'current'}).eq(0).each(function (idx) {
  6656. // Internal data grab
  6657. var row = data[idx];
  6658. if (row._detailsShow) {
  6659. row._details.insertAfter(row.nTr);
  6660. }
  6661. });
  6662. });
  6663. // Column visibility change - update the colspan
  6664. api.on(colvisEvent, function (e, ctx, idx, vis) {
  6665. if (settings !== ctx) {
  6666. return;
  6667. }
  6668. // Update the colspan for the details rows (note, only if it already has
  6669. // a colspan)
  6670. var row, visible = _fnVisbleColumns(ctx);
  6671. for (var i = 0, ien = data.length; i < ien; i++) {
  6672. row = data[i];
  6673. if (row._details) {
  6674. row._details.children('td[colspan]').attr('colspan', visible);
  6675. }
  6676. }
  6677. });
  6678. // Table destroyed - nuke any child rows
  6679. api.on(destroyEvent, function (e, ctx) {
  6680. if (settings !== ctx) {
  6681. return;
  6682. }
  6683. for (var i = 0, ien = data.length; i < ien; i++) {
  6684. if (data[i]._details) {
  6685. __details_remove(api, i);
  6686. }
  6687. }
  6688. });
  6689. }
  6690. };
  6691. // Strings for the method names to help minification
  6692. var _emp = '';
  6693. var _child_obj = _emp + 'row().child';
  6694. var _child_mth = _child_obj + '()';
  6695. // data can be:
  6696. // tr
  6697. // string
  6698. // jQuery or array of any of the above
  6699. _api_register(_child_mth, function (data, klass) {
  6700. var ctx = this.context;
  6701. if (data === undefined) {
  6702. // get
  6703. return ctx.length && this.length ?
  6704. ctx[0].aoData[this[0]]._details :
  6705. undefined;
  6706. } else if (data === true) {
  6707. // show
  6708. this.child.show();
  6709. } else if (data === false) {
  6710. // remove
  6711. __details_remove(this);
  6712. } else if (ctx.length && this.length) {
  6713. // set
  6714. __details_add(ctx[0], ctx[0].aoData[this[0]], data, klass);
  6715. }
  6716. return this;
  6717. });
  6718. _api_register([
  6719. _child_obj + '.show()',
  6720. _child_mth + '.show()' // only when `child()` was called with parameters (without
  6721. ], function (show) { // it returns an object and this method is not executed)
  6722. __details_display(this, true);
  6723. return this;
  6724. });
  6725. _api_register([
  6726. _child_obj + '.hide()',
  6727. _child_mth + '.hide()' // only when `child()` was called with parameters (without
  6728. ], function () { // it returns an object and this method is not executed)
  6729. __details_display(this, false);
  6730. return this;
  6731. });
  6732. _api_register([
  6733. _child_obj + '.remove()',
  6734. _child_mth + '.remove()' // only when `child()` was called with parameters (without
  6735. ], function () { // it returns an object and this method is not executed)
  6736. __details_remove(this);
  6737. return this;
  6738. });
  6739. _api_register(_child_obj + '.isShown()', function () {
  6740. var ctx = this.context;
  6741. if (ctx.length && this.length) {
  6742. // _detailsShown as false or undefined will fall through to return false
  6743. return ctx[0].aoData[this[0]]._detailsShow || false;
  6744. }
  6745. return false;
  6746. });
  6747. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  6748. * Columns
  6749. *
  6750. * {integer} - column index (>=0 count from left, <0 count from right)
  6751. * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
  6752. * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
  6753. * "{string}:name" - column name
  6754. * "{string}" - jQuery selector on column header nodes
  6755. *
  6756. */
  6757. // can be an array of these items, comma separated list, or an array of comma
  6758. // separated lists
  6759. var __re_column_selector = /^([^:]+):(name|visIdx|visible)$/;
  6760. // r1 and r2 are redundant - but it means that the parameters match for the
  6761. // iterator callback in columns().data()
  6762. var __columnData = function (settings, column, r1, r2, rows) {
  6763. var a = [];
  6764. for (var row = 0, ien = rows.length; row < ien; row++) {
  6765. a.push(_fnGetCellData(settings, rows[row], column));
  6766. }
  6767. return a;
  6768. };
  6769. var __column_selector = function (settings, selector, opts) {
  6770. var
  6771. columns = settings.aoColumns,
  6772. names = _pluck(columns, 'sName'),
  6773. nodes = _pluck(columns, 'nTh');
  6774. var run = function (s) {
  6775. var selInt = _intVal(s);
  6776. // Selector - all
  6777. if (s === '') {
  6778. return _range(columns.length);
  6779. }
  6780. // Selector - index
  6781. if (selInt !== null) {
  6782. return [selInt >= 0 ?
  6783. selInt : // Count from left
  6784. columns.length + selInt // Count from right (+ because its a negative value)
  6785. ];
  6786. }
  6787. // Selector = function
  6788. if (typeof s === 'function') {
  6789. var rows = _selector_row_indexes(settings, opts);
  6790. return $.map(columns, function (col, idx) {
  6791. return s(
  6792. idx,
  6793. __columnData(settings, idx, 0, 0, rows),
  6794. nodes[idx]
  6795. ) ? idx : null;
  6796. });
  6797. }
  6798. // jQuery or string selector
  6799. var match = typeof s === 'string' ?
  6800. s.match(__re_column_selector) :
  6801. '';
  6802. if (match) {
  6803. switch (match[2]) {
  6804. case 'visIdx':
  6805. case 'visible':
  6806. var idx = parseInt(match[1], 10);
  6807. // Visible index given, convert to column index
  6808. if (idx < 0) {
  6809. // Counting from the right
  6810. var visColumns = $.map(columns, function (col, i) {
  6811. return col.bVisible ? i : null;
  6812. });
  6813. return [visColumns[visColumns.length + idx]];
  6814. }
  6815. // Counting from the left
  6816. return [_fnVisibleToColumnIndex(settings, idx)];
  6817. case 'name':
  6818. // match by name. `names` is column index complete and in order
  6819. return $.map(names, function (name, i) {
  6820. return name === match[1] ? i : null;
  6821. });
  6822. default:
  6823. return [];
  6824. }
  6825. }
  6826. // Cell in the table body
  6827. if (s.nodeName && s._DT_CellIndex) {
  6828. return [s._DT_CellIndex.column];
  6829. }
  6830. // jQuery selector on the TH elements for the columns
  6831. var jqResult = $(nodes)
  6832. .filter(s)
  6833. .map(function () {
  6834. return $.inArray(this, nodes); // `nodes` is column index complete and in order
  6835. })
  6836. .toArray();
  6837. if (jqResult.length || !s.nodeName) {
  6838. return jqResult;
  6839. }
  6840. // Otherwise a node which might have a `dt-column` data attribute, or be
  6841. // a child or such an element
  6842. var host = $(s).closest('*[data-dt-column]');
  6843. return host.length ?
  6844. [host.data('dt-column')] :
  6845. [];
  6846. };
  6847. return _selector_run('column', selector, run, settings, opts);
  6848. };
  6849. var __setColumnVis = function (settings, column, vis) {
  6850. var
  6851. cols = settings.aoColumns,
  6852. col = cols[column],
  6853. data = settings.aoData,
  6854. row, cells, i, ien, tr;
  6855. // Get
  6856. if (vis === undefined) {
  6857. return col.bVisible;
  6858. }
  6859. // Set
  6860. // No change
  6861. if (col.bVisible === vis) {
  6862. return;
  6863. }
  6864. if (vis) {
  6865. // Insert column
  6866. // Need to decide if we should use appendChild or insertBefore
  6867. var insertBefore = $.inArray(true, _pluck(cols, 'bVisible'), column + 1);
  6868. for (i = 0, ien = data.length; i < ien; i++) {
  6869. tr = data[i].nTr;
  6870. cells = data[i].anCells;
  6871. if (tr) {
  6872. // insertBefore can act like appendChild if 2nd arg is null
  6873. tr.insertBefore(cells[column], cells[insertBefore] || null);
  6874. }
  6875. }
  6876. } else {
  6877. // Remove column
  6878. $(_pluck(settings.aoData, 'anCells', column)).detach();
  6879. }
  6880. // Common actions
  6881. col.bVisible = vis;
  6882. };
  6883. _api_register('columns()', function (selector, opts) {
  6884. // argument shifting
  6885. if (selector === undefined) {
  6886. selector = '';
  6887. } else if ($.isPlainObject(selector)) {
  6888. opts = selector;
  6889. selector = '';
  6890. }
  6891. opts = _selector_opts(opts);
  6892. var inst = this.iterator('table', function (settings) {
  6893. return __column_selector(settings, selector, opts);
  6894. }, 1);
  6895. // Want argument shifting here and in _row_selector?
  6896. inst.selector.cols = selector;
  6897. inst.selector.opts = opts;
  6898. return inst;
  6899. });
  6900. _api_registerPlural('columns().header()', 'column().header()', function (selector, opts) {
  6901. return this.iterator('column', function (settings, column) {
  6902. return settings.aoColumns[column].nTh;
  6903. }, 1);
  6904. });
  6905. _api_registerPlural('columns().footer()', 'column().footer()', function (selector, opts) {
  6906. return this.iterator('column', function (settings, column) {
  6907. return settings.aoColumns[column].nTf;
  6908. }, 1);
  6909. });
  6910. _api_registerPlural('columns().data()', 'column().data()', function () {
  6911. return this.iterator('column-rows', __columnData, 1);
  6912. });
  6913. _api_registerPlural('columns().dataSrc()', 'column().dataSrc()', function () {
  6914. return this.iterator('column', function (settings, column) {
  6915. return settings.aoColumns[column].mData;
  6916. }, 1);
  6917. });
  6918. _api_registerPlural('columns().cache()', 'column().cache()', function (type) {
  6919. return this.iterator('column-rows', function (settings, column, i, j, rows) {
  6920. return _pluck_order(settings.aoData, rows,
  6921. type === 'search' ? '_aFilterData' : '_aSortData', column
  6922. );
  6923. }, 1);
  6924. });
  6925. _api_registerPlural('columns().nodes()', 'column().nodes()', function () {
  6926. return this.iterator('column-rows', function (settings, column, i, j, rows) {
  6927. return _pluck_order(settings.aoData, rows, 'anCells', column);
  6928. }, 1);
  6929. });
  6930. _api_registerPlural('columns().visible()', 'column().visible()', function (vis, calc) {
  6931. var that = this;
  6932. var ret = this.iterator('column', function (settings, column) {
  6933. if (vis === undefined) {
  6934. return settings.aoColumns[column].bVisible;
  6935. } // else
  6936. __setColumnVis(settings, column, vis);
  6937. });
  6938. // Group the column visibility changes
  6939. if (vis !== undefined) {
  6940. this.iterator('table', function (settings) {
  6941. // Redraw the header after changes
  6942. _fnDrawHead(settings, settings.aoHeader);
  6943. _fnDrawHead(settings, settings.aoFooter);
  6944. // Update colspan for no records display. Child rows and extensions will use their own
  6945. // listeners to do this - only need to update the empty table item here
  6946. if (!settings.aiDisplay.length) {
  6947. $(settings.nTBody).find('td[colspan]').attr('colspan', _fnVisbleColumns(settings));
  6948. }
  6949. _fnSaveState(settings);
  6950. // Second loop once the first is done for events
  6951. that.iterator('column', function (settings, column) {
  6952. _fnCallbackFire(settings, null, 'column-visibility', [settings, column, vis, calc]);
  6953. });
  6954. if (calc === undefined || calc) {
  6955. that.columns.adjust();
  6956. }
  6957. });
  6958. }
  6959. return ret;
  6960. });
  6961. _api_registerPlural('columns().indexes()', 'column().index()', function (type) {
  6962. return this.iterator('column', function (settings, column) {
  6963. return type === 'visible' ?
  6964. _fnColumnIndexToVisible(settings, column) :
  6965. column;
  6966. }, 1);
  6967. });
  6968. _api_register('columns.adjust()', function () {
  6969. return this.iterator('table', function (settings) {
  6970. _fnAdjustColumnSizing(settings);
  6971. }, 1);
  6972. });
  6973. _api_register('column.index()', function (type, idx) {
  6974. if (this.context.length !== 0) {
  6975. var ctx = this.context[0];
  6976. if (type === 'fromVisible' || type === 'toData') {
  6977. return _fnVisibleToColumnIndex(ctx, idx);
  6978. } else if (type === 'fromData' || type === 'toVisible') {
  6979. return _fnColumnIndexToVisible(ctx, idx);
  6980. }
  6981. }
  6982. });
  6983. _api_register('column()', function (selector, opts) {
  6984. return _selector_first(this.columns(selector, opts));
  6985. });
  6986. var __cell_selector = function (settings, selector, opts) {
  6987. var data = settings.aoData;
  6988. var rows = _selector_row_indexes(settings, opts);
  6989. var cells = _removeEmpty(_pluck_order(data, rows, 'anCells'));
  6990. var allCells = $(_flatten([], cells));
  6991. var row;
  6992. var columns = settings.aoColumns.length;
  6993. var a, i, ien, j, o, host;
  6994. var run = function (s) {
  6995. var fnSelector = typeof s === 'function';
  6996. if (s === null || s === undefined || fnSelector) {
  6997. // All cells and function selectors
  6998. a = [];
  6999. for (i = 0, ien = rows.length; i < ien; i++) {
  7000. row = rows[i];
  7001. for (j = 0; j < columns; j++) {
  7002. o = {
  7003. row: row,
  7004. column: j
  7005. };
  7006. if (fnSelector) {
  7007. // Selector - function
  7008. host = data[row];
  7009. if (s(o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null)) {
  7010. a.push(o);
  7011. }
  7012. } else {
  7013. // Selector - all
  7014. a.push(o);
  7015. }
  7016. }
  7017. }
  7018. return a;
  7019. }
  7020. // Selector - index
  7021. if ($.isPlainObject(s)) {
  7022. // Valid cell index and its in the array of selectable rows
  7023. return s.column !== undefined && s.row !== undefined && $.inArray(s.row, rows) !== -1 ?
  7024. [s] :
  7025. [];
  7026. }
  7027. // Selector - jQuery filtered cells
  7028. var jqResult = allCells
  7029. .filter(s)
  7030. .map(function (i, el) {
  7031. return { // use a new object, in case someone changes the values
  7032. row: el._DT_CellIndex.row,
  7033. column: el._DT_CellIndex.column
  7034. };
  7035. })
  7036. .toArray();
  7037. if (jqResult.length || !s.nodeName) {
  7038. return jqResult;
  7039. }
  7040. // Otherwise the selector is a node, and there is one last option - the
  7041. // element might be a child of an element which has dt-row and dt-column
  7042. // data attributes
  7043. host = $(s).closest('*[data-dt-row]');
  7044. return host.length ?
  7045. [{
  7046. row: host.data('dt-row'),
  7047. column: host.data('dt-column')
  7048. }] :
  7049. [];
  7050. };
  7051. return _selector_run('cell', selector, run, settings, opts);
  7052. };
  7053. _api_register('cells()', function (rowSelector, columnSelector, opts) {
  7054. // Argument shifting
  7055. if ($.isPlainObject(rowSelector)) {
  7056. // Indexes
  7057. if (rowSelector.row === undefined) {
  7058. // Selector options in first parameter
  7059. opts = rowSelector;
  7060. rowSelector = null;
  7061. } else {
  7062. // Cell index objects in first parameter
  7063. opts = columnSelector;
  7064. columnSelector = null;
  7065. }
  7066. }
  7067. if ($.isPlainObject(columnSelector)) {
  7068. opts = columnSelector;
  7069. columnSelector = null;
  7070. }
  7071. // Cell selector
  7072. if (columnSelector === null || columnSelector === undefined) {
  7073. return this.iterator('table', function (settings) {
  7074. return __cell_selector(settings, rowSelector, _selector_opts(opts));
  7075. });
  7076. }
  7077. // The default built in options need to apply to row and columns
  7078. var internalOpts = opts ? {
  7079. page: opts.page,
  7080. order: opts.order,
  7081. search: opts.search
  7082. } : {};
  7083. // Row + column selector
  7084. var columns = this.columns(columnSelector, internalOpts);
  7085. var rows = this.rows(rowSelector, internalOpts);
  7086. var i, ien, j, jen;
  7087. var cellsNoOpts = this.iterator('table', function (settings, idx) {
  7088. var a = [];
  7089. for (i = 0, ien = rows[idx].length; i < ien; i++) {
  7090. for (j = 0, jen = columns[idx].length; j < jen; j++) {
  7091. a.push({
  7092. row: rows[idx][i],
  7093. column: columns[idx][j]
  7094. });
  7095. }
  7096. }
  7097. return a;
  7098. }, 1);
  7099. // There is currently only one extension which uses a cell selector extension
  7100. // It is a _major_ performance drag to run this if it isn't needed, so this is
  7101. // an extension specific check at the moment
  7102. var cells = opts && opts.selected ?
  7103. this.cells(cellsNoOpts, opts) :
  7104. cellsNoOpts;
  7105. $.extend(cells.selector, {
  7106. cols: columnSelector,
  7107. rows: rowSelector,
  7108. opts: opts
  7109. });
  7110. return cells;
  7111. });
  7112. _api_registerPlural('cells().nodes()', 'cell().node()', function () {
  7113. return this.iterator('cell', function (settings, row, column) {
  7114. var data = settings.aoData[row];
  7115. return data && data.anCells ?
  7116. data.anCells[column] :
  7117. undefined;
  7118. }, 1);
  7119. });
  7120. _api_register('cells().data()', function () {
  7121. return this.iterator('cell', function (settings, row, column) {
  7122. return _fnGetCellData(settings, row, column);
  7123. }, 1);
  7124. });
  7125. _api_registerPlural('cells().cache()', 'cell().cache()', function (type) {
  7126. type = type === 'search' ? '_aFilterData' : '_aSortData';
  7127. return this.iterator('cell', function (settings, row, column) {
  7128. return settings.aoData[row][type][column];
  7129. }, 1);
  7130. });
  7131. _api_registerPlural('cells().render()', 'cell().render()', function (type) {
  7132. return this.iterator('cell', function (settings, row, column) {
  7133. return _fnGetCellData(settings, row, column, type);
  7134. }, 1);
  7135. });
  7136. _api_registerPlural('cells().indexes()', 'cell().index()', function () {
  7137. return this.iterator('cell', function (settings, row, column) {
  7138. return {
  7139. row: row,
  7140. column: column,
  7141. columnVisible: _fnColumnIndexToVisible(settings, column)
  7142. };
  7143. }, 1);
  7144. });
  7145. _api_registerPlural('cells().invalidate()', 'cell().invalidate()', function (src) {
  7146. return this.iterator('cell', function (settings, row, column) {
  7147. _fnInvalidate(settings, row, src, column);
  7148. });
  7149. });
  7150. _api_register('cell()', function (rowSelector, columnSelector, opts) {
  7151. return _selector_first(this.cells(rowSelector, columnSelector, opts));
  7152. });
  7153. _api_register('cell().data()', function (data) {
  7154. var ctx = this.context;
  7155. var cell = this[0];
  7156. if (data === undefined) {
  7157. // Get
  7158. return ctx.length && cell.length ?
  7159. _fnGetCellData(ctx[0], cell[0].row, cell[0].column) :
  7160. undefined;
  7161. }
  7162. // Set
  7163. _fnSetCellData(ctx[0], cell[0].row, cell[0].column, data);
  7164. _fnInvalidate(ctx[0], cell[0].row, 'data', cell[0].column);
  7165. return this;
  7166. });
  7167. /**
  7168. * Get current ordering (sorting) that has been applied to the table.
  7169. *
  7170. * @returns {array} 2D array containing the sorting information for the first
  7171. * table in the current context. Each element in the parent array represents
  7172. * a column being sorted upon (i.e. multi-sorting with two columns would have
  7173. * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
  7174. * the column index that the sorting condition applies to, the second is the
  7175. * direction of the sort (`desc` or `asc`) and, optionally, the third is the
  7176. * index of the sorting order from the `column.sorting` initialisation array.
  7177. *//**
  7178. * Set the ordering for the table.
  7179. *
  7180. * @param {integer} order Column index to sort upon.
  7181. * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
  7182. * @returns {DataTables.Api} this
  7183. *//**
  7184. * Set the ordering for the table.
  7185. *
  7186. * @param {array} order 1D array of sorting information to be applied.
  7187. * @param {array} [...] Optional additional sorting conditions
  7188. * @returns {DataTables.Api} this
  7189. */
  7190. /**
  7191. * Set the ordering for the table.
  7192. *
  7193. * @param {array} order 2D array of sorting information to be applied.
  7194. * @returns {DataTables.Api} this
  7195. */
  7196. _api_register('order()', function (order, dir) {
  7197. var ctx = this.context;
  7198. if (order === undefined) {
  7199. // get
  7200. return ctx.length !== 0 ?
  7201. ctx[0].aaSorting :
  7202. undefined;
  7203. }
  7204. // set
  7205. if (typeof order === 'number') {
  7206. // Simple column / direction passed in
  7207. order = [[order, dir]];
  7208. } else if (order.length && !Array.isArray(order[0])) {
  7209. // Arguments passed in (list of 1D arrays)
  7210. order = Array.prototype.slice.call(arguments);
  7211. }
  7212. // otherwise a 2D array was passed in
  7213. return this.iterator('table', function (settings) {
  7214. settings.aaSorting = order.slice();
  7215. });
  7216. });
  7217. /**
  7218. * Attach a sort listener to an element for a given column
  7219. *
  7220. * @param {node|jQuery|string} node Identifier for the element(s) to attach the
  7221. * listener to. This can take the form of a single DOM node, a jQuery
  7222. * collection of nodes or a jQuery selector which will identify the node(s).
  7223. * @param {integer} column the column that a click on this node will sort on
  7224. * @param {function} [callback] callback function when sort is run
  7225. * @returns {DataTables.Api} this
  7226. */
  7227. _api_register('order.listener()', function (node, column, callback) {
  7228. return this.iterator('table', function (settings) {
  7229. _fnSortAttachListener(settings, node, column, callback);
  7230. });
  7231. });
  7232. _api_register('order.fixed()', function (set) {
  7233. if (!set) {
  7234. var ctx = this.context;
  7235. var fixed = ctx.length ?
  7236. ctx[0].aaSortingFixed :
  7237. undefined;
  7238. return Array.isArray(fixed) ?
  7239. {pre: fixed} :
  7240. fixed;
  7241. }
  7242. return this.iterator('table', function (settings) {
  7243. settings.aaSortingFixed = $.extend(true, {}, set);
  7244. });
  7245. });
  7246. // Order by the selected column(s)
  7247. _api_register([
  7248. 'columns().order()',
  7249. 'column().order()'
  7250. ], function (dir) {
  7251. var that = this;
  7252. return this.iterator('table', function (settings, i) {
  7253. var sort = [];
  7254. $.each(that[i], function (j, col) {
  7255. sort.push([col, dir]);
  7256. });
  7257. settings.aaSorting = sort;
  7258. });
  7259. });
  7260. _api_register('search()', function (input, regex, smart, caseInsen) {
  7261. var ctx = this.context;
  7262. if (input === undefined) {
  7263. // get
  7264. return ctx.length !== 0 ?
  7265. ctx[0].oPreviousSearch.sSearch :
  7266. undefined;
  7267. }
  7268. // set
  7269. return this.iterator('table', function (settings) {
  7270. if (!settings.oFeatures.bFilter) {
  7271. return;
  7272. }
  7273. _fnFilterComplete(settings, $.extend({}, settings.oPreviousSearch, {
  7274. "sSearch": input + "",
  7275. "bRegex": regex === null ? false : regex,
  7276. "bSmart": smart === null ? true : smart,
  7277. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7278. }), 1);
  7279. });
  7280. });
  7281. _api_registerPlural(
  7282. 'columns().search()',
  7283. 'column().search()',
  7284. function (input, regex, smart, caseInsen) {
  7285. return this.iterator('column', function (settings, column) {
  7286. var preSearch = settings.aoPreSearchCols;
  7287. if (input === undefined) {
  7288. // get
  7289. return preSearch[column].sSearch;
  7290. }
  7291. // set
  7292. if (!settings.oFeatures.bFilter) {
  7293. return;
  7294. }
  7295. $.extend(preSearch[column], {
  7296. "sSearch": input + "",
  7297. "bRegex": regex === null ? false : regex,
  7298. "bSmart": smart === null ? true : smart,
  7299. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  7300. });
  7301. _fnFilterComplete(settings, settings.oPreviousSearch, 1);
  7302. });
  7303. }
  7304. );
  7305. /*
  7306. * State API methods
  7307. */
  7308. _api_register('state()', function () {
  7309. return this.context.length ?
  7310. this.context[0].oSavedState :
  7311. null;
  7312. });
  7313. _api_register('state.clear()', function () {
  7314. return this.iterator('table', function (settings) {
  7315. // Save an empty object
  7316. settings.fnStateSaveCallback.call(settings.oInstance, settings, {});
  7317. });
  7318. });
  7319. _api_register('state.loaded()', function () {
  7320. return this.context.length ?
  7321. this.context[0].oLoadedState :
  7322. null;
  7323. });
  7324. _api_register('state.save()', function () {
  7325. return this.iterator('table', function (settings) {
  7326. _fnSaveState(settings);
  7327. });
  7328. });
  7329. /**
  7330. * Provide a common method for plug-ins to check the version of DataTables being
  7331. * used, in order to ensure compatibility.
  7332. *
  7333. * @param {string} version Version string to check for, in the format "X.Y.Z".
  7334. * Note that the formats "X" and "X.Y" are also acceptable.
  7335. * @returns {boolean} true if this version of DataTables is greater or equal to
  7336. * the required version, or false if this version of DataTales is not
  7337. * suitable
  7338. * @static
  7339. * @dtopt API-Static
  7340. *
  7341. * @example
  7342. * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
  7343. */
  7344. DataTable.versionCheck = DataTable.fnVersionCheck = function (version) {
  7345. var aThis = DataTable.version.split('.');
  7346. var aThat = version.split('.');
  7347. var iThis, iThat;
  7348. for (var i = 0, iLen = aThat.length; i < iLen; i++) {
  7349. iThis = parseInt(aThis[i], 10) || 0;
  7350. iThat = parseInt(aThat[i], 10) || 0;
  7351. // Parts are the same, keep comparing
  7352. if (iThis === iThat) {
  7353. continue;
  7354. }
  7355. // Parts are different, return immediately
  7356. return iThis > iThat;
  7357. }
  7358. return true;
  7359. };
  7360. /**
  7361. * Check if a `<table>` node is a DataTable table already or not.
  7362. *
  7363. * @param {node|jquery|string} table Table node, jQuery object or jQuery
  7364. * selector for the table to test. Note that if more than more than one
  7365. * table is passed on, only the first will be checked
  7366. * @returns {boolean} true the table given is a DataTable, or false otherwise
  7367. * @static
  7368. * @dtopt API-Static
  7369. *
  7370. * @example
  7371. * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
  7372. * $('#example').dataTable();
  7373. * }
  7374. */
  7375. DataTable.isDataTable = DataTable.fnIsDataTable = function (table) {
  7376. var t = $(table).get(0);
  7377. var is = false;
  7378. if (table instanceof DataTable.Api) {
  7379. return true;
  7380. }
  7381. $.each(DataTable.settings, function (i, o) {
  7382. var head = o.nScrollHead ? $('table', o.nScrollHead)[0] : null;
  7383. var foot = o.nScrollFoot ? $('table', o.nScrollFoot)[0] : null;
  7384. if (o.nTable === t || head === t || foot === t) {
  7385. is = true;
  7386. }
  7387. });
  7388. return is;
  7389. };
  7390. /**
  7391. * Get all DataTable tables that have been initialised - optionally you can
  7392. * select to get only currently visible tables.
  7393. *
  7394. * @param {boolean} [visible=false] Flag to indicate if you want all (default)
  7395. * or visible tables only.
  7396. * @returns {array} Array of `table` nodes (not DataTable instances) which are
  7397. * DataTables
  7398. * @static
  7399. * @dtopt API-Static
  7400. *
  7401. * @example
  7402. * $.each( $.fn.dataTable.tables(true), function () {
  7403. * $(table).DataTable().columns.adjust();
  7404. * } );
  7405. */
  7406. DataTable.tables = DataTable.fnTables = function (visible) {
  7407. var api = false;
  7408. if ($.isPlainObject(visible)) {
  7409. api = visible.api;
  7410. visible = visible.visible;
  7411. }
  7412. var a = $.map(DataTable.settings, function (o) {
  7413. if (!visible || (visible && $(o.nTable).is(':visible'))) {
  7414. return o.nTable;
  7415. }
  7416. });
  7417. return api ?
  7418. new _Api(a) :
  7419. a;
  7420. };
  7421. /**
  7422. * Convert from camel case parameters to Hungarian notation. This is made public
  7423. * for the extensions to provide the same ability as DataTables core to accept
  7424. * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
  7425. * parameters.
  7426. *
  7427. * @param {object} src The model object which holds all parameters that can be
  7428. * mapped.
  7429. * @param {object} user The object to convert from camel case to Hungarian.
  7430. * @param {boolean} force When set to `true`, properties which already have a
  7431. * Hungarian value in the `user` object will be overwritten. Otherwise they
  7432. * won't be.
  7433. */
  7434. DataTable.camelToHungarian = _fnCamelToHungarian;
  7435. /**
  7436. *
  7437. */
  7438. _api_register('$()', function (selector, opts) {
  7439. var
  7440. rows = this.rows(opts).nodes(), // Get all rows
  7441. jqRows = $(rows);
  7442. return $([].concat(
  7443. jqRows.filter(selector).toArray(),
  7444. jqRows.find(selector).toArray()
  7445. ));
  7446. });
  7447. // jQuery functions to operate on the tables
  7448. $.each(['on', 'one', 'off'], function (i, key) {
  7449. _api_register(key + '()', function ( /* event, handler */) {
  7450. var args = Array.prototype.slice.call(arguments);
  7451. // Add the `dt` namespace automatically if it isn't already present
  7452. args[0] = $.map(args[0].split(/\s/), function (e) {
  7453. return !e.match(/\.dt\b/) ?
  7454. e + '.dt' :
  7455. e;
  7456. }).join(' ');
  7457. var inst = $(this.tables().nodes());
  7458. inst[key].apply(inst, args);
  7459. return this;
  7460. });
  7461. });
  7462. _api_register('clear()', function () {
  7463. return this.iterator('table', function (settings) {
  7464. _fnClearTable(settings);
  7465. });
  7466. });
  7467. _api_register('settings()', function () {
  7468. return new _Api(this.context, this.context);
  7469. });
  7470. _api_register('init()', function () {
  7471. var ctx = this.context;
  7472. return ctx.length ? ctx[0].oInit : null;
  7473. });
  7474. _api_register('data()', function () {
  7475. return this.iterator('table', function (settings) {
  7476. return _pluck(settings.aoData, '_aData');
  7477. }).flatten();
  7478. });
  7479. _api_register('destroy()', function (remove) {
  7480. remove = remove || false;
  7481. return this.iterator('table', function (settings) {
  7482. var orig = settings.nTableWrapper.parentNode;
  7483. var classes = settings.oClasses;
  7484. var table = settings.nTable;
  7485. var tbody = settings.nTBody;
  7486. var thead = settings.nTHead;
  7487. var tfoot = settings.nTFoot;
  7488. var jqTable = $(table);
  7489. var jqTbody = $(tbody);
  7490. var jqWrapper = $(settings.nTableWrapper);
  7491. var rows = $.map(settings.aoData, function (r) {
  7492. return r.nTr;
  7493. });
  7494. var i, ien;
  7495. // Flag to note that the table is currently being destroyed - no action
  7496. // should be taken
  7497. settings.bDestroying = true;
  7498. // Fire off the destroy callbacks for plug-ins etc
  7499. _fnCallbackFire(settings, "aoDestroyCallback", "destroy", [settings]);
  7500. // If not being removed from the document, make all columns visible
  7501. if (!remove) {
  7502. new _Api(settings).columns().visible(true);
  7503. }
  7504. // Blitz all `DT` namespaced events (these are internal events, the
  7505. // lowercase, `dt` events are user subscribed and they are responsible
  7506. // for removing them
  7507. jqWrapper.off('.DT').find(':not(tbody *)').off('.DT');
  7508. $(window).off('.DT-' + settings.sInstance);
  7509. // When scrolling we had to break the table up - restore it
  7510. if (table != thead.parentNode) {
  7511. jqTable.children('thead').detach();
  7512. jqTable.append(thead);
  7513. }
  7514. if (tfoot && table != tfoot.parentNode) {
  7515. jqTable.children('tfoot').detach();
  7516. jqTable.append(tfoot);
  7517. }
  7518. settings.aaSorting = [];
  7519. settings.aaSortingFixed = [];
  7520. _fnSortingClasses(settings);
  7521. $(rows).removeClass(settings.asStripeClasses.join(' '));
  7522. $('th, td', thead).removeClass(classes.sSortable + ' ' +
  7523. classes.sSortableAsc + ' ' + classes.sSortableDesc + ' ' + classes.sSortableNone
  7524. );
  7525. // Add the TR elements back into the table in their original order
  7526. jqTbody.children().detach();
  7527. jqTbody.append(rows);
  7528. // Remove the DataTables generated nodes, events and classes
  7529. var removedMethod = remove ? 'remove' : 'detach';
  7530. jqTable[removedMethod]();
  7531. jqWrapper[removedMethod]();
  7532. // If we need to reattach the table to the document
  7533. if (!remove && orig) {
  7534. // insertBefore acts like appendChild if !arg[1]
  7535. orig.insertBefore(table, settings.nTableReinsertBefore);
  7536. // Restore the width of the original table - was read from the style property,
  7537. // so we can restore directly to that
  7538. jqTable
  7539. .css('width', settings.sDestroyWidth)
  7540. .removeClass(classes.sTable);
  7541. // If the were originally stripe classes - then we add them back here.
  7542. // Note this is not fool proof (for example if not all rows had stripe
  7543. // classes - but it's a good effort without getting carried away
  7544. ien = settings.asDestroyStripes.length;
  7545. if (ien) {
  7546. jqTbody.children().each(function (i) {
  7547. $(this).addClass(settings.asDestroyStripes[i % ien]);
  7548. });
  7549. }
  7550. }
  7551. /* Remove the settings object from the settings array */
  7552. var idx = $.inArray(settings, DataTable.settings);
  7553. if (idx !== -1) {
  7554. DataTable.settings.splice(idx, 1);
  7555. }
  7556. });
  7557. });
  7558. // Add the `every()` method for rows, columns and cells in a compact form
  7559. $.each(['column', 'row', 'cell'], function (i, type) {
  7560. _api_register(type + 's().every()', function (fn) {
  7561. var opts = this.selector.opts;
  7562. var api = this;
  7563. return this.iterator(type, function (settings, arg1, arg2, arg3, arg4) {
  7564. // Rows and columns:
  7565. // arg1 - index
  7566. // arg2 - table counter
  7567. // arg3 - loop counter
  7568. // arg4 - undefined
  7569. // Cells:
  7570. // arg1 - row index
  7571. // arg2 - column index
  7572. // arg3 - table counter
  7573. // arg4 - loop counter
  7574. fn.call(
  7575. api[type](
  7576. arg1,
  7577. type === 'cell' ? arg2 : opts,
  7578. type === 'cell' ? opts : undefined
  7579. ),
  7580. arg1, arg2, arg3, arg4
  7581. );
  7582. });
  7583. });
  7584. });
  7585. // i18n method for extensions to be able to use the language object from the
  7586. // DataTable
  7587. _api_register('i18n()', function (token, def, plural) {
  7588. var ctx = this.context[0];
  7589. var resolved = _fnGetObjectDataFn(token)(ctx.oLanguage);
  7590. if (resolved === undefined) {
  7591. resolved = def;
  7592. }
  7593. if (plural !== undefined && $.isPlainObject(resolved)) {
  7594. resolved = resolved[plural] !== undefined ?
  7595. resolved[plural] :
  7596. resolved._;
  7597. }
  7598. return resolved.replace('%d', plural); // nb: plural might be undefined,
  7599. });
  7600. /**
  7601. * Version string for plug-ins to check compatibility. Allowed format is
  7602. * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
  7603. * only for non-release builds. See http://semver.org/ for more information.
  7604. * @member
  7605. * @type string
  7606. * @default Version number
  7607. */
  7608. DataTable.version = "1.10.24";
  7609. /**
  7610. * Private data store, containing all of the settings objects that are
  7611. * created for the tables on a given page.
  7612. *
  7613. * Note that the `DataTable.settings` object is aliased to
  7614. * `jQuery.fn.dataTableExt` through which it may be accessed and
  7615. * manipulated, or `jQuery.fn.dataTable.settings`.
  7616. * @member
  7617. * @type array
  7618. * @default []
  7619. * @private
  7620. */
  7621. DataTable.settings = [];
  7622. /**
  7623. * Object models container, for the various models that DataTables has
  7624. * available to it. These models define the objects that are used to hold
  7625. * the active state and configuration of the table.
  7626. * @namespace
  7627. */
  7628. DataTable.models = {};
  7629. /**
  7630. * Template object for the way in which DataTables holds information about
  7631. * search information for the global filter and individual column filters.
  7632. * @namespace
  7633. */
  7634. DataTable.models.oSearch = {
  7635. /**
  7636. * Flag to indicate if the filtering should be case insensitive or not
  7637. * @type boolean
  7638. * @default true
  7639. */
  7640. "bCaseInsensitive": true,
  7641. /**
  7642. * Applied search term
  7643. * @type string
  7644. * @default <i>Empty string</i>
  7645. */
  7646. "sSearch": "",
  7647. /**
  7648. * Flag to indicate if the search term should be interpreted as a
  7649. * regular expression (true) or not (false) and therefore and special
  7650. * regex characters escaped.
  7651. * @type boolean
  7652. * @default false
  7653. */
  7654. "bRegex": false,
  7655. /**
  7656. * Flag to indicate if DataTables is to use its smart filtering or not.
  7657. * @type boolean
  7658. * @default true
  7659. */
  7660. "bSmart": true
  7661. };
  7662. /**
  7663. * Template object for the way in which DataTables holds information about
  7664. * each individual row. This is the object format used for the settings
  7665. * aoData array.
  7666. * @namespace
  7667. */
  7668. DataTable.models.oRow = {
  7669. /**
  7670. * TR element for the row
  7671. * @type node
  7672. * @default null
  7673. */
  7674. "nTr": null,
  7675. /**
  7676. * Array of TD elements for each row. This is null until the row has been
  7677. * created.
  7678. * @type array nodes
  7679. * @default []
  7680. */
  7681. "anCells": null,
  7682. /**
  7683. * Data object from the original data source for the row. This is either
  7684. * an array if using the traditional form of DataTables, or an object if
  7685. * using mData options. The exact type will depend on the passed in
  7686. * data from the data source, or will be an array if using DOM a data
  7687. * source.
  7688. * @type array|object
  7689. * @default []
  7690. */
  7691. "_aData": [],
  7692. /**
  7693. * Sorting data cache - this array is ostensibly the same length as the
  7694. * number of columns (although each index is generated only as it is
  7695. * needed), and holds the data that is used for sorting each column in the
  7696. * row. We do this cache generation at the start of the sort in order that
  7697. * the formatting of the sort data need be done only once for each cell
  7698. * per sort. This array should not be read from or written to by anything
  7699. * other than the master sorting methods.
  7700. * @type array
  7701. * @default null
  7702. * @private
  7703. */
  7704. "_aSortData": null,
  7705. /**
  7706. * Per cell filtering data cache. As per the sort data cache, used to
  7707. * increase the performance of the filtering in DataTables
  7708. * @type array
  7709. * @default null
  7710. * @private
  7711. */
  7712. "_aFilterData": null,
  7713. /**
  7714. * Filtering data cache. This is the same as the cell filtering cache, but
  7715. * in this case a string rather than an array. This is easily computed with
  7716. * a join on `_aFilterData`, but is provided as a cache so the join isn't
  7717. * needed on every search (memory traded for performance)
  7718. * @type array
  7719. * @default null
  7720. * @private
  7721. */
  7722. "_sFilterRow": null,
  7723. /**
  7724. * Cache of the class name that DataTables has applied to the row, so we
  7725. * can quickly look at this variable rather than needing to do a DOM check
  7726. * on className for the nTr property.
  7727. * @type string
  7728. * @default <i>Empty string</i>
  7729. * @private
  7730. */
  7731. "_sRowStripe": "",
  7732. /**
  7733. * Denote if the original data source was from the DOM, or the data source
  7734. * object. This is used for invalidating data, so DataTables can
  7735. * automatically read data from the original source, unless uninstructed
  7736. * otherwise.
  7737. * @type string
  7738. * @default null
  7739. * @private
  7740. */
  7741. "src": null,
  7742. /**
  7743. * Index in the aoData array. This saves an indexOf lookup when we have the
  7744. * object, but want to know the index
  7745. * @type integer
  7746. * @default -1
  7747. * @private
  7748. */
  7749. "idx": -1
  7750. };
  7751. /**
  7752. * Template object for the column information object in DataTables. This object
  7753. * is held in the settings aoColumns array and contains all the information that
  7754. * DataTables needs about each individual column.
  7755. *
  7756. * Note that this object is related to {@link DataTable.defaults.column}
  7757. * but this one is the internal data store for DataTables's cache of columns.
  7758. * It should NOT be manipulated outside of DataTables. Any configuration should
  7759. * be done through the initialisation options.
  7760. * @namespace
  7761. */
  7762. DataTable.models.oColumn = {
  7763. /**
  7764. * Column index. This could be worked out on-the-fly with $.inArray, but it
  7765. * is faster to just hold it as a variable
  7766. * @type integer
  7767. * @default null
  7768. */
  7769. "idx": null,
  7770. /**
  7771. * A list of the columns that sorting should occur on when this column
  7772. * is sorted. That this property is an array allows multi-column sorting
  7773. * to be defined for a column (for example first name / last name columns
  7774. * would benefit from this). The values are integers pointing to the
  7775. * columns to be sorted on (typically it will be a single integer pointing
  7776. * at itself, but that doesn't need to be the case).
  7777. * @type array
  7778. */
  7779. "aDataSort": null,
  7780. /**
  7781. * Define the sorting directions that are applied to the column, in sequence
  7782. * as the column is repeatedly sorted upon - i.e. the first value is used
  7783. * as the sorting direction when the column if first sorted (clicked on).
  7784. * Sort it again (click again) and it will move on to the next index.
  7785. * Repeat until loop.
  7786. * @type array
  7787. */
  7788. "asSorting": null,
  7789. /**
  7790. * Flag to indicate if the column is searchable, and thus should be included
  7791. * in the filtering or not.
  7792. * @type boolean
  7793. */
  7794. "bSearchable": null,
  7795. /**
  7796. * Flag to indicate if the column is sortable or not.
  7797. * @type boolean
  7798. */
  7799. "bSortable": null,
  7800. /**
  7801. * Flag to indicate if the column is currently visible in the table or not
  7802. * @type boolean
  7803. */
  7804. "bVisible": null,
  7805. /**
  7806. * Store for manual type assignment using the `column.type` option. This
  7807. * is held in store so we can manipulate the column's `sType` property.
  7808. * @type string
  7809. * @default null
  7810. * @private
  7811. */
  7812. "_sManualType": null,
  7813. /**
  7814. * Flag to indicate if HTML5 data attributes should be used as the data
  7815. * source for filtering or sorting. True is either are.
  7816. * @type boolean
  7817. * @default false
  7818. * @private
  7819. */
  7820. "_bAttrSrc": false,
  7821. /**
  7822. * Developer definable function that is called whenever a cell is created (Ajax source,
  7823. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  7824. * allowing you to modify the DOM element (add background colour for example) when the
  7825. * element is available.
  7826. * @type function
  7827. * @param {element} nTd The TD node that has been created
  7828. * @param {*} sData The Data for the cell
  7829. * @param {array|object} oData The data for the whole row
  7830. * @param {int} iRow The row index for the aoData data store
  7831. * @default null
  7832. */
  7833. "fnCreatedCell": null,
  7834. /**
  7835. * Function to get data from a cell in a column. You should <b>never</b>
  7836. * access data directly through _aData internally in DataTables - always use
  7837. * the method attached to this property. It allows mData to function as
  7838. * required. This function is automatically assigned by the column
  7839. * initialisation method
  7840. * @type function
  7841. * @param {array|object} oData The data array/object for the array
  7842. * (i.e. aoData[]._aData)
  7843. * @param {string} sSpecific The specific data type you want to get -
  7844. * 'display', 'type' 'filter' 'sort'
  7845. * @returns {*} The data for the cell from the given row's data
  7846. * @default null
  7847. */
  7848. "fnGetData": null,
  7849. /**
  7850. * Function to set data for a cell in the column. You should <b>never</b>
  7851. * set the data directly to _aData internally in DataTables - always use
  7852. * this method. It allows mData to function as required. This function
  7853. * is automatically assigned by the column initialisation method
  7854. * @type function
  7855. * @param {array|object} oData The data array/object for the array
  7856. * (i.e. aoData[]._aData)
  7857. * @param {*} sValue Value to set
  7858. * @default null
  7859. */
  7860. "fnSetData": null,
  7861. /**
  7862. * Property to read the value for the cells in the column from the data
  7863. * source array / object. If null, then the default content is used, if a
  7864. * function is given then the return from the function is used.
  7865. * @type function|int|string|null
  7866. * @default null
  7867. */
  7868. "mData": null,
  7869. /**
  7870. * Partner property to mData which is used (only when defined) to get
  7871. * the data - i.e. it is basically the same as mData, but without the
  7872. * 'set' option, and also the data fed to it is the result from mData.
  7873. * This is the rendering method to match the data method of mData.
  7874. * @type function|int|string|null
  7875. * @default null
  7876. */
  7877. "mRender": null,
  7878. /**
  7879. * Unique header TH/TD element for this column - this is what the sorting
  7880. * listener is attached to (if sorting is enabled.)
  7881. * @type node
  7882. * @default null
  7883. */
  7884. "nTh": null,
  7885. /**
  7886. * Unique footer TH/TD element for this column (if there is one). Not used
  7887. * in DataTables as such, but can be used for plug-ins to reference the
  7888. * footer for each column.
  7889. * @type node
  7890. * @default null
  7891. */
  7892. "nTf": null,
  7893. /**
  7894. * The class to apply to all TD elements in the table's TBODY for the column
  7895. * @type string
  7896. * @default null
  7897. */
  7898. "sClass": null,
  7899. /**
  7900. * When DataTables calculates the column widths to assign to each column,
  7901. * it finds the longest string in each column and then constructs a
  7902. * temporary table and reads the widths from that. The problem with this
  7903. * is that "mmm" is much wider then "iiii", but the latter is a longer
  7904. * string - thus the calculation can go wrong (doing it properly and putting
  7905. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  7906. * a "work around" we provide this option. It will append its value to the
  7907. * text that is found to be the longest string for the column - i.e. padding.
  7908. * @type string
  7909. */
  7910. "sContentPadding": null,
  7911. /**
  7912. * Allows a default value to be given for a column's data, and will be used
  7913. * whenever a null data source is encountered (this can be because mData
  7914. * is set to null, or because the data source itself is null).
  7915. * @type string
  7916. * @default null
  7917. */
  7918. "sDefaultContent": null,
  7919. /**
  7920. * Name for the column, allowing reference to the column by name as well as
  7921. * by index (needs a lookup to work by name).
  7922. * @type string
  7923. */
  7924. "sName": null,
  7925. /**
  7926. * Custom sorting data type - defines which of the available plug-ins in
  7927. * afnSortData the custom sorting will use - if any is defined.
  7928. * @type string
  7929. * @default std
  7930. */
  7931. "sSortDataType": 'std',
  7932. /**
  7933. * Class to be applied to the header element when sorting on this column
  7934. * @type string
  7935. * @default null
  7936. */
  7937. "sSortingClass": null,
  7938. /**
  7939. * Class to be applied to the header element when sorting on this column -
  7940. * when jQuery UI theming is used.
  7941. * @type string
  7942. * @default null
  7943. */
  7944. "sSortingClassJUI": null,
  7945. /**
  7946. * Title of the column - what is seen in the TH element (nTh).
  7947. * @type string
  7948. */
  7949. "sTitle": null,
  7950. /**
  7951. * Column sorting and filtering type
  7952. * @type string
  7953. * @default null
  7954. */
  7955. "sType": null,
  7956. /**
  7957. * Width of the column
  7958. * @type string
  7959. * @default null
  7960. */
  7961. "sWidth": null,
  7962. /**
  7963. * Width of the column when it was first "encountered"
  7964. * @type string
  7965. * @default null
  7966. */
  7967. "sWidthOrig": null
  7968. };
  7969. /*
  7970. * Developer note: The properties of the object below are given in Hungarian
  7971. * notation, that was used as the interface for DataTables prior to v1.10, however
  7972. * from v1.10 onwards the primary interface is camel case. In order to avoid
  7973. * breaking backwards compatibility utterly with this change, the Hungarian
  7974. * version is still, internally the primary interface, but is is not documented
  7975. * - hence the @name tags in each doc comment. This allows a Javascript function
  7976. * to create a map from Hungarian notation to camel case (going the other direction
  7977. * would require each property to be listed, which would add around 3K to the size
  7978. * of DataTables, while this method is about a 0.5K hit).
  7979. *
  7980. * Ultimately this does pave the way for Hungarian notation to be dropped
  7981. * completely, but that is a massive amount of work and will break current
  7982. * installs (therefore is on-hold until v2).
  7983. */
  7984. /**
  7985. * Initialisation options that can be given to DataTables at initialisation
  7986. * time.
  7987. * @namespace
  7988. */
  7989. DataTable.defaults = {
  7990. /**
  7991. * An array of data to use for the table, passed in at initialisation which
  7992. * will be used in preference to any data which is already in the DOM. This is
  7993. * particularly useful for constructing tables purely in Javascript, for
  7994. * example with a custom Ajax call.
  7995. * @type array
  7996. * @default null
  7997. *
  7998. * @dtopt Option
  7999. * @name DataTable.defaults.data
  8000. *
  8001. * @example
  8002. * // Using a 2D array data source
  8003. * $(document).ready( function () {
  8004. * $('#example').dataTable( {
  8005. * "data": [
  8006. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  8007. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  8008. * ],
  8009. * "columns": [
  8010. * { "title": "Engine" },
  8011. * { "title": "Browser" },
  8012. * { "title": "Platform" },
  8013. * { "title": "Version" },
  8014. * { "title": "Grade" }
  8015. * ]
  8016. * } );
  8017. * } );
  8018. *
  8019. * @example
  8020. * // Using an array of objects as a data source (`data`)
  8021. * $(document).ready( function () {
  8022. * $('#example').dataTable( {
  8023. * "data": [
  8024. * {
  8025. * "engine": "Trident",
  8026. * "browser": "Internet Explorer 4.0",
  8027. * "platform": "Win 95+",
  8028. * "version": 4,
  8029. * "grade": "X"
  8030. * },
  8031. * {
  8032. * "engine": "Trident",
  8033. * "browser": "Internet Explorer 5.0",
  8034. * "platform": "Win 95+",
  8035. * "version": 5,
  8036. * "grade": "C"
  8037. * }
  8038. * ],
  8039. * "columns": [
  8040. * { "title": "Engine", "data": "engine" },
  8041. * { "title": "Browser", "data": "browser" },
  8042. * { "title": "Platform", "data": "platform" },
  8043. * { "title": "Version", "data": "version" },
  8044. * { "title": "Grade", "data": "grade" }
  8045. * ]
  8046. * } );
  8047. * } );
  8048. */
  8049. "aaData": null,
  8050. /**
  8051. * If ordering is enabled, then DataTables will perform a first pass sort on
  8052. * initialisation. You can define which column(s) the sort is performed
  8053. * upon, and the sorting direction, with this variable. The `sorting` array
  8054. * should contain an array for each column to be sorted initially containing
  8055. * the column's index and a direction string ('asc' or 'desc').
  8056. * @type array
  8057. * @default [[0,'asc']]
  8058. *
  8059. * @dtopt Option
  8060. * @name DataTable.defaults.order
  8061. *
  8062. * @example
  8063. * // Sort by 3rd column first, and then 4th column
  8064. * $(document).ready( function() {
  8065. * $('#example').dataTable( {
  8066. * "order": [[2,'asc'], [3,'desc']]
  8067. * } );
  8068. * } );
  8069. *
  8070. * // No initial sorting
  8071. * $(document).ready( function() {
  8072. * $('#example').dataTable( {
  8073. * "order": []
  8074. * } );
  8075. * } );
  8076. */
  8077. "aaSorting": [[0, 'asc']],
  8078. /**
  8079. * This parameter is basically identical to the `sorting` parameter, but
  8080. * cannot be overridden by user interaction with the table. What this means
  8081. * is that you could have a column (visible or hidden) which the sorting
  8082. * will always be forced on first - any sorting after that (from the user)
  8083. * will then be performed as required. This can be useful for grouping rows
  8084. * together.
  8085. * @type array
  8086. * @default null
  8087. *
  8088. * @dtopt Option
  8089. * @name DataTable.defaults.orderFixed
  8090. *
  8091. * @example
  8092. * $(document).ready( function() {
  8093. * $('#example').dataTable( {
  8094. * "orderFixed": [[0,'asc']]
  8095. * } );
  8096. * } )
  8097. */
  8098. "aaSortingFixed": [],
  8099. /**
  8100. * DataTables can be instructed to load data to display in the table from a
  8101. * Ajax source. This option defines how that Ajax call is made and where to.
  8102. *
  8103. * The `ajax` property has three different modes of operation, depending on
  8104. * how it is defined. These are:
  8105. *
  8106. * * `string` - Set the URL from where the data should be loaded from.
  8107. * * `object` - Define properties for `jQuery.ajax`.
  8108. * * `function` - Custom data get function
  8109. *
  8110. * `string`
  8111. * --------
  8112. *
  8113. * As a string, the `ajax` property simply defines the URL from which
  8114. * DataTables will load data.
  8115. *
  8116. * `object`
  8117. * --------
  8118. *
  8119. * As an object, the parameters in the object are passed to
  8120. * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
  8121. * of the Ajax request. DataTables has a number of default parameters which
  8122. * you can override using this option. Please refer to the jQuery
  8123. * documentation for a full description of the options available, although
  8124. * the following parameters provide additional options in DataTables or
  8125. * require special consideration:
  8126. *
  8127. * * `data` - As with jQuery, `data` can be provided as an object, but it
  8128. * can also be used as a function to manipulate the data DataTables sends
  8129. * to the server. The function takes a single parameter, an object of
  8130. * parameters with the values that DataTables has readied for sending. An
  8131. * object may be returned which will be merged into the DataTables
  8132. * defaults, or you can add the items to the object that was passed in and
  8133. * not return anything from the function. This supersedes `fnServerParams`
  8134. * from DataTables 1.9-.
  8135. *
  8136. * * `dataSrc` - By default DataTables will look for the property `data` (or
  8137. * `aaData` for compatibility with DataTables 1.9-) when obtaining data
  8138. * from an Ajax source or for server-side processing - this parameter
  8139. * allows that property to be changed. You can use Javascript dotted
  8140. * object notation to get a data source for multiple levels of nesting, or
  8141. * it my be used as a function. As a function it takes a single parameter,
  8142. * the JSON returned from the server, which can be manipulated as
  8143. * required, with the returned value being that used by DataTables as the
  8144. * data source for the table. This supersedes `sAjaxDataProp` from
  8145. * DataTables 1.9-.
  8146. *
  8147. * * `success` - Should not be overridden it is used internally in
  8148. * DataTables. To manipulate / transform the data returned by the server
  8149. * use `ajax.dataSrc`, or use `ajax` as a function (see below).
  8150. *
  8151. * `function`
  8152. * ----------
  8153. *
  8154. * As a function, making the Ajax call is left up to yourself allowing
  8155. * complete control of the Ajax request. Indeed, if desired, a method other
  8156. * than Ajax could be used to obtain the required data, such as Web storage
  8157. * or an AIR database.
  8158. *
  8159. * The function is given four parameters and no return is required. The
  8160. * parameters are:
  8161. *
  8162. * 1. _object_ - Data to send to the server
  8163. * 2. _function_ - Callback function that must be executed when the required
  8164. * data has been obtained. That data should be passed into the callback
  8165. * as the only parameter
  8166. * 3. _object_ - DataTables settings object for the table
  8167. *
  8168. * Note that this supersedes `fnServerData` from DataTables 1.9-.
  8169. *
  8170. * @type string|object|function
  8171. * @default null
  8172. *
  8173. * @dtopt Option
  8174. * @name DataTable.defaults.ajax
  8175. * @since 1.10.0
  8176. *
  8177. * @example
  8178. * // Get JSON data from a file via Ajax.
  8179. * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
  8180. * $('#example').dataTable( {
  8181. * "ajax": "data.json"
  8182. * } );
  8183. *
  8184. * @example
  8185. * // Get JSON data from a file via Ajax, using `dataSrc` to change
  8186. * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
  8187. * $('#example').dataTable( {
  8188. * "ajax": {
  8189. * "url": "data.json",
  8190. * "dataSrc": "tableData"
  8191. * }
  8192. * } );
  8193. *
  8194. * @example
  8195. * // Get JSON data from a file via Ajax, using `dataSrc` to read data
  8196. * // from a plain array rather than an array in an object
  8197. * $('#example').dataTable( {
  8198. * "ajax": {
  8199. * "url": "data.json",
  8200. * "dataSrc": ""
  8201. * }
  8202. * } );
  8203. *
  8204. * @example
  8205. * // Manipulate the data returned from the server - add a link to data
  8206. * // (note this can, should, be done using `render` for the column - this
  8207. * // is just a simple example of how the data can be manipulated).
  8208. * $('#example').dataTable( {
  8209. * "ajax": {
  8210. * "url": "data.json",
  8211. * "dataSrc": function ( json ) {
  8212. * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
  8213. * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
  8214. * }
  8215. * return json;
  8216. * }
  8217. * }
  8218. * } );
  8219. *
  8220. * @example
  8221. * // Add data to the request
  8222. * $('#example').dataTable( {
  8223. * "ajax": {
  8224. * "url": "data.json",
  8225. * "data": function ( d ) {
  8226. * return {
  8227. * "extra_search": $('#extra').val()
  8228. * };
  8229. * }
  8230. * }
  8231. * } );
  8232. *
  8233. * @example
  8234. * // Send request as POST
  8235. * $('#example').dataTable( {
  8236. * "ajax": {
  8237. * "url": "data.json",
  8238. * "type": "POST"
  8239. * }
  8240. * } );
  8241. *
  8242. * @example
  8243. * // Get the data from localStorage (could interface with a form for
  8244. * // adding, editing and removing rows).
  8245. * $('#example').dataTable( {
  8246. * "ajax": function (data, callback, settings) {
  8247. * callback(
  8248. * JSON.parse( localStorage.getItem('dataTablesData') )
  8249. * );
  8250. * }
  8251. * } );
  8252. */
  8253. "ajax": null,
  8254. /**
  8255. * This parameter allows you to readily specify the entries in the length drop
  8256. * down menu that DataTables shows when pagination is enabled. It can be
  8257. * either a 1D array of options which will be used for both the displayed
  8258. * option and the value, or a 2D array which will use the array in the first
  8259. * position as the value, and the array in the second position as the
  8260. * displayed options (useful for language strings such as 'All').
  8261. *
  8262. * Note that the `pageLength` property will be automatically set to the
  8263. * first value given in this array, unless `pageLength` is also provided.
  8264. * @type array
  8265. * @default [ 10, 25, 50, 100 ]
  8266. *
  8267. * @dtopt Option
  8268. * @name DataTable.defaults.lengthMenu
  8269. *
  8270. * @example
  8271. * $(document).ready( function() {
  8272. * $('#example').dataTable( {
  8273. * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  8274. * } );
  8275. * } );
  8276. */
  8277. "aLengthMenu": [10, 25, 50, 100],
  8278. /**
  8279. * The `columns` option in the initialisation parameter allows you to define
  8280. * details about the way individual columns behave. For a full list of
  8281. * column options that can be set, please see
  8282. * {@link DataTable.defaults.column}. Note that if you use `columns` to
  8283. * define your columns, you must have an entry in the array for every single
  8284. * column that you have in your table (these can be null if you don't which
  8285. * to specify any options).
  8286. * @member
  8287. *
  8288. * @name DataTable.defaults.column
  8289. */
  8290. "aoColumns": null,
  8291. /**
  8292. * Very similar to `columns`, `columnDefs` allows you to target a specific
  8293. * column, multiple columns, or all columns, using the `targets` property of
  8294. * each object in the array. This allows great flexibility when creating
  8295. * tables, as the `columnDefs` arrays can be of any length, targeting the
  8296. * columns you specifically want. `columnDefs` may use any of the column
  8297. * options available: {@link DataTable.defaults.column}, but it _must_
  8298. * have `targets` defined in each object in the array. Values in the `targets`
  8299. * array may be:
  8300. * <ul>
  8301. * <li>a string - class name will be matched on the TH for the column</li>
  8302. * <li>0 or a positive integer - column index counting from the left</li>
  8303. * <li>a negative integer - column index counting from the right</li>
  8304. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  8305. * </ul>
  8306. * @member
  8307. *
  8308. * @name DataTable.defaults.columnDefs
  8309. */
  8310. "aoColumnDefs": null,
  8311. /**
  8312. * Basically the same as `search`, this parameter defines the individual column
  8313. * filtering state at initialisation time. The array must be of the same size
  8314. * as the number of columns, and each element be an object with the parameters
  8315. * `search` and `escapeRegex` (the latter is optional). 'null' is also
  8316. * accepted and the default will be used.
  8317. * @type array
  8318. * @default []
  8319. *
  8320. * @dtopt Option
  8321. * @name DataTable.defaults.searchCols
  8322. *
  8323. * @example
  8324. * $(document).ready( function() {
  8325. * $('#example').dataTable( {
  8326. * "searchCols": [
  8327. * null,
  8328. * { "search": "My filter" },
  8329. * null,
  8330. * { "search": "^[0-9]", "escapeRegex": false }
  8331. * ]
  8332. * } );
  8333. * } )
  8334. */
  8335. "aoSearchCols": [],
  8336. /**
  8337. * An array of CSS classes that should be applied to displayed rows. This
  8338. * array may be of any length, and DataTables will apply each class
  8339. * sequentially, looping when required.
  8340. * @type array
  8341. * @default null <i>Will take the values determined by the `oClasses.stripe*`
  8342. * options</i>
  8343. *
  8344. * @dtopt Option
  8345. * @name DataTable.defaults.stripeClasses
  8346. *
  8347. * @example
  8348. * $(document).ready( function() {
  8349. * $('#example').dataTable( {
  8350. * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  8351. * } );
  8352. * } )
  8353. */
  8354. "asStripeClasses": null,
  8355. /**
  8356. * Enable or disable automatic column width calculation. This can be disabled
  8357. * as an optimisation (it takes some time to calculate the widths) if the
  8358. * tables widths are passed in using `columns`.
  8359. * @type boolean
  8360. * @default true
  8361. *
  8362. * @dtopt Features
  8363. * @name DataTable.defaults.autoWidth
  8364. *
  8365. * @example
  8366. * $(document).ready( function () {
  8367. * $('#example').dataTable( {
  8368. * "autoWidth": false
  8369. * } );
  8370. * } );
  8371. */
  8372. "bAutoWidth": true,
  8373. /**
  8374. * Deferred rendering can provide DataTables with a huge speed boost when you
  8375. * are using an Ajax or JS data source for the table. This option, when set to
  8376. * true, will cause DataTables to defer the creation of the table elements for
  8377. * each row until they are needed for a draw - saving a significant amount of
  8378. * time.
  8379. * @type boolean
  8380. * @default false
  8381. *
  8382. * @dtopt Features
  8383. * @name DataTable.defaults.deferRender
  8384. *
  8385. * @example
  8386. * $(document).ready( function() {
  8387. * $('#example').dataTable( {
  8388. * "ajax": "sources/arrays.txt",
  8389. * "deferRender": true
  8390. * } );
  8391. * } );
  8392. */
  8393. "bDeferRender": false,
  8394. /**
  8395. * Replace a DataTable which matches the given selector and replace it with
  8396. * one which has the properties of the new initialisation object passed. If no
  8397. * table matches the selector, then the new DataTable will be constructed as
  8398. * per normal.
  8399. * @type boolean
  8400. * @default false
  8401. *
  8402. * @dtopt Options
  8403. * @name DataTable.defaults.destroy
  8404. *
  8405. * @example
  8406. * $(document).ready( function() {
  8407. * $('#example').dataTable( {
  8408. * "srollY": "200px",
  8409. * "paginate": false
  8410. * } );
  8411. *
  8412. * // Some time later....
  8413. * $('#example').dataTable( {
  8414. * "filter": false,
  8415. * "destroy": true
  8416. * } );
  8417. * } );
  8418. */
  8419. "bDestroy": false,
  8420. /**
  8421. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  8422. * that it allows the end user to input multiple words (space separated) and
  8423. * will match a row containing those words, even if not in the order that was
  8424. * specified (this allow matching across multiple columns). Note that if you
  8425. * wish to use filtering in DataTables this must remain 'true' - to remove the
  8426. * default filtering input box and retain filtering abilities, please use
  8427. * {@link DataTable.defaults.dom}.
  8428. * @type boolean
  8429. * @default true
  8430. *
  8431. * @dtopt Features
  8432. * @name DataTable.defaults.searching
  8433. *
  8434. * @example
  8435. * $(document).ready( function () {
  8436. * $('#example').dataTable( {
  8437. * "searching": false
  8438. * } );
  8439. * } );
  8440. */
  8441. "bFilter": true,
  8442. /**
  8443. * Enable or disable the table information display. This shows information
  8444. * about the data that is currently visible on the page, including information
  8445. * about filtered data if that action is being performed.
  8446. * @type boolean
  8447. * @default true
  8448. *
  8449. * @dtopt Features
  8450. * @name DataTable.defaults.info
  8451. *
  8452. * @example
  8453. * $(document).ready( function () {
  8454. * $('#example').dataTable( {
  8455. * "info": false
  8456. * } );
  8457. * } );
  8458. */
  8459. "bInfo": true,
  8460. /**
  8461. * Allows the end user to select the size of a formatted page from a select
  8462. * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
  8463. * @type boolean
  8464. * @default true
  8465. *
  8466. * @dtopt Features
  8467. * @name DataTable.defaults.lengthChange
  8468. *
  8469. * @example
  8470. * $(document).ready( function () {
  8471. * $('#example').dataTable( {
  8472. * "lengthChange": false
  8473. * } );
  8474. * } );
  8475. */
  8476. "bLengthChange": true,
  8477. /**
  8478. * Enable or disable pagination.
  8479. * @type boolean
  8480. * @default true
  8481. *
  8482. * @dtopt Features
  8483. * @name DataTable.defaults.paging
  8484. *
  8485. * @example
  8486. * $(document).ready( function () {
  8487. * $('#example').dataTable( {
  8488. * "paging": false
  8489. * } );
  8490. * } );
  8491. */
  8492. "bPaginate": true,
  8493. /**
  8494. * Enable or disable the display of a 'processing' indicator when the table is
  8495. * being processed (e.g. a sort). This is particularly useful for tables with
  8496. * large amounts of data where it can take a noticeable amount of time to sort
  8497. * the entries.
  8498. * @type boolean
  8499. * @default false
  8500. *
  8501. * @dtopt Features
  8502. * @name DataTable.defaults.processing
  8503. *
  8504. * @example
  8505. * $(document).ready( function () {
  8506. * $('#example').dataTable( {
  8507. * "processing": true
  8508. * } );
  8509. * } );
  8510. */
  8511. "bProcessing": false,
  8512. /**
  8513. * Retrieve the DataTables object for the given selector. Note that if the
  8514. * table has already been initialised, this parameter will cause DataTables
  8515. * to simply return the object that has already been set up - it will not take
  8516. * account of any changes you might have made to the initialisation object
  8517. * passed to DataTables (setting this parameter to true is an acknowledgement
  8518. * that you understand this). `destroy` can be used to reinitialise a table if
  8519. * you need.
  8520. * @type boolean
  8521. * @default false
  8522. *
  8523. * @dtopt Options
  8524. * @name DataTable.defaults.retrieve
  8525. *
  8526. * @example
  8527. * $(document).ready( function() {
  8528. * initTable();
  8529. * tableActions();
  8530. * } );
  8531. *
  8532. * function initTable ()
  8533. * {
  8534. * return $('#example').dataTable( {
  8535. * "scrollY": "200px",
  8536. * "paginate": false,
  8537. * "retrieve": true
  8538. * } );
  8539. * }
  8540. *
  8541. * function tableActions ()
  8542. * {
  8543. * var table = initTable();
  8544. * // perform API operations with oTable
  8545. * }
  8546. */
  8547. "bRetrieve": false,
  8548. /**
  8549. * When vertical (y) scrolling is enabled, DataTables will force the height of
  8550. * the table's viewport to the given height at all times (useful for layout).
  8551. * However, this can look odd when filtering data down to a small data set,
  8552. * and the footer is left "floating" further down. This parameter (when
  8553. * enabled) will cause DataTables to collapse the table's viewport down when
  8554. * the result set will fit within the given Y height.
  8555. * @type boolean
  8556. * @default false
  8557. *
  8558. * @dtopt Options
  8559. * @name DataTable.defaults.scrollCollapse
  8560. *
  8561. * @example
  8562. * $(document).ready( function() {
  8563. * $('#example').dataTable( {
  8564. * "scrollY": "200",
  8565. * "scrollCollapse": true
  8566. * } );
  8567. * } );
  8568. */
  8569. "bScrollCollapse": false,
  8570. /**
  8571. * Configure DataTables to use server-side processing. Note that the
  8572. * `ajax` parameter must also be given in order to give DataTables a
  8573. * source to obtain the required data for each draw.
  8574. * @type boolean
  8575. * @default false
  8576. *
  8577. * @dtopt Features
  8578. * @dtopt Server-side
  8579. * @name DataTable.defaults.serverSide
  8580. *
  8581. * @example
  8582. * $(document).ready( function () {
  8583. * $('#example').dataTable( {
  8584. * "serverSide": true,
  8585. * "ajax": "xhr.php"
  8586. * } );
  8587. * } );
  8588. */
  8589. "bServerSide": false,
  8590. /**
  8591. * Enable or disable sorting of columns. Sorting of individual columns can be
  8592. * disabled by the `sortable` option for each column.
  8593. * @type boolean
  8594. * @default true
  8595. *
  8596. * @dtopt Features
  8597. * @name DataTable.defaults.ordering
  8598. *
  8599. * @example
  8600. * $(document).ready( function () {
  8601. * $('#example').dataTable( {
  8602. * "ordering": false
  8603. * } );
  8604. * } );
  8605. */
  8606. "bSort": true,
  8607. /**
  8608. * Enable or display DataTables' ability to sort multiple columns at the
  8609. * same time (activated by shift-click by the user).
  8610. * @type boolean
  8611. * @default true
  8612. *
  8613. * @dtopt Options
  8614. * @name DataTable.defaults.orderMulti
  8615. *
  8616. * @example
  8617. * // Disable multiple column sorting ability
  8618. * $(document).ready( function () {
  8619. * $('#example').dataTable( {
  8620. * "orderMulti": false
  8621. * } );
  8622. * } );
  8623. */
  8624. "bSortMulti": true,
  8625. /**
  8626. * Allows control over whether DataTables should use the top (true) unique
  8627. * cell that is found for a single column, or the bottom (false - default).
  8628. * This is useful when using complex headers.
  8629. * @type boolean
  8630. * @default false
  8631. *
  8632. * @dtopt Options
  8633. * @name DataTable.defaults.orderCellsTop
  8634. *
  8635. * @example
  8636. * $(document).ready( function() {
  8637. * $('#example').dataTable( {
  8638. * "orderCellsTop": true
  8639. * } );
  8640. * } );
  8641. */
  8642. "bSortCellsTop": false,
  8643. /**
  8644. * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
  8645. * `sorting\_3` to the columns which are currently being sorted on. This is
  8646. * presented as a feature switch as it can increase processing time (while
  8647. * classes are removed and added) so for large data sets you might want to
  8648. * turn this off.
  8649. * @type boolean
  8650. * @default true
  8651. *
  8652. * @dtopt Features
  8653. * @name DataTable.defaults.orderClasses
  8654. *
  8655. * @example
  8656. * $(document).ready( function () {
  8657. * $('#example').dataTable( {
  8658. * "orderClasses": false
  8659. * } );
  8660. * } );
  8661. */
  8662. "bSortClasses": true,
  8663. /**
  8664. * Enable or disable state saving. When enabled HTML5 `localStorage` will be
  8665. * used to save table display information such as pagination information,
  8666. * display length, filtering and sorting. As such when the end user reloads
  8667. * the page the display display will match what thy had previously set up.
  8668. *
  8669. * Due to the use of `localStorage` the default state saving is not supported
  8670. * in IE6 or 7. If state saving is required in those browsers, use
  8671. * `stateSaveCallback` to provide a storage solution such as cookies.
  8672. * @type boolean
  8673. * @default false
  8674. *
  8675. * @dtopt Features
  8676. * @name DataTable.defaults.stateSave
  8677. *
  8678. * @example
  8679. * $(document).ready( function () {
  8680. * $('#example').dataTable( {
  8681. * "stateSave": true
  8682. * } );
  8683. * } );
  8684. */
  8685. "bStateSave": false,
  8686. /**
  8687. * This function is called when a TR element is created (and all TD child
  8688. * elements have been inserted), or registered if using a DOM source, allowing
  8689. * manipulation of the TR element (adding classes etc).
  8690. * @type function
  8691. * @param {node} row "TR" element for the current row
  8692. * @param {array} data Raw data array for this row
  8693. * @param {int} dataIndex The index of this row in the internal aoData array
  8694. *
  8695. * @dtopt Callbacks
  8696. * @name DataTable.defaults.createdRow
  8697. *
  8698. * @example
  8699. * $(document).ready( function() {
  8700. * $('#example').dataTable( {
  8701. * "createdRow": function( row, data, dataIndex ) {
  8702. * // Bold the grade for all 'A' grade browsers
  8703. * if ( data[4] == "A" )
  8704. * {
  8705. * $('td:eq(4)', row).html( '<b>A</b>' );
  8706. * }
  8707. * }
  8708. * } );
  8709. * } );
  8710. */
  8711. "fnCreatedRow": null,
  8712. /**
  8713. * This function is called on every 'draw' event, and allows you to
  8714. * dynamically modify any aspect you want about the created DOM.
  8715. * @type function
  8716. * @param {object} settings DataTables settings object
  8717. *
  8718. * @dtopt Callbacks
  8719. * @name DataTable.defaults.drawCallback
  8720. *
  8721. * @example
  8722. * $(document).ready( function() {
  8723. * $('#example').dataTable( {
  8724. * "drawCallback": function( settings ) {
  8725. * alert( 'DataTables has redrawn the table' );
  8726. * }
  8727. * } );
  8728. * } );
  8729. */
  8730. "fnDrawCallback": null,
  8731. /**
  8732. * Identical to fnHeaderCallback() but for the table footer this function
  8733. * allows you to modify the table footer on every 'draw' event.
  8734. * @type function
  8735. * @param {node} foot "TR" element for the footer
  8736. * @param {array} data Full table data (as derived from the original HTML)
  8737. * @param {int} start Index for the current display starting point in the
  8738. * display array
  8739. * @param {int} end Index for the current display ending point in the
  8740. * display array
  8741. * @param {array int} display Index array to translate the visual position
  8742. * to the full data array
  8743. *
  8744. * @dtopt Callbacks
  8745. * @name DataTable.defaults.footerCallback
  8746. *
  8747. * @example
  8748. * $(document).ready( function() {
  8749. * $('#example').dataTable( {
  8750. * "footerCallback": function( tfoot, data, start, end, display ) {
  8751. * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
  8752. * }
  8753. * } );
  8754. * } )
  8755. */
  8756. "fnFooterCallback": null,
  8757. /**
  8758. * When rendering large numbers in the information element for the table
  8759. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  8760. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  8761. * rendered as "1,000,000") to help readability for the end user. This
  8762. * function will override the default method DataTables uses.
  8763. * @type function
  8764. * @member
  8765. * @param {int} toFormat number to be formatted
  8766. * @returns {string} formatted string for DataTables to show the number
  8767. *
  8768. * @dtopt Callbacks
  8769. * @name DataTable.defaults.formatNumber
  8770. *
  8771. * @example
  8772. * // Format a number using a single quote for the separator (note that
  8773. * // this can also be done with the language.thousands option)
  8774. * $(document).ready( function() {
  8775. * $('#example').dataTable( {
  8776. * "formatNumber": function ( toFormat ) {
  8777. * return toFormat.toString().replace(
  8778. * /\B(?=(\d{3})+(?!\d))/g, "'"
  8779. * );
  8780. * };
  8781. * } );
  8782. * } );
  8783. */
  8784. "fnFormatNumber": function (toFormat) {
  8785. return toFormat.toString().replace(
  8786. /\B(?=(\d{3})+(?!\d))/g,
  8787. this.oLanguage.sThousands
  8788. );
  8789. },
  8790. /**
  8791. * This function is called on every 'draw' event, and allows you to
  8792. * dynamically modify the header row. This can be used to calculate and
  8793. * display useful information about the table.
  8794. * @type function
  8795. * @param {node} head "TR" element for the header
  8796. * @param {array} data Full table data (as derived from the original HTML)
  8797. * @param {int} start Index for the current display starting point in the
  8798. * display array
  8799. * @param {int} end Index for the current display ending point in the
  8800. * display array
  8801. * @param {array int} display Index array to translate the visual position
  8802. * to the full data array
  8803. *
  8804. * @dtopt Callbacks
  8805. * @name DataTable.defaults.headerCallback
  8806. *
  8807. * @example
  8808. * $(document).ready( function() {
  8809. * $('#example').dataTable( {
  8810. * "fheaderCallback": function( head, data, start, end, display ) {
  8811. * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
  8812. * }
  8813. * } );
  8814. * } )
  8815. */
  8816. "fnHeaderCallback": null,
  8817. /**
  8818. * The information element can be used to convey information about the current
  8819. * state of the table. Although the internationalisation options presented by
  8820. * DataTables are quite capable of dealing with most customisations, there may
  8821. * be times where you wish to customise the string further. This callback
  8822. * allows you to do exactly that.
  8823. * @type function
  8824. * @param {object} oSettings DataTables settings object
  8825. * @param {int} start Starting position in data for the draw
  8826. * @param {int} end End position in data for the draw
  8827. * @param {int} max Total number of rows in the table (regardless of
  8828. * filtering)
  8829. * @param {int} total Total number of rows in the data set, after filtering
  8830. * @param {string} pre The string that DataTables has formatted using it's
  8831. * own rules
  8832. * @returns {string} The string to be displayed in the information element.
  8833. *
  8834. * @dtopt Callbacks
  8835. * @name DataTable.defaults.infoCallback
  8836. *
  8837. * @example
  8838. * $('#example').dataTable( {
  8839. * "infoCallback": function( settings, start, end, max, total, pre ) {
  8840. * return start +" to "+ end;
  8841. * }
  8842. * } );
  8843. */
  8844. "fnInfoCallback": null,
  8845. /**
  8846. * Called when the table has been initialised. Normally DataTables will
  8847. * initialise sequentially and there will be no need for this function,
  8848. * however, this does not hold true when using external language information
  8849. * since that is obtained using an async XHR call.
  8850. * @type function
  8851. * @param {object} settings DataTables settings object
  8852. * @param {object} json The JSON object request from the server - only
  8853. * present if client-side Ajax sourced data is used
  8854. *
  8855. * @dtopt Callbacks
  8856. * @name DataTable.defaults.initComplete
  8857. *
  8858. * @example
  8859. * $(document).ready( function() {
  8860. * $('#example').dataTable( {
  8861. * "initComplete": function(settings, json) {
  8862. * alert( 'DataTables has finished its initialisation.' );
  8863. * }
  8864. * } );
  8865. * } )
  8866. */
  8867. "fnInitComplete": null,
  8868. /**
  8869. * Called at the very start of each table draw and can be used to cancel the
  8870. * draw by returning false, any other return (including undefined) results in
  8871. * the full draw occurring).
  8872. * @type function
  8873. * @param {object} settings DataTables settings object
  8874. * @returns {boolean} False will cancel the draw, anything else (including no
  8875. * return) will allow it to complete.
  8876. *
  8877. * @dtopt Callbacks
  8878. * @name DataTable.defaults.preDrawCallback
  8879. *
  8880. * @example
  8881. * $(document).ready( function() {
  8882. * $('#example').dataTable( {
  8883. * "preDrawCallback": function( settings ) {
  8884. * if ( $('#test').val() == 1 ) {
  8885. * return false;
  8886. * }
  8887. * }
  8888. * } );
  8889. * } );
  8890. */
  8891. "fnPreDrawCallback": null,
  8892. /**
  8893. * This function allows you to 'post process' each row after it have been
  8894. * generated for each table draw, but before it is rendered on screen. This
  8895. * function might be used for setting the row class name etc.
  8896. * @type function
  8897. * @param {node} row "TR" element for the current row
  8898. * @param {array} data Raw data array for this row
  8899. * @param {int} displayIndex The display index for the current table draw
  8900. * @param {int} displayIndexFull The index of the data in the full list of
  8901. * rows (after filtering)
  8902. *
  8903. * @dtopt Callbacks
  8904. * @name DataTable.defaults.rowCallback
  8905. *
  8906. * @example
  8907. * $(document).ready( function() {
  8908. * $('#example').dataTable( {
  8909. * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
  8910. * // Bold the grade for all 'A' grade browsers
  8911. * if ( data[4] == "A" ) {
  8912. * $('td:eq(4)', row).html( '<b>A</b>' );
  8913. * }
  8914. * }
  8915. * } );
  8916. * } );
  8917. */
  8918. "fnRowCallback": null,
  8919. /**
  8920. * __Deprecated__ The functionality provided by this parameter has now been
  8921. * superseded by that provided through `ajax`, which should be used instead.
  8922. *
  8923. * This parameter allows you to override the default function which obtains
  8924. * the data from the server so something more suitable for your application.
  8925. * For example you could use POST data, or pull information from a Gears or
  8926. * AIR database.
  8927. * @type function
  8928. * @member
  8929. * @param {string} source HTTP source to obtain the data from (`ajax`)
  8930. * @param {array} data A key/value pair object containing the data to send
  8931. * to the server
  8932. * @param {function} callback to be called on completion of the data get
  8933. * process that will draw the data on the page.
  8934. * @param {object} settings DataTables settings object
  8935. *
  8936. * @dtopt Callbacks
  8937. * @dtopt Server-side
  8938. * @name DataTable.defaults.serverData
  8939. *
  8940. * @deprecated 1.10. Please use `ajax` for this functionality now.
  8941. */
  8942. "fnServerData": null,
  8943. /**
  8944. * __Deprecated__ The functionality provided by this parameter has now been
  8945. * superseded by that provided through `ajax`, which should be used instead.
  8946. *
  8947. * It is often useful to send extra data to the server when making an Ajax
  8948. * request - for example custom filtering information, and this callback
  8949. * function makes it trivial to send extra information to the server. The
  8950. * passed in parameter is the data set that has been constructed by
  8951. * DataTables, and you can add to this or modify it as you require.
  8952. * @type function
  8953. * @param {array} data Data array (array of objects which are name/value
  8954. * pairs) that has been constructed by DataTables and will be sent to the
  8955. * server. In the case of Ajax sourced data with server-side processing
  8956. * this will be an empty array, for server-side processing there will be a
  8957. * significant number of parameters!
  8958. * @returns {undefined} Ensure that you modify the data array passed in,
  8959. * as this is passed by reference.
  8960. *
  8961. * @dtopt Callbacks
  8962. * @dtopt Server-side
  8963. * @name DataTable.defaults.serverParams
  8964. *
  8965. * @deprecated 1.10. Please use `ajax` for this functionality now.
  8966. */
  8967. "fnServerParams": null,
  8968. /**
  8969. * Load the table state. With this function you can define from where, and how, the
  8970. * state of a table is loaded. By default DataTables will load from `localStorage`
  8971. * but you might wish to use a server-side database or cookies.
  8972. * @type function
  8973. * @member
  8974. * @param {object} settings DataTables settings object
  8975. * @param {object} callback Callback that can be executed when done. It
  8976. * should be passed the loaded state object.
  8977. * @return {object} The DataTables state object to be loaded
  8978. *
  8979. * @dtopt Callbacks
  8980. * @name DataTable.defaults.stateLoadCallback
  8981. *
  8982. * @example
  8983. * $(document).ready( function() {
  8984. * $('#example').dataTable( {
  8985. * "stateSave": true,
  8986. * "stateLoadCallback": function (settings, callback) {
  8987. * $.ajax( {
  8988. * "url": "/state_load",
  8989. * "dataType": "json",
  8990. * "success": function (json) {
  8991. * callback( json );
  8992. * }
  8993. * } );
  8994. * }
  8995. * } );
  8996. * } );
  8997. */
  8998. "fnStateLoadCallback": function (settings) {
  8999. try {
  9000. return JSON.parse(
  9001. (settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem(
  9002. 'DataTables_' + settings.sInstance + '_' + location.pathname
  9003. )
  9004. );
  9005. } catch (e) {
  9006. return {};
  9007. }
  9008. },
  9009. /**
  9010. * Callback which allows modification of the saved state prior to loading that state.
  9011. * This callback is called when the table is loading state from the stored data, but
  9012. * prior to the settings object being modified by the saved state. Note that for
  9013. * plug-in authors, you should use the `stateLoadParams` event to load parameters for
  9014. * a plug-in.
  9015. * @type function
  9016. * @param {object} settings DataTables settings object
  9017. * @param {object} data The state object that is to be loaded
  9018. *
  9019. * @dtopt Callbacks
  9020. * @name DataTable.defaults.stateLoadParams
  9021. *
  9022. * @example
  9023. * // Remove a saved filter, so filtering is never loaded
  9024. * $(document).ready( function() {
  9025. * $('#example').dataTable( {
  9026. * "stateSave": true,
  9027. * "stateLoadParams": function (settings, data) {
  9028. * data.oSearch.sSearch = "";
  9029. * }
  9030. * } );
  9031. * } );
  9032. *
  9033. * @example
  9034. * // Disallow state loading by returning false
  9035. * $(document).ready( function() {
  9036. * $('#example').dataTable( {
  9037. * "stateSave": true,
  9038. * "stateLoadParams": function (settings, data) {
  9039. * return false;
  9040. * }
  9041. * } );
  9042. * } );
  9043. */
  9044. "fnStateLoadParams": null,
  9045. /**
  9046. * Callback that is called when the state has been loaded from the state saving method
  9047. * and the DataTables settings object has been modified as a result of the loaded state.
  9048. * @type function
  9049. * @param {object} settings DataTables settings object
  9050. * @param {object} data The state object that was loaded
  9051. *
  9052. * @dtopt Callbacks
  9053. * @name DataTable.defaults.stateLoaded
  9054. *
  9055. * @example
  9056. * // Show an alert with the filtering value that was saved
  9057. * $(document).ready( function() {
  9058. * $('#example').dataTable( {
  9059. * "stateSave": true,
  9060. * "stateLoaded": function (settings, data) {
  9061. * alert( 'Saved filter was: '+data.oSearch.sSearch );
  9062. * }
  9063. * } );
  9064. * } );
  9065. */
  9066. "fnStateLoaded": null,
  9067. /**
  9068. * Save the table state. This function allows you to define where and how the state
  9069. * information for the table is stored By default DataTables will use `localStorage`
  9070. * but you might wish to use a server-side database or cookies.
  9071. * @type function
  9072. * @member
  9073. * @param {object} settings DataTables settings object
  9074. * @param {object} data The state object to be saved
  9075. *
  9076. * @dtopt Callbacks
  9077. * @name DataTable.defaults.stateSaveCallback
  9078. *
  9079. * @example
  9080. * $(document).ready( function() {
  9081. * $('#example').dataTable( {
  9082. * "stateSave": true,
  9083. * "stateSaveCallback": function (settings, data) {
  9084. * // Send an Ajax request to the server with the state object
  9085. * $.ajax( {
  9086. * "url": "/state_save",
  9087. * "data": data,
  9088. * "dataType": "json",
  9089. * "method": "POST"
  9090. * "success": function () {}
  9091. * } );
  9092. * }
  9093. * } );
  9094. * } );
  9095. */
  9096. "fnStateSaveCallback": function (settings, data) {
  9097. try {
  9098. (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem(
  9099. 'DataTables_' + settings.sInstance + '_' + location.pathname,
  9100. JSON.stringify(data)
  9101. );
  9102. } catch (e) {
  9103. }
  9104. },
  9105. /**
  9106. * Callback which allows modification of the state to be saved. Called when the table
  9107. * has changed state a new state save is required. This method allows modification of
  9108. * the state saving object prior to actually doing the save, including addition or
  9109. * other state properties or modification. Note that for plug-in authors, you should
  9110. * use the `stateSaveParams` event to save parameters for a plug-in.
  9111. * @type function
  9112. * @param {object} settings DataTables settings object
  9113. * @param {object} data The state object to be saved
  9114. *
  9115. * @dtopt Callbacks
  9116. * @name DataTable.defaults.stateSaveParams
  9117. *
  9118. * @example
  9119. * // Remove a saved filter, so filtering is never saved
  9120. * $(document).ready( function() {
  9121. * $('#example').dataTable( {
  9122. * "stateSave": true,
  9123. * "stateSaveParams": function (settings, data) {
  9124. * data.oSearch.sSearch = "";
  9125. * }
  9126. * } );
  9127. * } );
  9128. */
  9129. "fnStateSaveParams": null,
  9130. /**
  9131. * Duration for which the saved state information is considered valid. After this period
  9132. * has elapsed the state will be returned to the default.
  9133. * Value is given in seconds.
  9134. * @type int
  9135. * @default 7200 <i>(2 hours)</i>
  9136. *
  9137. * @dtopt Options
  9138. * @name DataTable.defaults.stateDuration
  9139. *
  9140. * @example
  9141. * $(document).ready( function() {
  9142. * $('#example').dataTable( {
  9143. * "stateDuration": 60*60*24; // 1 day
  9144. * } );
  9145. * } )
  9146. */
  9147. "iStateDuration": 7200,
  9148. /**
  9149. * When enabled DataTables will not make a request to the server for the first
  9150. * page draw - rather it will use the data already on the page (no sorting etc
  9151. * will be applied to it), thus saving on an XHR at load time. `deferLoading`
  9152. * is used to indicate that deferred loading is required, but it is also used
  9153. * to tell DataTables how many records there are in the full table (allowing
  9154. * the information element and pagination to be displayed correctly). In the case
  9155. * where a filtering is applied to the table on initial load, this can be
  9156. * indicated by giving the parameter as an array, where the first element is
  9157. * the number of records available after filtering and the second element is the
  9158. * number of records without filtering (allowing the table information element
  9159. * to be shown correctly).
  9160. * @type int | array
  9161. * @default null
  9162. *
  9163. * @dtopt Options
  9164. * @name DataTable.defaults.deferLoading
  9165. *
  9166. * @example
  9167. * // 57 records available in the table, no filtering applied
  9168. * $(document).ready( function() {
  9169. * $('#example').dataTable( {
  9170. * "serverSide": true,
  9171. * "ajax": "scripts/server_processing.php",
  9172. * "deferLoading": 57
  9173. * } );
  9174. * } );
  9175. *
  9176. * @example
  9177. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  9178. * $(document).ready( function() {
  9179. * $('#example').dataTable( {
  9180. * "serverSide": true,
  9181. * "ajax": "scripts/server_processing.php",
  9182. * "deferLoading": [ 57, 100 ],
  9183. * "search": {
  9184. * "search": "my_filter"
  9185. * }
  9186. * } );
  9187. * } );
  9188. */
  9189. "iDeferLoading": null,
  9190. /**
  9191. * Number of rows to display on a single page when using pagination. If
  9192. * feature enabled (`lengthChange`) then the end user will be able to override
  9193. * this to a custom setting using a pop-up menu.
  9194. * @type int
  9195. * @default 10
  9196. *
  9197. * @dtopt Options
  9198. * @name DataTable.defaults.pageLength
  9199. *
  9200. * @example
  9201. * $(document).ready( function() {
  9202. * $('#example').dataTable( {
  9203. * "pageLength": 50
  9204. * } );
  9205. * } )
  9206. */
  9207. "iDisplayLength": 10,
  9208. /**
  9209. * Define the starting point for data display when using DataTables with
  9210. * pagination. Note that this parameter is the number of records, rather than
  9211. * the page number, so if you have 10 records per page and want to start on
  9212. * the third page, it should be "20".
  9213. * @type int
  9214. * @default 0
  9215. *
  9216. * @dtopt Options
  9217. * @name DataTable.defaults.displayStart
  9218. *
  9219. * @example
  9220. * $(document).ready( function() {
  9221. * $('#example').dataTable( {
  9222. * "displayStart": 20
  9223. * } );
  9224. * } )
  9225. */
  9226. "iDisplayStart": 0,
  9227. /**
  9228. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  9229. * and filtering) by adding a `tabindex` attribute to the required elements. This
  9230. * allows you to tab through the controls and press the enter key to activate them.
  9231. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  9232. * You can overrule this using this parameter if you wish. Use a value of -1 to
  9233. * disable built-in keyboard navigation.
  9234. * @type int
  9235. * @default 0
  9236. *
  9237. * @dtopt Options
  9238. * @name DataTable.defaults.tabIndex
  9239. *
  9240. * @example
  9241. * $(document).ready( function() {
  9242. * $('#example').dataTable( {
  9243. * "tabIndex": 1
  9244. * } );
  9245. * } );
  9246. */
  9247. "iTabIndex": 0,
  9248. /**
  9249. * Classes that DataTables assigns to the various components and features
  9250. * that it adds to the HTML table. This allows classes to be configured
  9251. * during initialisation in addition to through the static
  9252. * {@link DataTable.ext.oStdClasses} object).
  9253. * @namespace
  9254. * @name DataTable.defaults.classes
  9255. */
  9256. "oClasses": {},
  9257. /**
  9258. * All strings that DataTables uses in the user interface that it creates
  9259. * are defined in this object, allowing you to modified them individually or
  9260. * completely replace them all as required.
  9261. * @namespace
  9262. * @name DataTable.defaults.language
  9263. */
  9264. "oLanguage": {
  9265. /**
  9266. * Strings that are used for WAI-ARIA labels and controls only (these are not
  9267. * actually visible on the page, but will be read by screenreaders, and thus
  9268. * must be internationalised as well).
  9269. * @namespace
  9270. * @name DataTable.defaults.language.aria
  9271. */
  9272. "oAria": {
  9273. /**
  9274. * ARIA label that is added to the table headers when the column may be
  9275. * sorted ascending by activing the column (click or return when focused).
  9276. * Note that the column header is prefixed to this string.
  9277. * @type string
  9278. * @default : activate to sort column ascending
  9279. *
  9280. * @dtopt Language
  9281. * @name DataTable.defaults.language.aria.sortAscending
  9282. *
  9283. * @example
  9284. * $(document).ready( function() {
  9285. * $('#example').dataTable( {
  9286. * "language": {
  9287. * "aria": {
  9288. * "sortAscending": " - click/return to sort ascending"
  9289. * }
  9290. * }
  9291. * } );
  9292. * } );
  9293. */
  9294. "sSortAscending": ": activate to sort column ascending",
  9295. /**
  9296. * ARIA label that is added to the table headers when the column may be
  9297. * sorted descending by activing the column (click or return when focused).
  9298. * Note that the column header is prefixed to this string.
  9299. * @type string
  9300. * @default : activate to sort column ascending
  9301. *
  9302. * @dtopt Language
  9303. * @name DataTable.defaults.language.aria.sortDescending
  9304. *
  9305. * @example
  9306. * $(document).ready( function() {
  9307. * $('#example').dataTable( {
  9308. * "language": {
  9309. * "aria": {
  9310. * "sortDescending": " - click/return to sort descending"
  9311. * }
  9312. * }
  9313. * } );
  9314. * } );
  9315. */
  9316. "sSortDescending": ": activate to sort column descending"
  9317. },
  9318. /**
  9319. * Pagination string used by DataTables for the built-in pagination
  9320. * control types.
  9321. * @namespace
  9322. * @name DataTable.defaults.language.paginate
  9323. */
  9324. "oPaginate": {
  9325. /**
  9326. * Text to use when using the 'full_numbers' type of pagination for the
  9327. * button to take the user to the first page.
  9328. * @type string
  9329. * @default First
  9330. *
  9331. * @dtopt Language
  9332. * @name DataTable.defaults.language.paginate.first
  9333. *
  9334. * @example
  9335. * $(document).ready( function() {
  9336. * $('#example').dataTable( {
  9337. * "language": {
  9338. * "paginate": {
  9339. * "first": "First page"
  9340. * }
  9341. * }
  9342. * } );
  9343. * } );
  9344. */
  9345. "sFirst": "First",
  9346. /**
  9347. * Text to use when using the 'full_numbers' type of pagination for the
  9348. * button to take the user to the last page.
  9349. * @type string
  9350. * @default Last
  9351. *
  9352. * @dtopt Language
  9353. * @name DataTable.defaults.language.paginate.last
  9354. *
  9355. * @example
  9356. * $(document).ready( function() {
  9357. * $('#example').dataTable( {
  9358. * "language": {
  9359. * "paginate": {
  9360. * "last": "Last page"
  9361. * }
  9362. * }
  9363. * } );
  9364. * } );
  9365. */
  9366. "sLast": "Last",
  9367. /**
  9368. * Text to use for the 'next' pagination button (to take the user to the
  9369. * next page).
  9370. * @type string
  9371. * @default Next
  9372. *
  9373. * @dtopt Language
  9374. * @name DataTable.defaults.language.paginate.next
  9375. *
  9376. * @example
  9377. * $(document).ready( function() {
  9378. * $('#example').dataTable( {
  9379. * "language": {
  9380. * "paginate": {
  9381. * "next": "Next page"
  9382. * }
  9383. * }
  9384. * } );
  9385. * } );
  9386. */
  9387. "sNext": "Next",
  9388. /**
  9389. * Text to use for the 'previous' pagination button (to take the user to
  9390. * the previous page).
  9391. * @type string
  9392. * @default Previous
  9393. *
  9394. * @dtopt Language
  9395. * @name DataTable.defaults.language.paginate.previous
  9396. *
  9397. * @example
  9398. * $(document).ready( function() {
  9399. * $('#example').dataTable( {
  9400. * "language": {
  9401. * "paginate": {
  9402. * "previous": "Previous page"
  9403. * }
  9404. * }
  9405. * } );
  9406. * } );
  9407. */
  9408. "sPrevious": "Previous"
  9409. },
  9410. /**
  9411. * This string is shown in preference to `zeroRecords` when the table is
  9412. * empty of data (regardless of filtering). Note that this is an optional
  9413. * parameter - if it is not given, the value of `zeroRecords` will be used
  9414. * instead (either the default or given value).
  9415. * @type string
  9416. * @default No data available in table
  9417. *
  9418. * @dtopt Language
  9419. * @name DataTable.defaults.language.emptyTable
  9420. *
  9421. * @example
  9422. * $(document).ready( function() {
  9423. * $('#example').dataTable( {
  9424. * "language": {
  9425. * "emptyTable": "No data available in table"
  9426. * }
  9427. * } );
  9428. * } );
  9429. */
  9430. "sEmptyTable": "No data available in table",
  9431. /**
  9432. * This string gives information to the end user about the information
  9433. * that is current on display on the page. The following tokens can be
  9434. * used in the string and will be dynamically replaced as the table
  9435. * display updates. This tokens can be placed anywhere in the string, or
  9436. * removed as needed by the language requires:
  9437. *
  9438. * * `\_START\_` - Display index of the first record on the current page
  9439. * * `\_END\_` - Display index of the last record on the current page
  9440. * * `\_TOTAL\_` - Number of records in the table after filtering
  9441. * * `\_MAX\_` - Number of records in the table without filtering
  9442. * * `\_PAGE\_` - Current page number
  9443. * * `\_PAGES\_` - Total number of pages of data in the table
  9444. *
  9445. * @type string
  9446. * @default Showing _START_ to _END_ of _TOTAL_ entries
  9447. *
  9448. * @dtopt Language
  9449. * @name DataTable.defaults.language.info
  9450. *
  9451. * @example
  9452. * $(document).ready( function() {
  9453. * $('#example').dataTable( {
  9454. * "language": {
  9455. * "info": "Showing page _PAGE_ of _PAGES_"
  9456. * }
  9457. * } );
  9458. * } );
  9459. */
  9460. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  9461. /**
  9462. * Display information string for when the table is empty. Typically the
  9463. * format of this string should match `info`.
  9464. * @type string
  9465. * @default Showing 0 to 0 of 0 entries
  9466. *
  9467. * @dtopt Language
  9468. * @name DataTable.defaults.language.infoEmpty
  9469. *
  9470. * @example
  9471. * $(document).ready( function() {
  9472. * $('#example').dataTable( {
  9473. * "language": {
  9474. * "infoEmpty": "No entries to show"
  9475. * }
  9476. * } );
  9477. * } );
  9478. */
  9479. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  9480. /**
  9481. * When a user filters the information in a table, this string is appended
  9482. * to the information (`info`) to give an idea of how strong the filtering
  9483. * is. The variable _MAX_ is dynamically updated.
  9484. * @type string
  9485. * @default (filtered from _MAX_ total entries)
  9486. *
  9487. * @dtopt Language
  9488. * @name DataTable.defaults.language.infoFiltered
  9489. *
  9490. * @example
  9491. * $(document).ready( function() {
  9492. * $('#example').dataTable( {
  9493. * "language": {
  9494. * "infoFiltered": " - filtering from _MAX_ records"
  9495. * }
  9496. * } );
  9497. * } );
  9498. */
  9499. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  9500. /**
  9501. * If can be useful to append extra information to the info string at times,
  9502. * and this variable does exactly that. This information will be appended to
  9503. * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
  9504. * being used) at all times.
  9505. * @type string
  9506. * @default <i>Empty string</i>
  9507. *
  9508. * @dtopt Language
  9509. * @name DataTable.defaults.language.infoPostFix
  9510. *
  9511. * @example
  9512. * $(document).ready( function() {
  9513. * $('#example').dataTable( {
  9514. * "language": {
  9515. * "infoPostFix": "All records shown are derived from real information."
  9516. * }
  9517. * } );
  9518. * } );
  9519. */
  9520. "sInfoPostFix": "",
  9521. /**
  9522. * This decimal place operator is a little different from the other
  9523. * language options since DataTables doesn't output floating point
  9524. * numbers, so it won't ever use this for display of a number. Rather,
  9525. * what this parameter does is modify the sort methods of the table so
  9526. * that numbers which are in a format which has a character other than
  9527. * a period (`.`) as a decimal place will be sorted numerically.
  9528. *
  9529. * Note that numbers with different decimal places cannot be shown in
  9530. * the same table and still be sortable, the table must be consistent.
  9531. * However, multiple different tables on the page can use different
  9532. * decimal place characters.
  9533. * @type string
  9534. * @default
  9535. *
  9536. * @dtopt Language
  9537. * @name DataTable.defaults.language.decimal
  9538. *
  9539. * @example
  9540. * $(document).ready( function() {
  9541. * $('#example').dataTable( {
  9542. * "language": {
  9543. * "decimal": ","
  9544. * "thousands": "."
  9545. * }
  9546. * } );
  9547. * } );
  9548. */
  9549. "sDecimal": "",
  9550. /**
  9551. * DataTables has a build in number formatter (`formatNumber`) which is
  9552. * used to format large numbers that are used in the table information.
  9553. * By default a comma is used, but this can be trivially changed to any
  9554. * character you wish with this parameter.
  9555. * @type string
  9556. * @default ,
  9557. *
  9558. * @dtopt Language
  9559. * @name DataTable.defaults.language.thousands
  9560. *
  9561. * @example
  9562. * $(document).ready( function() {
  9563. * $('#example').dataTable( {
  9564. * "language": {
  9565. * "thousands": "'"
  9566. * }
  9567. * } );
  9568. * } );
  9569. */
  9570. "sThousands": ",",
  9571. /**
  9572. * Detail the action that will be taken when the drop down menu for the
  9573. * pagination length option is changed. The '_MENU_' variable is replaced
  9574. * with a default select list of 10, 25, 50 and 100, and can be replaced
  9575. * with a custom select box if required.
  9576. * @type string
  9577. * @default Show _MENU_ entries
  9578. *
  9579. * @dtopt Language
  9580. * @name DataTable.defaults.language.lengthMenu
  9581. *
  9582. * @example
  9583. * // Language change only
  9584. * $(document).ready( function() {
  9585. * $('#example').dataTable( {
  9586. * "language": {
  9587. * "lengthMenu": "Display _MENU_ records"
  9588. * }
  9589. * } );
  9590. * } );
  9591. *
  9592. * @example
  9593. * // Language and options change
  9594. * $(document).ready( function() {
  9595. * $('#example').dataTable( {
  9596. * "language": {
  9597. * "lengthMenu": 'Display <select>'+
  9598. * '<option value="10">10</option>'+
  9599. * '<option value="20">20</option>'+
  9600. * '<option value="30">30</option>'+
  9601. * '<option value="40">40</option>'+
  9602. * '<option value="50">50</option>'+
  9603. * '<option value="-1">All</option>'+
  9604. * '</select> records'
  9605. * }
  9606. * } );
  9607. * } );
  9608. */
  9609. "sLengthMenu": "Show _MENU_ entries",
  9610. /**
  9611. * When using Ajax sourced data and during the first draw when DataTables is
  9612. * gathering the data, this message is shown in an empty row in the table to
  9613. * indicate to the end user the the data is being loaded. Note that this
  9614. * parameter is not used when loading data by server-side processing, just
  9615. * Ajax sourced data with client-side processing.
  9616. * @type string
  9617. * @default Loading...
  9618. *
  9619. * @dtopt Language
  9620. * @name DataTable.defaults.language.loadingRecords
  9621. *
  9622. * @example
  9623. * $(document).ready( function() {
  9624. * $('#example').dataTable( {
  9625. * "language": {
  9626. * "loadingRecords": "Please wait - loading..."
  9627. * }
  9628. * } );
  9629. * } );
  9630. */
  9631. "sLoadingRecords": "Loading...",
  9632. /**
  9633. * Text which is displayed when the table is processing a user action
  9634. * (usually a sort command or similar).
  9635. * @type string
  9636. * @default Processing...
  9637. *
  9638. * @dtopt Language
  9639. * @name DataTable.defaults.language.processing
  9640. *
  9641. * @example
  9642. * $(document).ready( function() {
  9643. * $('#example').dataTable( {
  9644. * "language": {
  9645. * "processing": "DataTables is currently busy"
  9646. * }
  9647. * } );
  9648. * } );
  9649. */
  9650. "sProcessing": "Processing...",
  9651. /**
  9652. * Details the actions that will be taken when the user types into the
  9653. * filtering input text box. The variable "_INPUT_", if used in the string,
  9654. * is replaced with the HTML text box for the filtering input allowing
  9655. * control over where it appears in the string. If "_INPUT_" is not given
  9656. * then the input box is appended to the string automatically.
  9657. * @type string
  9658. * @default Search:
  9659. *
  9660. * @dtopt Language
  9661. * @name DataTable.defaults.language.search
  9662. *
  9663. * @example
  9664. * // Input text box will be appended at the end automatically
  9665. * $(document).ready( function() {
  9666. * $('#example').dataTable( {
  9667. * "language": {
  9668. * "search": "Filter records:"
  9669. * }
  9670. * } );
  9671. * } );
  9672. *
  9673. * @example
  9674. * // Specify where the filter should appear
  9675. * $(document).ready( function() {
  9676. * $('#example').dataTable( {
  9677. * "language": {
  9678. * "search": "Apply filter _INPUT_ to table"
  9679. * }
  9680. * } );
  9681. * } );
  9682. */
  9683. "sSearch": "Search:",
  9684. /**
  9685. * Assign a `placeholder` attribute to the search `input` element
  9686. * @type string
  9687. * @default
  9688. *
  9689. * @dtopt Language
  9690. * @name DataTable.defaults.language.searchPlaceholder
  9691. */
  9692. "sSearchPlaceholder": "",
  9693. /**
  9694. * All of the language information can be stored in a file on the
  9695. * server-side, which DataTables will look up if this parameter is passed.
  9696. * It must store the URL of the language file, which is in a JSON format,
  9697. * and the object has the same properties as the oLanguage object in the
  9698. * initialiser object (i.e. the above parameters). Please refer to one of
  9699. * the example language files to see how this works in action.
  9700. * @type string
  9701. * @default <i>Empty string - i.e. disabled</i>
  9702. *
  9703. * @dtopt Language
  9704. * @name DataTable.defaults.language.url
  9705. *
  9706. * @example
  9707. * $(document).ready( function() {
  9708. * $('#example').dataTable( {
  9709. * "language": {
  9710. * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  9711. * }
  9712. * } );
  9713. * } );
  9714. */
  9715. "sUrl": "",
  9716. /**
  9717. * Text shown inside the table records when the is no information to be
  9718. * displayed after filtering. `emptyTable` is shown when there is simply no
  9719. * information in the table at all (regardless of filtering).
  9720. * @type string
  9721. * @default No matching records found
  9722. *
  9723. * @dtopt Language
  9724. * @name DataTable.defaults.language.zeroRecords
  9725. *
  9726. * @example
  9727. * $(document).ready( function() {
  9728. * $('#example').dataTable( {
  9729. * "language": {
  9730. * "zeroRecords": "No records to display"
  9731. * }
  9732. * } );
  9733. * } );
  9734. */
  9735. "sZeroRecords": "No matching records found"
  9736. },
  9737. /**
  9738. * This parameter allows you to have define the global filtering state at
  9739. * initialisation time. As an object the `search` parameter must be
  9740. * defined, but all other parameters are optional. When `regex` is true,
  9741. * the search string will be treated as a regular expression, when false
  9742. * (default) it will be treated as a straight string. When `smart`
  9743. * DataTables will use it's smart filtering methods (to word match at
  9744. * any point in the data), when false this will not be done.
  9745. * @namespace
  9746. * @extends DataTable.models.oSearch
  9747. *
  9748. * @dtopt Options
  9749. * @name DataTable.defaults.search
  9750. *
  9751. * @example
  9752. * $(document).ready( function() {
  9753. * $('#example').dataTable( {
  9754. * "search": {"search": "Initial search"}
  9755. * } );
  9756. * } )
  9757. */
  9758. "oSearch": $.extend({}, DataTable.models.oSearch),
  9759. /**
  9760. * __Deprecated__ The functionality provided by this parameter has now been
  9761. * superseded by that provided through `ajax`, which should be used instead.
  9762. *
  9763. * By default DataTables will look for the property `data` (or `aaData` for
  9764. * compatibility with DataTables 1.9-) when obtaining data from an Ajax
  9765. * source or for server-side processing - this parameter allows that
  9766. * property to be changed. You can use Javascript dotted object notation to
  9767. * get a data source for multiple levels of nesting.
  9768. * @type string
  9769. * @default data
  9770. *
  9771. * @dtopt Options
  9772. * @dtopt Server-side
  9773. * @name DataTable.defaults.ajaxDataProp
  9774. *
  9775. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9776. */
  9777. "sAjaxDataProp": "data",
  9778. /**
  9779. * __Deprecated__ The functionality provided by this parameter has now been
  9780. * superseded by that provided through `ajax`, which should be used instead.
  9781. *
  9782. * You can instruct DataTables to load data from an external
  9783. * source using this parameter (use aData if you want to pass data in you
  9784. * already have). Simply provide a url a JSON object can be obtained from.
  9785. * @type string
  9786. * @default null
  9787. *
  9788. * @dtopt Options
  9789. * @dtopt Server-side
  9790. * @name DataTable.defaults.ajaxSource
  9791. *
  9792. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9793. */
  9794. "sAjaxSource": null,
  9795. /**
  9796. * This initialisation variable allows you to specify exactly where in the
  9797. * DOM you want DataTables to inject the various controls it adds to the page
  9798. * (for example you might want the pagination controls at the top of the
  9799. * table). DIV elements (with or without a custom class) can also be added to
  9800. * aid styling. The follow syntax is used:
  9801. * <ul>
  9802. * <li>The following options are allowed:
  9803. * <ul>
  9804. * <li>'l' - Length changing</li>
  9805. * <li>'f' - Filtering input</li>
  9806. * <li>'t' - The table!</li>
  9807. * <li>'i' - Information</li>
  9808. * <li>'p' - Pagination</li>
  9809. * <li>'r' - pRocessing</li>
  9810. * </ul>
  9811. * </li>
  9812. * <li>The following constants are allowed:
  9813. * <ul>
  9814. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  9815. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  9816. * </ul>
  9817. * </li>
  9818. * <li>The following syntax is expected:
  9819. * <ul>
  9820. * <li>'&lt;' and '&gt;' - div elements</li>
  9821. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  9822. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  9823. * </ul>
  9824. * </li>
  9825. * <li>Examples:
  9826. * <ul>
  9827. * <li>'&lt;"wrapper"flipt&gt;'</li>
  9828. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  9829. * </ul>
  9830. * </li>
  9831. * </ul>
  9832. * @type string
  9833. * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
  9834. * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
  9835. *
  9836. * @dtopt Options
  9837. * @name DataTable.defaults.dom
  9838. *
  9839. * @example
  9840. * $(document).ready( function() {
  9841. * $('#example').dataTable( {
  9842. * "dom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&gt;'
  9843. * } );
  9844. * } );
  9845. */
  9846. "sDom": "lfrtip",
  9847. /**
  9848. * Search delay option. This will throttle full table searches that use the
  9849. * DataTables provided search input element (it does not effect calls to
  9850. * `dt-api search()`, providing a delay before the search is made.
  9851. * @type integer
  9852. * @default 0
  9853. *
  9854. * @dtopt Options
  9855. * @name DataTable.defaults.searchDelay
  9856. *
  9857. * @example
  9858. * $(document).ready( function() {
  9859. * $('#example').dataTable( {
  9860. * "searchDelay": 200
  9861. * } );
  9862. * } )
  9863. */
  9864. "searchDelay": null,
  9865. /**
  9866. * DataTables features six different built-in options for the buttons to
  9867. * display for pagination control:
  9868. *
  9869. * * `numbers` - Page number buttons only
  9870. * * `simple` - 'Previous' and 'Next' buttons only
  9871. * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
  9872. * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
  9873. * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers
  9874. * * `first_last_numbers` - 'First' and 'Last' buttons, plus page numbers
  9875. *
  9876. * Further methods can be added using {@link DataTable.ext.oPagination}.
  9877. * @type string
  9878. * @default simple_numbers
  9879. *
  9880. * @dtopt Options
  9881. * @name DataTable.defaults.pagingType
  9882. *
  9883. * @example
  9884. * $(document).ready( function() {
  9885. * $('#example').dataTable( {
  9886. * "pagingType": "full_numbers"
  9887. * } );
  9888. * } )
  9889. */
  9890. "sPaginationType": "simple_numbers",
  9891. /**
  9892. * Enable horizontal scrolling. When a table is too wide to fit into a
  9893. * certain layout, or you have a large number of columns in the table, you
  9894. * can enable x-scrolling to show the table in a viewport, which can be
  9895. * scrolled. This property can be `true` which will allow the table to
  9896. * scroll horizontally when needed, or any CSS unit, or a number (in which
  9897. * case it will be treated as a pixel measurement). Setting as simply `true`
  9898. * is recommended.
  9899. * @type boolean|string
  9900. * @default <i>blank string - i.e. disabled</i>
  9901. *
  9902. * @dtopt Features
  9903. * @name DataTable.defaults.scrollX
  9904. *
  9905. * @example
  9906. * $(document).ready( function() {
  9907. * $('#example').dataTable( {
  9908. * "scrollX": true,
  9909. * "scrollCollapse": true
  9910. * } );
  9911. * } );
  9912. */
  9913. "sScrollX": "",
  9914. /**
  9915. * This property can be used to force a DataTable to use more width than it
  9916. * might otherwise do when x-scrolling is enabled. For example if you have a
  9917. * table which requires to be well spaced, this parameter is useful for
  9918. * "over-sizing" the table, and thus forcing scrolling. This property can by
  9919. * any CSS unit, or a number (in which case it will be treated as a pixel
  9920. * measurement).
  9921. * @type string
  9922. * @default <i>blank string - i.e. disabled</i>
  9923. *
  9924. * @dtopt Options
  9925. * @name DataTable.defaults.scrollXInner
  9926. *
  9927. * @example
  9928. * $(document).ready( function() {
  9929. * $('#example').dataTable( {
  9930. * "scrollX": "100%",
  9931. * "scrollXInner": "110%"
  9932. * } );
  9933. * } );
  9934. */
  9935. "sScrollXInner": "",
  9936. /**
  9937. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  9938. * to the given height, and enable scrolling for any data which overflows the
  9939. * current viewport. This can be used as an alternative to paging to display
  9940. * a lot of data in a small area (although paging and scrolling can both be
  9941. * enabled at the same time). This property can be any CSS unit, or a number
  9942. * (in which case it will be treated as a pixel measurement).
  9943. * @type string
  9944. * @default <i>blank string - i.e. disabled</i>
  9945. *
  9946. * @dtopt Features
  9947. * @name DataTable.defaults.scrollY
  9948. *
  9949. * @example
  9950. * $(document).ready( function() {
  9951. * $('#example').dataTable( {
  9952. * "scrollY": "200px",
  9953. * "paginate": false
  9954. * } );
  9955. * } );
  9956. */
  9957. "sScrollY": "",
  9958. /**
  9959. * __Deprecated__ The functionality provided by this parameter has now been
  9960. * superseded by that provided through `ajax`, which should be used instead.
  9961. *
  9962. * Set the HTTP method that is used to make the Ajax call for server-side
  9963. * processing or Ajax sourced data.
  9964. * @type string
  9965. * @default GET
  9966. *
  9967. * @dtopt Options
  9968. * @dtopt Server-side
  9969. * @name DataTable.defaults.serverMethod
  9970. *
  9971. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9972. */
  9973. "sServerMethod": "GET",
  9974. /**
  9975. * DataTables makes use of renderers when displaying HTML elements for
  9976. * a table. These renderers can be added or modified by plug-ins to
  9977. * generate suitable mark-up for a site. For example the Bootstrap
  9978. * integration plug-in for DataTables uses a paging button renderer to
  9979. * display pagination buttons in the mark-up required by Bootstrap.
  9980. *
  9981. * For further information about the renderers available see
  9982. * DataTable.ext.renderer
  9983. * @type string|object
  9984. * @default null
  9985. *
  9986. * @name DataTable.defaults.renderer
  9987. *
  9988. */
  9989. "renderer": null,
  9990. /**
  9991. * Set the data property name that DataTables should use to get a row's id
  9992. * to set as the `id` property in the node.
  9993. * @type string
  9994. * @default DT_RowId
  9995. *
  9996. * @name DataTable.defaults.rowId
  9997. */
  9998. "rowId": "DT_RowId"
  9999. };
  10000. _fnHungarianMap(DataTable.defaults);
  10001. /*
  10002. * Developer note - See note in model.defaults.js about the use of Hungarian
  10003. * notation and camel case.
  10004. */
  10005. /**
  10006. * Column options that can be given to DataTables at initialisation time.
  10007. * @namespace
  10008. */
  10009. DataTable.defaults.column = {
  10010. /**
  10011. * Define which column(s) an order will occur on for this column. This
  10012. * allows a column's ordering to take multiple columns into account when
  10013. * doing a sort or use the data from a different column. For example first
  10014. * name / last name columns make sense to do a multi-column sort over the
  10015. * two columns.
  10016. * @type array|int
  10017. * @default null <i>Takes the value of the column index automatically</i>
  10018. *
  10019. * @name DataTable.defaults.column.orderData
  10020. * @dtopt Columns
  10021. *
  10022. * @example
  10023. * // Using `columnDefs`
  10024. * $(document).ready( function() {
  10025. * $('#example').dataTable( {
  10026. * "columnDefs": [
  10027. * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
  10028. * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
  10029. * { "orderData": 2, "targets": [ 2 ] }
  10030. * ]
  10031. * } );
  10032. * } );
  10033. *
  10034. * @example
  10035. * // Using `columns`
  10036. * $(document).ready( function() {
  10037. * $('#example').dataTable( {
  10038. * "columns": [
  10039. * { "orderData": [ 0, 1 ] },
  10040. * { "orderData": [ 1, 0 ] },
  10041. * { "orderData": 2 },
  10042. * null,
  10043. * null
  10044. * ]
  10045. * } );
  10046. * } );
  10047. */
  10048. "aDataSort": null,
  10049. "iDataSort": -1,
  10050. /**
  10051. * You can control the default ordering direction, and even alter the
  10052. * behaviour of the sort handler (i.e. only allow ascending ordering etc)
  10053. * using this parameter.
  10054. * @type array
  10055. * @default [ 'asc', 'desc' ]
  10056. *
  10057. * @name DataTable.defaults.column.orderSequence
  10058. * @dtopt Columns
  10059. *
  10060. * @example
  10061. * // Using `columnDefs`
  10062. * $(document).ready( function() {
  10063. * $('#example').dataTable( {
  10064. * "columnDefs": [
  10065. * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
  10066. * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
  10067. * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
  10068. * ]
  10069. * } );
  10070. * } );
  10071. *
  10072. * @example
  10073. * // Using `columns`
  10074. * $(document).ready( function() {
  10075. * $('#example').dataTable( {
  10076. * "columns": [
  10077. * null,
  10078. * { "orderSequence": [ "asc" ] },
  10079. * { "orderSequence": [ "desc", "asc", "asc" ] },
  10080. * { "orderSequence": [ "desc" ] },
  10081. * null
  10082. * ]
  10083. * } );
  10084. * } );
  10085. */
  10086. "asSorting": ['asc', 'desc'],
  10087. /**
  10088. * Enable or disable filtering on the data in this column.
  10089. * @type boolean
  10090. * @default true
  10091. *
  10092. * @name DataTable.defaults.column.searchable
  10093. * @dtopt Columns
  10094. *
  10095. * @example
  10096. * // Using `columnDefs`
  10097. * $(document).ready( function() {
  10098. * $('#example').dataTable( {
  10099. * "columnDefs": [
  10100. * { "searchable": false, "targets": [ 0 ] }
  10101. * ] } );
  10102. * } );
  10103. *
  10104. * @example
  10105. * // Using `columns`
  10106. * $(document).ready( function() {
  10107. * $('#example').dataTable( {
  10108. * "columns": [
  10109. * { "searchable": false },
  10110. * null,
  10111. * null,
  10112. * null,
  10113. * null
  10114. * ] } );
  10115. * } );
  10116. */
  10117. "bSearchable": true,
  10118. /**
  10119. * Enable or disable ordering on this column.
  10120. * @type boolean
  10121. * @default true
  10122. *
  10123. * @name DataTable.defaults.column.orderable
  10124. * @dtopt Columns
  10125. *
  10126. * @example
  10127. * // Using `columnDefs`
  10128. * $(document).ready( function() {
  10129. * $('#example').dataTable( {
  10130. * "columnDefs": [
  10131. * { "orderable": false, "targets": [ 0 ] }
  10132. * ] } );
  10133. * } );
  10134. *
  10135. * @example
  10136. * // Using `columns`
  10137. * $(document).ready( function() {
  10138. * $('#example').dataTable( {
  10139. * "columns": [
  10140. * { "orderable": false },
  10141. * null,
  10142. * null,
  10143. * null,
  10144. * null
  10145. * ] } );
  10146. * } );
  10147. */
  10148. "bSortable": true,
  10149. /**
  10150. * Enable or disable the display of this column.
  10151. * @type boolean
  10152. * @default true
  10153. *
  10154. * @name DataTable.defaults.column.visible
  10155. * @dtopt Columns
  10156. *
  10157. * @example
  10158. * // Using `columnDefs`
  10159. * $(document).ready( function() {
  10160. * $('#example').dataTable( {
  10161. * "columnDefs": [
  10162. * { "visible": false, "targets": [ 0 ] }
  10163. * ] } );
  10164. * } );
  10165. *
  10166. * @example
  10167. * // Using `columns`
  10168. * $(document).ready( function() {
  10169. * $('#example').dataTable( {
  10170. * "columns": [
  10171. * { "visible": false },
  10172. * null,
  10173. * null,
  10174. * null,
  10175. * null
  10176. * ] } );
  10177. * } );
  10178. */
  10179. "bVisible": true,
  10180. /**
  10181. * Developer definable function that is called whenever a cell is created (Ajax source,
  10182. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  10183. * allowing you to modify the DOM element (add background colour for example) when the
  10184. * element is available.
  10185. * @type function
  10186. * @param {element} td The TD node that has been created
  10187. * @param {*} cellData The Data for the cell
  10188. * @param {array|object} rowData The data for the whole row
  10189. * @param {int} row The row index for the aoData data store
  10190. * @param {int} col The column index for aoColumns
  10191. *
  10192. * @name DataTable.defaults.column.createdCell
  10193. * @dtopt Columns
  10194. *
  10195. * @example
  10196. * $(document).ready( function() {
  10197. * $('#example').dataTable( {
  10198. * "columnDefs": [ {
  10199. * "targets": [3],
  10200. * "createdCell": function (td, cellData, rowData, row, col) {
  10201. * if ( cellData == "1.7" ) {
  10202. * $(td).css('color', 'blue')
  10203. * }
  10204. * }
  10205. * } ]
  10206. * });
  10207. * } );
  10208. */
  10209. "fnCreatedCell": null,
  10210. /**
  10211. * This parameter has been replaced by `data` in DataTables to ensure naming
  10212. * consistency. `dataProp` can still be used, as there is backwards
  10213. * compatibility in DataTables for this option, but it is strongly
  10214. * recommended that you use `data` in preference to `dataProp`.
  10215. * @name DataTable.defaults.column.dataProp
  10216. */
  10217. /**
  10218. * This property can be used to read data from any data source property,
  10219. * including deeply nested objects / properties. `data` can be given in a
  10220. * number of different ways which effect its behaviour:
  10221. *
  10222. * * `integer` - treated as an array index for the data source. This is the
  10223. * default that DataTables uses (incrementally increased for each column).
  10224. * * `string` - read an object property from the data source. There are
  10225. * three 'special' options that can be used in the string to alter how
  10226. * DataTables reads the data from the source object:
  10227. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10228. * Javascript to read from nested objects, so to can the options
  10229. * specified in `data`. For example: `browser.version` or
  10230. * `browser.name`. If your object parameter name contains a period, use
  10231. * `\\` to escape it - i.e. `first\\.name`.
  10232. * * `[]` - Array notation. DataTables can automatically combine data
  10233. * from and array source, joining the data with the characters provided
  10234. * between the two brackets. For example: `name[, ]` would provide a
  10235. * comma-space separated list from the source array. If no characters
  10236. * are provided between the brackets, the original array source is
  10237. * returned.
  10238. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10239. * execute a function of the name given. For example: `browser()` for a
  10240. * simple function on the data source, `browser.version()` for a
  10241. * function in a nested property or even `browser().version` to get an
  10242. * object property if the function called returns an object. Note that
  10243. * function notation is recommended for use in `render` rather than
  10244. * `data` as it is much simpler to use as a renderer.
  10245. * * `null` - use the original data source for the row rather than plucking
  10246. * data directly from it. This action has effects on two other
  10247. * initialisation options:
  10248. * * `defaultContent` - When null is given as the `data` option and
  10249. * `defaultContent` is specified for the column, the value defined by
  10250. * `defaultContent` will be used for the cell.
  10251. * * `render` - When null is used for the `data` option and the `render`
  10252. * option is specified for the column, the whole data source for the
  10253. * row is used for the renderer.
  10254. * * `function` - the function given will be executed whenever DataTables
  10255. * needs to set or get the data for a cell in the column. The function
  10256. * takes three parameters:
  10257. * * Parameters:
  10258. * * `{array|object}` The data source for the row
  10259. * * `{string}` The type call data requested - this will be 'set' when
  10260. * setting data or 'filter', 'display', 'type', 'sort' or undefined
  10261. * when gathering data. Note that when `undefined` is given for the
  10262. * type DataTables expects to get the raw data for the object back<
  10263. * * `{*}` Data to set when the second parameter is 'set'.
  10264. * * Return:
  10265. * * The return value from the function is not required when 'set' is
  10266. * the type of call, but otherwise the return is what will be used
  10267. * for the data requested.
  10268. *
  10269. * Note that `data` is a getter and setter option. If you just require
  10270. * formatting of data for output, you will likely want to use `render` which
  10271. * is simply a getter and thus simpler to use.
  10272. *
  10273. * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
  10274. * name change reflects the flexibility of this property and is consistent
  10275. * with the naming of mRender. If 'mDataProp' is given, then it will still
  10276. * be used by DataTables, as it automatically maps the old name to the new
  10277. * if required.
  10278. *
  10279. * @type string|int|function|null
  10280. * @default null <i>Use automatically calculated column index</i>
  10281. *
  10282. * @name DataTable.defaults.column.data
  10283. * @dtopt Columns
  10284. *
  10285. * @example
  10286. * // Read table data from objects
  10287. * // JSON structure for each row:
  10288. * // {
  10289. * // "engine": {value},
  10290. * // "browser": {value},
  10291. * // "platform": {value},
  10292. * // "version": {value},
  10293. * // "grade": {value}
  10294. * // }
  10295. * $(document).ready( function() {
  10296. * $('#example').dataTable( {
  10297. * "ajaxSource": "sources/objects.txt",
  10298. * "columns": [
  10299. * { "data": "engine" },
  10300. * { "data": "browser" },
  10301. * { "data": "platform" },
  10302. * { "data": "version" },
  10303. * { "data": "grade" }
  10304. * ]
  10305. * } );
  10306. * } );
  10307. *
  10308. * @example
  10309. * // Read information from deeply nested objects
  10310. * // JSON structure for each row:
  10311. * // {
  10312. * // "engine": {value},
  10313. * // "browser": {value},
  10314. * // "platform": {
  10315. * // "inner": {value}
  10316. * // },
  10317. * // "details": [
  10318. * // {value}, {value}
  10319. * // ]
  10320. * // }
  10321. * $(document).ready( function() {
  10322. * $('#example').dataTable( {
  10323. * "ajaxSource": "sources/deep.txt",
  10324. * "columns": [
  10325. * { "data": "engine" },
  10326. * { "data": "browser" },
  10327. * { "data": "platform.inner" },
  10328. * { "data": "details.0" },
  10329. * { "data": "details.1" }
  10330. * ]
  10331. * } );
  10332. * } );
  10333. *
  10334. * @example
  10335. * // Using `data` as a function to provide different information for
  10336. * // sorting, filtering and display. In this case, currency (price)
  10337. * $(document).ready( function() {
  10338. * $('#example').dataTable( {
  10339. * "columnDefs": [ {
  10340. * "targets": [ 0 ],
  10341. * "data": function ( source, type, val ) {
  10342. * if (type === 'set') {
  10343. * source.price = val;
  10344. * // Store the computed dislay and filter values for efficiency
  10345. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  10346. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  10347. * return;
  10348. * }
  10349. * else if (type === 'display') {
  10350. * return source.price_display;
  10351. * }
  10352. * else if (type === 'filter') {
  10353. * return source.price_filter;
  10354. * }
  10355. * // 'sort', 'type' and undefined all just use the integer
  10356. * return source.price;
  10357. * }
  10358. * } ]
  10359. * } );
  10360. * } );
  10361. *
  10362. * @example
  10363. * // Using default content
  10364. * $(document).ready( function() {
  10365. * $('#example').dataTable( {
  10366. * "columnDefs": [ {
  10367. * "targets": [ 0 ],
  10368. * "data": null,
  10369. * "defaultContent": "Click to edit"
  10370. * } ]
  10371. * } );
  10372. * } );
  10373. *
  10374. * @example
  10375. * // Using array notation - outputting a list from an array
  10376. * $(document).ready( function() {
  10377. * $('#example').dataTable( {
  10378. * "columnDefs": [ {
  10379. * "targets": [ 0 ],
  10380. * "data": "name[, ]"
  10381. * } ]
  10382. * } );
  10383. * } );
  10384. *
  10385. */
  10386. "mData": null,
  10387. /**
  10388. * This property is the rendering partner to `data` and it is suggested that
  10389. * when you want to manipulate data for display (including filtering,
  10390. * sorting etc) without altering the underlying data for the table, use this
  10391. * property. `render` can be considered to be the the read only companion to
  10392. * `data` which is read / write (then as such more complex). Like `data`
  10393. * this option can be given in a number of different ways to effect its
  10394. * behaviour:
  10395. *
  10396. * * `integer` - treated as an array index for the data source. This is the
  10397. * default that DataTables uses (incrementally increased for each column).
  10398. * * `string` - read an object property from the data source. There are
  10399. * three 'special' options that can be used in the string to alter how
  10400. * DataTables reads the data from the source object:
  10401. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  10402. * Javascript to read from nested objects, so to can the options
  10403. * specified in `data`. For example: `browser.version` or
  10404. * `browser.name`. If your object parameter name contains a period, use
  10405. * `\\` to escape it - i.e. `first\\.name`.
  10406. * * `[]` - Array notation. DataTables can automatically combine data
  10407. * from and array source, joining the data with the characters provided
  10408. * between the two brackets. For example: `name[, ]` would provide a
  10409. * comma-space separated list from the source array. If no characters
  10410. * are provided between the brackets, the original array source is
  10411. * returned.
  10412. * * `()` - Function notation. Adding `()` to the end of a parameter will
  10413. * execute a function of the name given. For example: `browser()` for a
  10414. * simple function on the data source, `browser.version()` for a
  10415. * function in a nested property or even `browser().version` to get an
  10416. * object property if the function called returns an object.
  10417. * * `object` - use different data for the different data types requested by
  10418. * DataTables ('filter', 'display', 'type' or 'sort'). The property names
  10419. * of the object is the data type the property refers to and the value can
  10420. * defined using an integer, string or function using the same rules as
  10421. * `render` normally does. Note that an `_` option _must_ be specified.
  10422. * This is the default value to use if you haven't specified a value for
  10423. * the data type requested by DataTables.
  10424. * * `function` - the function given will be executed whenever DataTables
  10425. * needs to set or get the data for a cell in the column. The function
  10426. * takes three parameters:
  10427. * * Parameters:
  10428. * * {array|object} The data source for the row (based on `data`)
  10429. * * {string} The type call data requested - this will be 'filter',
  10430. * 'display', 'type' or 'sort'.
  10431. * * {array|object} The full data source for the row (not based on
  10432. * `data`)
  10433. * * Return:
  10434. * * The return value from the function is what will be used for the
  10435. * data requested.
  10436. *
  10437. * @type string|int|function|object|null
  10438. * @default null Use the data source value.
  10439. *
  10440. * @name DataTable.defaults.column.render
  10441. * @dtopt Columns
  10442. *
  10443. * @example
  10444. * // Create a comma separated list from an array of objects
  10445. * $(document).ready( function() {
  10446. * $('#example').dataTable( {
  10447. * "ajaxSource": "sources/deep.txt",
  10448. * "columns": [
  10449. * { "data": "engine" },
  10450. * { "data": "browser" },
  10451. * {
  10452. * "data": "platform",
  10453. * "render": "[, ].name"
  10454. * }
  10455. * ]
  10456. * } );
  10457. * } );
  10458. *
  10459. * @example
  10460. * // Execute a function to obtain data
  10461. * $(document).ready( function() {
  10462. * $('#example').dataTable( {
  10463. * "columnDefs": [ {
  10464. * "targets": [ 0 ],
  10465. * "data": null, // Use the full data source object for the renderer's source
  10466. * "render": "browserName()"
  10467. * } ]
  10468. * } );
  10469. * } );
  10470. *
  10471. * @example
  10472. * // As an object, extracting different data for the different types
  10473. * // This would be used with a data source such as:
  10474. * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
  10475. * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
  10476. * // (which has both forms) is used for filtering for if a user inputs either format, while
  10477. * // the formatted phone number is the one that is shown in the table.
  10478. * $(document).ready( function() {
  10479. * $('#example').dataTable( {
  10480. * "columnDefs": [ {
  10481. * "targets": [ 0 ],
  10482. * "data": null, // Use the full data source object for the renderer's source
  10483. * "render": {
  10484. * "_": "phone",
  10485. * "filter": "phone_filter",
  10486. * "display": "phone_display"
  10487. * }
  10488. * } ]
  10489. * } );
  10490. * } );
  10491. *
  10492. * @example
  10493. * // Use as a function to create a link from the data source
  10494. * $(document).ready( function() {
  10495. * $('#example').dataTable( {
  10496. * "columnDefs": [ {
  10497. * "targets": [ 0 ],
  10498. * "data": "download_link",
  10499. * "render": function ( data, type, full ) {
  10500. * return '<a href="'+data+'">Download</a>';
  10501. * }
  10502. * } ]
  10503. * } );
  10504. * } );
  10505. */
  10506. "mRender": null,
  10507. /**
  10508. * Change the cell type created for the column - either TD cells or TH cells. This
  10509. * can be useful as TH cells have semantic meaning in the table body, allowing them
  10510. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  10511. * @type string
  10512. * @default td
  10513. *
  10514. * @name DataTable.defaults.column.cellType
  10515. * @dtopt Columns
  10516. *
  10517. * @example
  10518. * // Make the first column use TH cells
  10519. * $(document).ready( function() {
  10520. * $('#example').dataTable( {
  10521. * "columnDefs": [ {
  10522. * "targets": [ 0 ],
  10523. * "cellType": "th"
  10524. * } ]
  10525. * } );
  10526. * } );
  10527. */
  10528. "sCellType": "td",
  10529. /**
  10530. * Class to give to each cell in this column.
  10531. * @type string
  10532. * @default <i>Empty string</i>
  10533. *
  10534. * @name DataTable.defaults.column.class
  10535. * @dtopt Columns
  10536. *
  10537. * @example
  10538. * // Using `columnDefs`
  10539. * $(document).ready( function() {
  10540. * $('#example').dataTable( {
  10541. * "columnDefs": [
  10542. * { "class": "my_class", "targets": [ 0 ] }
  10543. * ]
  10544. * } );
  10545. * } );
  10546. *
  10547. * @example
  10548. * // Using `columns`
  10549. * $(document).ready( function() {
  10550. * $('#example').dataTable( {
  10551. * "columns": [
  10552. * { "class": "my_class" },
  10553. * null,
  10554. * null,
  10555. * null,
  10556. * null
  10557. * ]
  10558. * } );
  10559. * } );
  10560. */
  10561. "sClass": "",
  10562. /**
  10563. * When DataTables calculates the column widths to assign to each column,
  10564. * it finds the longest string in each column and then constructs a
  10565. * temporary table and reads the widths from that. The problem with this
  10566. * is that "mmm" is much wider then "iiii", but the latter is a longer
  10567. * string - thus the calculation can go wrong (doing it properly and putting
  10568. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  10569. * a "work around" we provide this option. It will append its value to the
  10570. * text that is found to be the longest string for the column - i.e. padding.
  10571. * Generally you shouldn't need this!
  10572. * @type string
  10573. * @default <i>Empty string<i>
  10574. *
  10575. * @name DataTable.defaults.column.contentPadding
  10576. * @dtopt Columns
  10577. *
  10578. * @example
  10579. * // Using `columns`
  10580. * $(document).ready( function() {
  10581. * $('#example').dataTable( {
  10582. * "columns": [
  10583. * null,
  10584. * null,
  10585. * null,
  10586. * {
  10587. * "contentPadding": "mmm"
  10588. * }
  10589. * ]
  10590. * } );
  10591. * } );
  10592. */
  10593. "sContentPadding": "",
  10594. /**
  10595. * Allows a default value to be given for a column's data, and will be used
  10596. * whenever a null data source is encountered (this can be because `data`
  10597. * is set to null, or because the data source itself is null).
  10598. * @type string
  10599. * @default null
  10600. *
  10601. * @name DataTable.defaults.column.defaultContent
  10602. * @dtopt Columns
  10603. *
  10604. * @example
  10605. * // Using `columnDefs`
  10606. * $(document).ready( function() {
  10607. * $('#example').dataTable( {
  10608. * "columnDefs": [
  10609. * {
  10610. * "data": null,
  10611. * "defaultContent": "Edit",
  10612. * "targets": [ -1 ]
  10613. * }
  10614. * ]
  10615. * } );
  10616. * } );
  10617. *
  10618. * @example
  10619. * // Using `columns`
  10620. * $(document).ready( function() {
  10621. * $('#example').dataTable( {
  10622. * "columns": [
  10623. * null,
  10624. * null,
  10625. * null,
  10626. * {
  10627. * "data": null,
  10628. * "defaultContent": "Edit"
  10629. * }
  10630. * ]
  10631. * } );
  10632. * } );
  10633. */
  10634. "sDefaultContent": null,
  10635. /**
  10636. * This parameter is only used in DataTables' server-side processing. It can
  10637. * be exceptionally useful to know what columns are being displayed on the
  10638. * client side, and to map these to database fields. When defined, the names
  10639. * also allow DataTables to reorder information from the server if it comes
  10640. * back in an unexpected order (i.e. if you switch your columns around on the
  10641. * client-side, your server-side code does not also need updating).
  10642. * @type string
  10643. * @default <i>Empty string</i>
  10644. *
  10645. * @name DataTable.defaults.column.name
  10646. * @dtopt Columns
  10647. *
  10648. * @example
  10649. * // Using `columnDefs`
  10650. * $(document).ready( function() {
  10651. * $('#example').dataTable( {
  10652. * "columnDefs": [
  10653. * { "name": "engine", "targets": [ 0 ] },
  10654. * { "name": "browser", "targets": [ 1 ] },
  10655. * { "name": "platform", "targets": [ 2 ] },
  10656. * { "name": "version", "targets": [ 3 ] },
  10657. * { "name": "grade", "targets": [ 4 ] }
  10658. * ]
  10659. * } );
  10660. * } );
  10661. *
  10662. * @example
  10663. * // Using `columns`
  10664. * $(document).ready( function() {
  10665. * $('#example').dataTable( {
  10666. * "columns": [
  10667. * { "name": "engine" },
  10668. * { "name": "browser" },
  10669. * { "name": "platform" },
  10670. * { "name": "version" },
  10671. * { "name": "grade" }
  10672. * ]
  10673. * } );
  10674. * } );
  10675. */
  10676. "sName": "",
  10677. /**
  10678. * Defines a data source type for the ordering which can be used to read
  10679. * real-time information from the table (updating the internally cached
  10680. * version) prior to ordering. This allows ordering to occur on user
  10681. * editable elements such as form inputs.
  10682. * @type string
  10683. * @default std
  10684. *
  10685. * @name DataTable.defaults.column.orderDataType
  10686. * @dtopt Columns
  10687. *
  10688. * @example
  10689. * // Using `columnDefs`
  10690. * $(document).ready( function() {
  10691. * $('#example').dataTable( {
  10692. * "columnDefs": [
  10693. * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
  10694. * { "type": "numeric", "targets": [ 3 ] },
  10695. * { "orderDataType": "dom-select", "targets": [ 4 ] },
  10696. * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
  10697. * ]
  10698. * } );
  10699. * } );
  10700. *
  10701. * @example
  10702. * // Using `columns`
  10703. * $(document).ready( function() {
  10704. * $('#example').dataTable( {
  10705. * "columns": [
  10706. * null,
  10707. * null,
  10708. * { "orderDataType": "dom-text" },
  10709. * { "orderDataType": "dom-text", "type": "numeric" },
  10710. * { "orderDataType": "dom-select" },
  10711. * { "orderDataType": "dom-checkbox" }
  10712. * ]
  10713. * } );
  10714. * } );
  10715. */
  10716. "sSortDataType": "std",
  10717. /**
  10718. * The title of this column.
  10719. * @type string
  10720. * @default null <i>Derived from the 'TH' value for this column in the
  10721. * original HTML table.</i>
  10722. *
  10723. * @name DataTable.defaults.column.title
  10724. * @dtopt Columns
  10725. *
  10726. * @example
  10727. * // Using `columnDefs`
  10728. * $(document).ready( function() {
  10729. * $('#example').dataTable( {
  10730. * "columnDefs": [
  10731. * { "title": "My column title", "targets": [ 0 ] }
  10732. * ]
  10733. * } );
  10734. * } );
  10735. *
  10736. * @example
  10737. * // Using `columns`
  10738. * $(document).ready( function() {
  10739. * $('#example').dataTable( {
  10740. * "columns": [
  10741. * { "title": "My column title" },
  10742. * null,
  10743. * null,
  10744. * null,
  10745. * null
  10746. * ]
  10747. * } );
  10748. * } );
  10749. */
  10750. "sTitle": null,
  10751. /**
  10752. * The type allows you to specify how the data for this column will be
  10753. * ordered. Four types (string, numeric, date and html (which will strip
  10754. * HTML tags before ordering)) are currently available. Note that only date
  10755. * formats understood by Javascript's Date() object will be accepted as type
  10756. * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
  10757. * 'numeric', 'date' or 'html' (by default). Further types can be adding
  10758. * through plug-ins.
  10759. * @type string
  10760. * @default null <i>Auto-detected from raw data</i>
  10761. *
  10762. * @name DataTable.defaults.column.type
  10763. * @dtopt Columns
  10764. *
  10765. * @example
  10766. * // Using `columnDefs`
  10767. * $(document).ready( function() {
  10768. * $('#example').dataTable( {
  10769. * "columnDefs": [
  10770. * { "type": "html", "targets": [ 0 ] }
  10771. * ]
  10772. * } );
  10773. * } );
  10774. *
  10775. * @example
  10776. * // Using `columns`
  10777. * $(document).ready( function() {
  10778. * $('#example').dataTable( {
  10779. * "columns": [
  10780. * { "type": "html" },
  10781. * null,
  10782. * null,
  10783. * null,
  10784. * null
  10785. * ]
  10786. * } );
  10787. * } );
  10788. */
  10789. "sType": null,
  10790. /**
  10791. * Defining the width of the column, this parameter may take any CSS value
  10792. * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
  10793. * been given a specific width through this interface ensuring that the table
  10794. * remains readable.
  10795. * @type string
  10796. * @default null <i>Automatic</i>
  10797. *
  10798. * @name DataTable.defaults.column.width
  10799. * @dtopt Columns
  10800. *
  10801. * @example
  10802. * // Using `columnDefs`
  10803. * $(document).ready( function() {
  10804. * $('#example').dataTable( {
  10805. * "columnDefs": [
  10806. * { "width": "20%", "targets": [ 0 ] }
  10807. * ]
  10808. * } );
  10809. * } );
  10810. *
  10811. * @example
  10812. * // Using `columns`
  10813. * $(document).ready( function() {
  10814. * $('#example').dataTable( {
  10815. * "columns": [
  10816. * { "width": "20%" },
  10817. * null,
  10818. * null,
  10819. * null,
  10820. * null
  10821. * ]
  10822. * } );
  10823. * } );
  10824. */
  10825. "sWidth": null
  10826. };
  10827. _fnHungarianMap(DataTable.defaults.column);
  10828. /**
  10829. * DataTables settings object - this holds all the information needed for a
  10830. * given table, including configuration, data and current application of the
  10831. * table options. DataTables does not have a single instance for each DataTable
  10832. * with the settings attached to that instance, but rather instances of the
  10833. * DataTable "class" are created on-the-fly as needed (typically by a
  10834. * $().dataTable() call) and the settings object is then applied to that
  10835. * instance.
  10836. *
  10837. * Note that this object is related to {@link DataTable.defaults} but this
  10838. * one is the internal data store for DataTables's cache of columns. It should
  10839. * NOT be manipulated outside of DataTables. Any configuration should be done
  10840. * through the initialisation options.
  10841. * @namespace
  10842. * @todo Really should attach the settings object to individual instances so we
  10843. * don't need to create new instances on each $().dataTable() call (if the
  10844. * table already exists). It would also save passing oSettings around and
  10845. * into every single function. However, this is a very significant
  10846. * architecture change for DataTables and will almost certainly break
  10847. * backwards compatibility with older installations. This is something that
  10848. * will be done in 2.0.
  10849. */
  10850. DataTable.models.oSettings = {
  10851. /**
  10852. * Primary features of DataTables and their enablement state.
  10853. * @namespace
  10854. */
  10855. "oFeatures": {
  10856. /**
  10857. * Flag to say if DataTables should automatically try to calculate the
  10858. * optimum table and columns widths (true) or not (false).
  10859. * Note that this parameter will be set by the initialisation routine. To
  10860. * set a default use {@link DataTable.defaults}.
  10861. * @type boolean
  10862. */
  10863. "bAutoWidth": null,
  10864. /**
  10865. * Delay the creation of TR and TD elements until they are actually
  10866. * needed by a driven page draw. This can give a significant speed
  10867. * increase for Ajax source and Javascript source data, but makes no
  10868. * difference at all fro DOM and server-side processing tables.
  10869. * Note that this parameter will be set by the initialisation routine. To
  10870. * set a default use {@link DataTable.defaults}.
  10871. * @type boolean
  10872. */
  10873. "bDeferRender": null,
  10874. /**
  10875. * Enable filtering on the table or not. Note that if this is disabled
  10876. * then there is no filtering at all on the table, including fnFilter.
  10877. * To just remove the filtering input use sDom and remove the 'f' option.
  10878. * Note that this parameter will be set by the initialisation routine. To
  10879. * set a default use {@link DataTable.defaults}.
  10880. * @type boolean
  10881. */
  10882. "bFilter": null,
  10883. /**
  10884. * Table information element (the 'Showing x of y records' div) enable
  10885. * flag.
  10886. * Note that this parameter will be set by the initialisation routine. To
  10887. * set a default use {@link DataTable.defaults}.
  10888. * @type boolean
  10889. */
  10890. "bInfo": null,
  10891. /**
  10892. * Present a user control allowing the end user to change the page size
  10893. * when pagination is enabled.
  10894. * Note that this parameter will be set by the initialisation routine. To
  10895. * set a default use {@link DataTable.defaults}.
  10896. * @type boolean
  10897. */
  10898. "bLengthChange": null,
  10899. /**
  10900. * Pagination enabled or not. Note that if this is disabled then length
  10901. * changing must also be disabled.
  10902. * Note that this parameter will be set by the initialisation routine. To
  10903. * set a default use {@link DataTable.defaults}.
  10904. * @type boolean
  10905. */
  10906. "bPaginate": null,
  10907. /**
  10908. * Processing indicator enable flag whenever DataTables is enacting a
  10909. * user request - typically an Ajax request for server-side processing.
  10910. * Note that this parameter will be set by the initialisation routine. To
  10911. * set a default use {@link DataTable.defaults}.
  10912. * @type boolean
  10913. */
  10914. "bProcessing": null,
  10915. /**
  10916. * Server-side processing enabled flag - when enabled DataTables will
  10917. * get all data from the server for every draw - there is no filtering,
  10918. * sorting or paging done on the client-side.
  10919. * Note that this parameter will be set by the initialisation routine. To
  10920. * set a default use {@link DataTable.defaults}.
  10921. * @type boolean
  10922. */
  10923. "bServerSide": null,
  10924. /**
  10925. * Sorting enablement flag.
  10926. * Note that this parameter will be set by the initialisation routine. To
  10927. * set a default use {@link DataTable.defaults}.
  10928. * @type boolean
  10929. */
  10930. "bSort": null,
  10931. /**
  10932. * Multi-column sorting
  10933. * Note that this parameter will be set by the initialisation routine. To
  10934. * set a default use {@link DataTable.defaults}.
  10935. * @type boolean
  10936. */
  10937. "bSortMulti": null,
  10938. /**
  10939. * Apply a class to the columns which are being sorted to provide a
  10940. * visual highlight or not. This can slow things down when enabled since
  10941. * there is a lot of DOM interaction.
  10942. * Note that this parameter will be set by the initialisation routine. To
  10943. * set a default use {@link DataTable.defaults}.
  10944. * @type boolean
  10945. */
  10946. "bSortClasses": null,
  10947. /**
  10948. * State saving enablement flag.
  10949. * Note that this parameter will be set by the initialisation routine. To
  10950. * set a default use {@link DataTable.defaults}.
  10951. * @type boolean
  10952. */
  10953. "bStateSave": null
  10954. },
  10955. /**
  10956. * Scrolling settings for a table.
  10957. * @namespace
  10958. */
  10959. "oScroll": {
  10960. /**
  10961. * When the table is shorter in height than sScrollY, collapse the
  10962. * table container down to the height of the table (when true).
  10963. * Note that this parameter will be set by the initialisation routine. To
  10964. * set a default use {@link DataTable.defaults}.
  10965. * @type boolean
  10966. */
  10967. "bCollapse": null,
  10968. /**
  10969. * Width of the scrollbar for the web-browser's platform. Calculated
  10970. * during table initialisation.
  10971. * @type int
  10972. * @default 0
  10973. */
  10974. "iBarWidth": 0,
  10975. /**
  10976. * Viewport width for horizontal scrolling. Horizontal scrolling is
  10977. * disabled if an empty string.
  10978. * Note that this parameter will be set by the initialisation routine. To
  10979. * set a default use {@link DataTable.defaults}.
  10980. * @type string
  10981. */
  10982. "sX": null,
  10983. /**
  10984. * Width to expand the table to when using x-scrolling. Typically you
  10985. * should not need to use this.
  10986. * Note that this parameter will be set by the initialisation routine. To
  10987. * set a default use {@link DataTable.defaults}.
  10988. * @type string
  10989. * @deprecated
  10990. */
  10991. "sXInner": null,
  10992. /**
  10993. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  10994. * if an empty string.
  10995. * Note that this parameter will be set by the initialisation routine. To
  10996. * set a default use {@link DataTable.defaults}.
  10997. * @type string
  10998. */
  10999. "sY": null
  11000. },
  11001. /**
  11002. * Language information for the table.
  11003. * @namespace
  11004. * @extends DataTable.defaults.oLanguage
  11005. */
  11006. "oLanguage": {
  11007. /**
  11008. * Information callback function. See
  11009. * {@link DataTable.defaults.fnInfoCallback}
  11010. * @type function
  11011. * @default null
  11012. */
  11013. "fnInfoCallback": null
  11014. },
  11015. /**
  11016. * Browser support parameters
  11017. * @namespace
  11018. */
  11019. "oBrowser": {
  11020. /**
  11021. * Indicate if the browser incorrectly calculates width:100% inside a
  11022. * scrolling element (IE6/7)
  11023. * @type boolean
  11024. * @default false
  11025. */
  11026. "bScrollOversize": false,
  11027. /**
  11028. * Determine if the vertical scrollbar is on the right or left of the
  11029. * scrolling container - needed for rtl language layout, although not
  11030. * all browsers move the scrollbar (Safari).
  11031. * @type boolean
  11032. * @default false
  11033. */
  11034. "bScrollbarLeft": false,
  11035. /**
  11036. * Flag for if `getBoundingClientRect` is fully supported or not
  11037. * @type boolean
  11038. * @default false
  11039. */
  11040. "bBounding": false,
  11041. /**
  11042. * Browser scrollbar width
  11043. * @type integer
  11044. * @default 0
  11045. */
  11046. "barWidth": 0
  11047. },
  11048. "ajax": null,
  11049. /**
  11050. * Array referencing the nodes which are used for the features. The
  11051. * parameters of this object match what is allowed by sDom - i.e.
  11052. * <ul>
  11053. * <li>'l' - Length changing</li>
  11054. * <li>'f' - Filtering input</li>
  11055. * <li>'t' - The table!</li>
  11056. * <li>'i' - Information</li>
  11057. * <li>'p' - Pagination</li>
  11058. * <li>'r' - pRocessing</li>
  11059. * </ul>
  11060. * @type array
  11061. * @default []
  11062. */
  11063. "aanFeatures": [],
  11064. /**
  11065. * Store data information - see {@link DataTable.models.oRow} for detailed
  11066. * information.
  11067. * @type array
  11068. * @default []
  11069. */
  11070. "aoData": [],
  11071. /**
  11072. * Array of indexes which are in the current display (after filtering etc)
  11073. * @type array
  11074. * @default []
  11075. */
  11076. "aiDisplay": [],
  11077. /**
  11078. * Array of indexes for display - no filtering
  11079. * @type array
  11080. * @default []
  11081. */
  11082. "aiDisplayMaster": [],
  11083. /**
  11084. * Map of row ids to data indexes
  11085. * @type object
  11086. * @default {}
  11087. */
  11088. "aIds": {},
  11089. /**
  11090. * Store information about each column that is in use
  11091. * @type array
  11092. * @default []
  11093. */
  11094. "aoColumns": [],
  11095. /**
  11096. * Store information about the table's header
  11097. * @type array
  11098. * @default []
  11099. */
  11100. "aoHeader": [],
  11101. /**
  11102. * Store information about the table's footer
  11103. * @type array
  11104. * @default []
  11105. */
  11106. "aoFooter": [],
  11107. /**
  11108. * Store the applied global search information in case we want to force a
  11109. * research or compare the old search to a new one.
  11110. * Note that this parameter will be set by the initialisation routine. To
  11111. * set a default use {@link DataTable.defaults}.
  11112. * @namespace
  11113. * @extends DataTable.models.oSearch
  11114. */
  11115. "oPreviousSearch": {},
  11116. /**
  11117. * Store the applied search for each column - see
  11118. * {@link DataTable.models.oSearch} for the format that is used for the
  11119. * filtering information for each column.
  11120. * @type array
  11121. * @default []
  11122. */
  11123. "aoPreSearchCols": [],
  11124. /**
  11125. * Sorting that is applied to the table. Note that the inner arrays are
  11126. * used in the following manner:
  11127. * <ul>
  11128. * <li>Index 0 - column number</li>
  11129. * <li>Index 1 - current sorting direction</li>
  11130. * </ul>
  11131. * Note that this parameter will be set by the initialisation routine. To
  11132. * set a default use {@link DataTable.defaults}.
  11133. * @type array
  11134. * @todo These inner arrays should really be objects
  11135. */
  11136. "aaSorting": null,
  11137. /**
  11138. * Sorting that is always applied to the table (i.e. prefixed in front of
  11139. * aaSorting).
  11140. * Note that this parameter will be set by the initialisation routine. To
  11141. * set a default use {@link DataTable.defaults}.
  11142. * @type array
  11143. * @default []
  11144. */
  11145. "aaSortingFixed": [],
  11146. /**
  11147. * Classes to use for the striping of a table.
  11148. * Note that this parameter will be set by the initialisation routine. To
  11149. * set a default use {@link DataTable.defaults}.
  11150. * @type array
  11151. * @default []
  11152. */
  11153. "asStripeClasses": null,
  11154. /**
  11155. * If restoring a table - we should restore its striping classes as well
  11156. * @type array
  11157. * @default []
  11158. */
  11159. "asDestroyStripes": [],
  11160. /**
  11161. * If restoring a table - we should restore its width
  11162. * @type int
  11163. * @default 0
  11164. */
  11165. "sDestroyWidth": 0,
  11166. /**
  11167. * Callback functions array for every time a row is inserted (i.e. on a draw).
  11168. * @type array
  11169. * @default []
  11170. */
  11171. "aoRowCallback": [],
  11172. /**
  11173. * Callback functions for the header on each draw.
  11174. * @type array
  11175. * @default []
  11176. */
  11177. "aoHeaderCallback": [],
  11178. /**
  11179. * Callback function for the footer on each draw.
  11180. * @type array
  11181. * @default []
  11182. */
  11183. "aoFooterCallback": [],
  11184. /**
  11185. * Array of callback functions for draw callback functions
  11186. * @type array
  11187. * @default []
  11188. */
  11189. "aoDrawCallback": [],
  11190. /**
  11191. * Array of callback functions for row created function
  11192. * @type array
  11193. * @default []
  11194. */
  11195. "aoRowCreatedCallback": [],
  11196. /**
  11197. * Callback functions for just before the table is redrawn. A return of
  11198. * false will be used to cancel the draw.
  11199. * @type array
  11200. * @default []
  11201. */
  11202. "aoPreDrawCallback": [],
  11203. /**
  11204. * Callback functions for when the table has been initialised.
  11205. * @type array
  11206. * @default []
  11207. */
  11208. "aoInitComplete": [],
  11209. /**
  11210. * Callbacks for modifying the settings to be stored for state saving, prior to
  11211. * saving state.
  11212. * @type array
  11213. * @default []
  11214. */
  11215. "aoStateSaveParams": [],
  11216. /**
  11217. * Callbacks for modifying the settings that have been stored for state saving
  11218. * prior to using the stored values to restore the state.
  11219. * @type array
  11220. * @default []
  11221. */
  11222. "aoStateLoadParams": [],
  11223. /**
  11224. * Callbacks for operating on the settings object once the saved state has been
  11225. * loaded
  11226. * @type array
  11227. * @default []
  11228. */
  11229. "aoStateLoaded": [],
  11230. /**
  11231. * Cache the table ID for quick access
  11232. * @type string
  11233. * @default <i>Empty string</i>
  11234. */
  11235. "sTableId": "",
  11236. /**
  11237. * The TABLE node for the main table
  11238. * @type node
  11239. * @default null
  11240. */
  11241. "nTable": null,
  11242. /**
  11243. * Permanent ref to the thead element
  11244. * @type node
  11245. * @default null
  11246. */
  11247. "nTHead": null,
  11248. /**
  11249. * Permanent ref to the tfoot element - if it exists
  11250. * @type node
  11251. * @default null
  11252. */
  11253. "nTFoot": null,
  11254. /**
  11255. * Permanent ref to the tbody element
  11256. * @type node
  11257. * @default null
  11258. */
  11259. "nTBody": null,
  11260. /**
  11261. * Cache the wrapper node (contains all DataTables controlled elements)
  11262. * @type node
  11263. * @default null
  11264. */
  11265. "nTableWrapper": null,
  11266. /**
  11267. * Indicate if when using server-side processing the loading of data
  11268. * should be deferred until the second draw.
  11269. * Note that this parameter will be set by the initialisation routine. To
  11270. * set a default use {@link DataTable.defaults}.
  11271. * @type boolean
  11272. * @default false
  11273. */
  11274. "bDeferLoading": false,
  11275. /**
  11276. * Indicate if all required information has been read in
  11277. * @type boolean
  11278. * @default false
  11279. */
  11280. "bInitialised": false,
  11281. /**
  11282. * Information about open rows. Each object in the array has the parameters
  11283. * 'nTr' and 'nParent'
  11284. * @type array
  11285. * @default []
  11286. */
  11287. "aoOpenRows": [],
  11288. /**
  11289. * Dictate the positioning of DataTables' control elements - see
  11290. * {@link DataTable.model.oInit.sDom}.
  11291. * Note that this parameter will be set by the initialisation routine. To
  11292. * set a default use {@link DataTable.defaults}.
  11293. * @type string
  11294. * @default null
  11295. */
  11296. "sDom": null,
  11297. /**
  11298. * Search delay (in mS)
  11299. * @type integer
  11300. * @default null
  11301. */
  11302. "searchDelay": null,
  11303. /**
  11304. * Which type of pagination should be used.
  11305. * Note that this parameter will be set by the initialisation routine. To
  11306. * set a default use {@link DataTable.defaults}.
  11307. * @type string
  11308. * @default two_button
  11309. */
  11310. "sPaginationType": "two_button",
  11311. /**
  11312. * The state duration (for `stateSave`) in seconds.
  11313. * Note that this parameter will be set by the initialisation routine. To
  11314. * set a default use {@link DataTable.defaults}.
  11315. * @type int
  11316. * @default 0
  11317. */
  11318. "iStateDuration": 0,
  11319. /**
  11320. * Array of callback functions for state saving. Each array element is an
  11321. * object with the following parameters:
  11322. * <ul>
  11323. * <li>function:fn - function to call. Takes two parameters, oSettings
  11324. * and the JSON string to save that has been thus far created. Returns
  11325. * a JSON string to be inserted into a json object
  11326. * (i.e. '"param": [ 0, 1, 2]')</li>
  11327. * <li>string:sName - name of callback</li>
  11328. * </ul>
  11329. * @type array
  11330. * @default []
  11331. */
  11332. "aoStateSave": [],
  11333. /**
  11334. * Array of callback functions for state loading. Each array element is an
  11335. * object with the following parameters:
  11336. * <ul>
  11337. * <li>function:fn - function to call. Takes two parameters, oSettings
  11338. * and the object stored. May return false to cancel state loading</li>
  11339. * <li>string:sName - name of callback</li>
  11340. * </ul>
  11341. * @type array
  11342. * @default []
  11343. */
  11344. "aoStateLoad": [],
  11345. /**
  11346. * State that was saved. Useful for back reference
  11347. * @type object
  11348. * @default null
  11349. */
  11350. "oSavedState": null,
  11351. /**
  11352. * State that was loaded. Useful for back reference
  11353. * @type object
  11354. * @default null
  11355. */
  11356. "oLoadedState": null,
  11357. /**
  11358. * Source url for AJAX data for the table.
  11359. * Note that this parameter will be set by the initialisation routine. To
  11360. * set a default use {@link DataTable.defaults}.
  11361. * @type string
  11362. * @default null
  11363. */
  11364. "sAjaxSource": null,
  11365. /**
  11366. * Property from a given object from which to read the table data from. This
  11367. * can be an empty string (when not server-side processing), in which case
  11368. * it is assumed an an array is given directly.
  11369. * Note that this parameter will be set by the initialisation routine. To
  11370. * set a default use {@link DataTable.defaults}.
  11371. * @type string
  11372. */
  11373. "sAjaxDataProp": null,
  11374. /**
  11375. * Note if draw should be blocked while getting data
  11376. * @type boolean
  11377. * @default true
  11378. */
  11379. "bAjaxDataGet": true,
  11380. /**
  11381. * The last jQuery XHR object that was used for server-side data gathering.
  11382. * This can be used for working with the XHR information in one of the
  11383. * callbacks
  11384. * @type object
  11385. * @default null
  11386. */
  11387. "jqXHR": null,
  11388. /**
  11389. * JSON returned from the server in the last Ajax request
  11390. * @type object
  11391. * @default undefined
  11392. */
  11393. "json": undefined,
  11394. /**
  11395. * Data submitted as part of the last Ajax request
  11396. * @type object
  11397. * @default undefined
  11398. */
  11399. "oAjaxData": undefined,
  11400. /**
  11401. * Function to get the server-side data.
  11402. * Note that this parameter will be set by the initialisation routine. To
  11403. * set a default use {@link DataTable.defaults}.
  11404. * @type function
  11405. */
  11406. "fnServerData": null,
  11407. /**
  11408. * Functions which are called prior to sending an Ajax request so extra
  11409. * parameters can easily be sent to the server
  11410. * @type array
  11411. * @default []
  11412. */
  11413. "aoServerParams": [],
  11414. /**
  11415. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  11416. * required).
  11417. * Note that this parameter will be set by the initialisation routine. To
  11418. * set a default use {@link DataTable.defaults}.
  11419. * @type string
  11420. */
  11421. "sServerMethod": null,
  11422. /**
  11423. * Format numbers for display.
  11424. * Note that this parameter will be set by the initialisation routine. To
  11425. * set a default use {@link DataTable.defaults}.
  11426. * @type function
  11427. */
  11428. "fnFormatNumber": null,
  11429. /**
  11430. * List of options that can be used for the user selectable length menu.
  11431. * Note that this parameter will be set by the initialisation routine. To
  11432. * set a default use {@link DataTable.defaults}.
  11433. * @type array
  11434. * @default []
  11435. */
  11436. "aLengthMenu": null,
  11437. /**
  11438. * Counter for the draws that the table does. Also used as a tracker for
  11439. * server-side processing
  11440. * @type int
  11441. * @default 0
  11442. */
  11443. "iDraw": 0,
  11444. /**
  11445. * Indicate if a redraw is being done - useful for Ajax
  11446. * @type boolean
  11447. * @default false
  11448. */
  11449. "bDrawing": false,
  11450. /**
  11451. * Draw index (iDraw) of the last error when parsing the returned data
  11452. * @type int
  11453. * @default -1
  11454. */
  11455. "iDrawError": -1,
  11456. /**
  11457. * Paging display length
  11458. * @type int
  11459. * @default 10
  11460. */
  11461. "_iDisplayLength": 10,
  11462. /**
  11463. * Paging start point - aiDisplay index
  11464. * @type int
  11465. * @default 0
  11466. */
  11467. "_iDisplayStart": 0,
  11468. /**
  11469. * Server-side processing - number of records in the result set
  11470. * (i.e. before filtering), Use fnRecordsTotal rather than
  11471. * this property to get the value of the number of records, regardless of
  11472. * the server-side processing setting.
  11473. * @type int
  11474. * @default 0
  11475. * @private
  11476. */
  11477. "_iRecordsTotal": 0,
  11478. /**
  11479. * Server-side processing - number of records in the current display set
  11480. * (i.e. after filtering). Use fnRecordsDisplay rather than
  11481. * this property to get the value of the number of records, regardless of
  11482. * the server-side processing setting.
  11483. * @type boolean
  11484. * @default 0
  11485. * @private
  11486. */
  11487. "_iRecordsDisplay": 0,
  11488. /**
  11489. * The classes to use for the table
  11490. * @type object
  11491. * @default {}
  11492. */
  11493. "oClasses": {},
  11494. /**
  11495. * Flag attached to the settings object so you can check in the draw
  11496. * callback if filtering has been done in the draw. Deprecated in favour of
  11497. * events.
  11498. * @type boolean
  11499. * @default false
  11500. * @deprecated
  11501. */
  11502. "bFiltered": false,
  11503. /**
  11504. * Flag attached to the settings object so you can check in the draw
  11505. * callback if sorting has been done in the draw. Deprecated in favour of
  11506. * events.
  11507. * @type boolean
  11508. * @default false
  11509. * @deprecated
  11510. */
  11511. "bSorted": false,
  11512. /**
  11513. * Indicate that if multiple rows are in the header and there is more than
  11514. * one unique cell per column, if the top one (true) or bottom one (false)
  11515. * should be used for sorting / title by DataTables.
  11516. * Note that this parameter will be set by the initialisation routine. To
  11517. * set a default use {@link DataTable.defaults}.
  11518. * @type boolean
  11519. */
  11520. "bSortCellsTop": null,
  11521. /**
  11522. * Initialisation object that is used for the table
  11523. * @type object
  11524. * @default null
  11525. */
  11526. "oInit": null,
  11527. /**
  11528. * Destroy callback functions - for plug-ins to attach themselves to the
  11529. * destroy so they can clean up markup and events.
  11530. * @type array
  11531. * @default []
  11532. */
  11533. "aoDestroyCallback": [],
  11534. /**
  11535. * Get the number of records in the current record set, before filtering
  11536. * @type function
  11537. */
  11538. "fnRecordsTotal": function () {
  11539. return _fnDataSource(this) == 'ssp' ?
  11540. this._iRecordsTotal * 1 :
  11541. this.aiDisplayMaster.length;
  11542. },
  11543. /**
  11544. * Get the number of records in the current record set, after filtering
  11545. * @type function
  11546. */
  11547. "fnRecordsDisplay": function () {
  11548. return _fnDataSource(this) == 'ssp' ?
  11549. this._iRecordsDisplay * 1 :
  11550. this.aiDisplay.length;
  11551. },
  11552. /**
  11553. * Get the display end point - aiDisplay index
  11554. * @type function
  11555. */
  11556. "fnDisplayEnd": function () {
  11557. var
  11558. len = this._iDisplayLength,
  11559. start = this._iDisplayStart,
  11560. calc = start + len,
  11561. records = this.aiDisplay.length,
  11562. features = this.oFeatures,
  11563. paginate = features.bPaginate;
  11564. if (features.bServerSide) {
  11565. return paginate === false || len === -1 ?
  11566. start + records :
  11567. Math.min(start + len, this._iRecordsDisplay);
  11568. } else {
  11569. return !paginate || calc > records || len === -1 ?
  11570. records :
  11571. calc;
  11572. }
  11573. },
  11574. /**
  11575. * The DataTables object for this table
  11576. * @type object
  11577. * @default null
  11578. */
  11579. "oInstance": null,
  11580. /**
  11581. * Unique identifier for each instance of the DataTables object. If there
  11582. * is an ID on the table node, then it takes that value, otherwise an
  11583. * incrementing internal counter is used.
  11584. * @type string
  11585. * @default null
  11586. */
  11587. "sInstance": null,
  11588. /**
  11589. * tabindex attribute value that is added to DataTables control elements, allowing
  11590. * keyboard navigation of the table and its controls.
  11591. */
  11592. "iTabIndex": 0,
  11593. /**
  11594. * DIV container for the footer scrolling table if scrolling
  11595. */
  11596. "nScrollHead": null,
  11597. /**
  11598. * DIV container for the footer scrolling table if scrolling
  11599. */
  11600. "nScrollFoot": null,
  11601. /**
  11602. * Last applied sort
  11603. * @type array
  11604. * @default []
  11605. */
  11606. "aLastSort": [],
  11607. /**
  11608. * Stored plug-in instances
  11609. * @type object
  11610. * @default {}
  11611. */
  11612. "oPlugins": {},
  11613. /**
  11614. * Function used to get a row's id from the row's data
  11615. * @type function
  11616. * @default null
  11617. */
  11618. "rowIdFn": null,
  11619. /**
  11620. * Data location where to store a row's id
  11621. * @type string
  11622. * @default null
  11623. */
  11624. "rowId": null
  11625. };
  11626. /**
  11627. * Extension object for DataTables that is used to provide all extension
  11628. * options.
  11629. *
  11630. * Note that the `DataTable.ext` object is available through
  11631. * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
  11632. * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
  11633. * @namespace
  11634. * @extends DataTable.models.ext
  11635. */
  11636. /**
  11637. * DataTables extensions
  11638. *
  11639. * This namespace acts as a collection area for plug-ins that can be used to
  11640. * extend DataTables capabilities. Indeed many of the build in methods
  11641. * use this method to provide their own capabilities (sorting methods for
  11642. * example).
  11643. *
  11644. * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
  11645. * reasons
  11646. *
  11647. * @namespace
  11648. */
  11649. DataTable.ext = _ext = {
  11650. /**
  11651. * Buttons. For use with the Buttons extension for DataTables. This is
  11652. * defined here so other extensions can define buttons regardless of load
  11653. * order. It is _not_ used by DataTables core.
  11654. *
  11655. * @type object
  11656. * @default {}
  11657. */
  11658. buttons: {},
  11659. /**
  11660. * Element class names
  11661. *
  11662. * @type object
  11663. * @default {}
  11664. */
  11665. classes: {},
  11666. /**
  11667. * DataTables build type (expanded by the download builder)
  11668. *
  11669. * @type string
  11670. */
  11671. builder: "-source-",
  11672. /**
  11673. * Error reporting.
  11674. *
  11675. * How should DataTables report an error. Can take the value 'alert',
  11676. * 'throw', 'none' or a function.
  11677. *
  11678. * @type string|function
  11679. * @default alert
  11680. */
  11681. errMode: "alert",
  11682. /**
  11683. * Feature plug-ins.
  11684. *
  11685. * This is an array of objects which describe the feature plug-ins that are
  11686. * available to DataTables. These feature plug-ins are then available for
  11687. * use through the `dom` initialisation option.
  11688. *
  11689. * Each feature plug-in is described by an object which must have the
  11690. * following properties:
  11691. *
  11692. * * `fnInit` - function that is used to initialise the plug-in,
  11693. * * `cFeature` - a character so the feature can be enabled by the `dom`
  11694. * instillation option. This is case sensitive.
  11695. *
  11696. * The `fnInit` function has the following input parameters:
  11697. *
  11698. * 1. `{object}` DataTables settings object: see
  11699. * {@link DataTable.models.oSettings}
  11700. *
  11701. * And the following return is expected:
  11702. *
  11703. * * {node|null} The element which contains your feature. Note that the
  11704. * return may also be void if your plug-in does not require to inject any
  11705. * DOM elements into DataTables control (`dom`) - for example this might
  11706. * be useful when developing a plug-in which allows table control via
  11707. * keyboard entry
  11708. *
  11709. * @type array
  11710. *
  11711. * @example
  11712. * $.fn.dataTable.ext.features.push( {
  11713. * "fnInit": function( oSettings ) {
  11714. * return new TableTools( { "oDTSettings": oSettings } );
  11715. * },
  11716. * "cFeature": "T"
  11717. * } );
  11718. */
  11719. feature: [],
  11720. /**
  11721. * Row searching.
  11722. *
  11723. * This method of searching is complimentary to the default type based
  11724. * searching, and a lot more comprehensive as it allows you complete control
  11725. * over the searching logic. Each element in this array is a function
  11726. * (parameters described below) that is called for every row in the table,
  11727. * and your logic decides if it should be included in the searching data set
  11728. * or not.
  11729. *
  11730. * Searching functions have the following input parameters:
  11731. *
  11732. * 1. `{object}` DataTables settings object: see
  11733. * {@link DataTable.models.oSettings}
  11734. * 2. `{array|object}` Data for the row to be processed (same as the
  11735. * original format that was passed in as the data source, or an array
  11736. * from a DOM data source
  11737. * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
  11738. * can be useful to retrieve the `TR` element if you need DOM interaction.
  11739. *
  11740. * And the following return is expected:
  11741. *
  11742. * * {boolean} Include the row in the searched result set (true) or not
  11743. * (false)
  11744. *
  11745. * Note that as with the main search ability in DataTables, technically this
  11746. * is "filtering", since it is subtractive. However, for consistency in
  11747. * naming we call it searching here.
  11748. *
  11749. * @type array
  11750. * @default []
  11751. *
  11752. * @example
  11753. * // The following example shows custom search being applied to the
  11754. * // fourth column (i.e. the data[3] index) based on two input values
  11755. * // from the end-user, matching the data in a certain range.
  11756. * $.fn.dataTable.ext.search.push(
  11757. * function( settings, data, dataIndex ) {
  11758. * var min = document.getElementById('min').value * 1;
  11759. * var max = document.getElementById('max').value * 1;
  11760. * var version = data[3] == "-" ? 0 : data[3]*1;
  11761. *
  11762. * if ( min == "" && max == "" ) {
  11763. * return true;
  11764. * }
  11765. * else if ( min == "" && version < max ) {
  11766. * return true;
  11767. * }
  11768. * else if ( min < version && "" == max ) {
  11769. * return true;
  11770. * }
  11771. * else if ( min < version && version < max ) {
  11772. * return true;
  11773. * }
  11774. * return false;
  11775. * }
  11776. * );
  11777. */
  11778. search: [],
  11779. /**
  11780. * Selector extensions
  11781. *
  11782. * The `selector` option can be used to extend the options available for the
  11783. * selector modifier options (`selector-modifier` object data type) that
  11784. * each of the three built in selector types offer (row, column and cell +
  11785. * their plural counterparts). For example the Select extension uses this
  11786. * mechanism to provide an option to select only rows, columns and cells
  11787. * that have been marked as selected by the end user (`{selected: true}`),
  11788. * which can be used in conjunction with the existing built in selector
  11789. * options.
  11790. *
  11791. * Each property is an array to which functions can be pushed. The functions
  11792. * take three attributes:
  11793. *
  11794. * * Settings object for the host table
  11795. * * Options object (`selector-modifier` object type)
  11796. * * Array of selected item indexes
  11797. *
  11798. * The return is an array of the resulting item indexes after the custom
  11799. * selector has been applied.
  11800. *
  11801. * @type object
  11802. */
  11803. selector: {
  11804. cell: [],
  11805. column: [],
  11806. row: []
  11807. },
  11808. /**
  11809. * Internal functions, exposed for used in plug-ins.
  11810. *
  11811. * Please note that you should not need to use the internal methods for
  11812. * anything other than a plug-in (and even then, try to avoid if possible).
  11813. * The internal function may change between releases.
  11814. *
  11815. * @type object
  11816. * @default {}
  11817. */
  11818. internal: {},
  11819. /**
  11820. * Legacy configuration options. Enable and disable legacy options that
  11821. * are available in DataTables.
  11822. *
  11823. * @type object
  11824. */
  11825. legacy: {
  11826. /**
  11827. * Enable / disable DataTables 1.9 compatible server-side processing
  11828. * requests
  11829. *
  11830. * @type boolean
  11831. * @default null
  11832. */
  11833. ajax: null
  11834. },
  11835. /**
  11836. * Pagination plug-in methods.
  11837. *
  11838. * Each entry in this object is a function and defines which buttons should
  11839. * be shown by the pagination rendering method that is used for the table:
  11840. * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
  11841. * buttons are displayed in the document, while the functions here tell it
  11842. * what buttons to display. This is done by returning an array of button
  11843. * descriptions (what each button will do).
  11844. *
  11845. * Pagination types (the four built in options and any additional plug-in
  11846. * options defined here) can be used through the `paginationType`
  11847. * initialisation parameter.
  11848. *
  11849. * The functions defined take two parameters:
  11850. *
  11851. * 1. `{int} page` The current page index
  11852. * 2. `{int} pages` The number of pages in the table
  11853. *
  11854. * Each function is expected to return an array where each element of the
  11855. * array can be one of:
  11856. *
  11857. * * `first` - Jump to first page when activated
  11858. * * `last` - Jump to last page when activated
  11859. * * `previous` - Show previous page when activated
  11860. * * `next` - Show next page when activated
  11861. * * `{int}` - Show page of the index given
  11862. * * `{array}` - A nested array containing the above elements to add a
  11863. * containing 'DIV' element (might be useful for styling).
  11864. *
  11865. * Note that DataTables v1.9- used this object slightly differently whereby
  11866. * an object with two functions would be defined for each plug-in. That
  11867. * ability is still supported by DataTables 1.10+ to provide backwards
  11868. * compatibility, but this option of use is now decremented and no longer
  11869. * documented in DataTables 1.10+.
  11870. *
  11871. * @type object
  11872. * @default {}
  11873. *
  11874. * @example
  11875. * // Show previous, next and current page buttons only
  11876. * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
  11877. * return [ 'previous', page, 'next' ];
  11878. * };
  11879. */
  11880. pager: {},
  11881. renderer: {
  11882. pageButton: {},
  11883. header: {}
  11884. },
  11885. /**
  11886. * Ordering plug-ins - custom data source
  11887. *
  11888. * The extension options for ordering of data available here is complimentary
  11889. * to the default type based ordering that DataTables typically uses. It
  11890. * allows much greater control over the the data that is being used to
  11891. * order a column, but is necessarily therefore more complex.
  11892. *
  11893. * This type of ordering is useful if you want to do ordering based on data
  11894. * live from the DOM (for example the contents of an 'input' element) rather
  11895. * than just the static string that DataTables knows of.
  11896. *
  11897. * The way these plug-ins work is that you create an array of the values you
  11898. * wish to be ordering for the column in question and then return that
  11899. * array. The data in the array much be in the index order of the rows in
  11900. * the table (not the currently ordering order!). Which order data gathering
  11901. * function is run here depends on the `dt-init columns.orderDataType`
  11902. * parameter that is used for the column (if any).
  11903. *
  11904. * The functions defined take two parameters:
  11905. *
  11906. * 1. `{object}` DataTables settings object: see
  11907. * {@link DataTable.models.oSettings}
  11908. * 2. `{int}` Target column index
  11909. *
  11910. * Each function is expected to return an array:
  11911. *
  11912. * * `{array}` Data for the column to be ordering upon
  11913. *
  11914. * @type array
  11915. *
  11916. * @example
  11917. * // Ordering using `input` node values
  11918. * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
  11919. * {
  11920. * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
  11921. * return $('input', td).val();
  11922. * } );
  11923. * }
  11924. */
  11925. order: {},
  11926. /**
  11927. * Type based plug-ins.
  11928. *
  11929. * Each column in DataTables has a type assigned to it, either by automatic
  11930. * detection or by direct assignment using the `type` option for the column.
  11931. * The type of a column will effect how it is ordering and search (plug-ins
  11932. * can also make use of the column type if required).
  11933. *
  11934. * @namespace
  11935. */
  11936. type: {
  11937. /**
  11938. * Type detection functions.
  11939. *
  11940. * The functions defined in this object are used to automatically detect
  11941. * a column's type, making initialisation of DataTables super easy, even
  11942. * when complex data is in the table.
  11943. *
  11944. * The functions defined take two parameters:
  11945. *
  11946. * 1. `{*}` Data from the column cell to be analysed
  11947. * 2. `{settings}` DataTables settings object. This can be used to
  11948. * perform context specific type detection - for example detection
  11949. * based on language settings such as using a comma for a decimal
  11950. * place. Generally speaking the options from the settings will not
  11951. * be required
  11952. *
  11953. * Each function is expected to return:
  11954. *
  11955. * * `{string|null}` Data type detected, or null if unknown (and thus
  11956. * pass it on to the other type detection functions.
  11957. *
  11958. * @type array
  11959. *
  11960. * @example
  11961. * // Currency type detection plug-in:
  11962. * $.fn.dataTable.ext.type.detect.push(
  11963. * function ( data, settings ) {
  11964. * // Check the numeric part
  11965. * if ( ! data.substring(1).match(/[0-9]/) ) {
  11966. * return null;
  11967. * }
  11968. *
  11969. * // Check prefixed by currency
  11970. * if ( data.charAt(0) == '$' || data.charAt(0) == '&pound;' ) {
  11971. * return 'currency';
  11972. * }
  11973. * return null;
  11974. * }
  11975. * );
  11976. */
  11977. detect: [],
  11978. /**
  11979. * Type based search formatting.
  11980. *
  11981. * The type based searching functions can be used to pre-format the
  11982. * data to be search on. For example, it can be used to strip HTML
  11983. * tags or to de-format telephone numbers for numeric only searching.
  11984. *
  11985. * Note that is a search is not defined for a column of a given type,
  11986. * no search formatting will be performed.
  11987. *
  11988. * Pre-processing of searching data plug-ins - When you assign the sType
  11989. * for a column (or have it automatically detected for you by DataTables
  11990. * or a type detection plug-in), you will typically be using this for
  11991. * custom sorting, but it can also be used to provide custom searching
  11992. * by allowing you to pre-processing the data and returning the data in
  11993. * the format that should be searched upon. This is done by adding
  11994. * functions this object with a parameter name which matches the sType
  11995. * for that target column. This is the corollary of <i>afnSortData</i>
  11996. * for searching data.
  11997. *
  11998. * The functions defined take a single parameter:
  11999. *
  12000. * 1. `{*}` Data from the column cell to be prepared for searching
  12001. *
  12002. * Each function is expected to return:
  12003. *
  12004. * * `{string|null}` Formatted string that will be used for the searching.
  12005. *
  12006. * @type object
  12007. * @default {}
  12008. *
  12009. * @example
  12010. * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
  12011. * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
  12012. * }
  12013. */
  12014. search: {},
  12015. /**
  12016. * Type based ordering.
  12017. *
  12018. * The column type tells DataTables what ordering to apply to the table
  12019. * when a column is sorted upon. The order for each type that is defined,
  12020. * is defined by the functions available in this object.
  12021. *
  12022. * Each ordering option can be described by three properties added to
  12023. * this object:
  12024. *
  12025. * * `{type}-pre` - Pre-formatting function
  12026. * * `{type}-asc` - Ascending order function
  12027. * * `{type}-desc` - Descending order function
  12028. *
  12029. * All three can be used together, only `{type}-pre` or only
  12030. * `{type}-asc` and `{type}-desc` together. It is generally recommended
  12031. * that only `{type}-pre` is used, as this provides the optimal
  12032. * implementation in terms of speed, although the others are provided
  12033. * for compatibility with existing Javascript sort functions.
  12034. *
  12035. * `{type}-pre`: Functions defined take a single parameter:
  12036. *
  12037. * 1. `{*}` Data from the column cell to be prepared for ordering
  12038. *
  12039. * And return:
  12040. *
  12041. * * `{*}` Data to be sorted upon
  12042. *
  12043. * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
  12044. * functions, taking two parameters:
  12045. *
  12046. * 1. `{*}` Data to compare to the second parameter
  12047. * 2. `{*}` Data to compare to the first parameter
  12048. *
  12049. * And returning:
  12050. *
  12051. * * `{*}` Ordering match: <0 if first parameter should be sorted lower
  12052. * than the second parameter, ===0 if the two parameters are equal and
  12053. * >0 if the first parameter should be sorted height than the second
  12054. * parameter.
  12055. *
  12056. * @type object
  12057. * @default {}
  12058. *
  12059. * @example
  12060. * // Numeric ordering of formatted numbers with a pre-formatter
  12061. * $.extend( $.fn.dataTable.ext.type.order, {
  12062. * "string-pre": function(x) {
  12063. * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  12064. * return parseFloat( a );
  12065. * }
  12066. * } );
  12067. *
  12068. * @example
  12069. * // Case-sensitive string ordering, with no pre-formatting method
  12070. * $.extend( $.fn.dataTable.ext.order, {
  12071. * "string-case-asc": function(x,y) {
  12072. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12073. * },
  12074. * "string-case-desc": function(x,y) {
  12075. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12076. * }
  12077. * } );
  12078. */
  12079. order: {}
  12080. },
  12081. /**
  12082. * Unique DataTables instance counter
  12083. *
  12084. * @type int
  12085. * @private
  12086. */
  12087. _unique: 0,
  12088. //
  12089. // Depreciated
  12090. // The following properties are retained for backwards compatiblity only.
  12091. // The should not be used in new projects and will be removed in a future
  12092. // version
  12093. //
  12094. /**
  12095. * Version check function.
  12096. * @type function
  12097. * @depreciated Since 1.10
  12098. */
  12099. fnVersionCheck: DataTable.fnVersionCheck,
  12100. /**
  12101. * Index for what 'this' index API functions should use
  12102. * @type int
  12103. * @deprecated Since v1.10
  12104. */
  12105. iApiIndex: 0,
  12106. /**
  12107. * jQuery UI class container
  12108. * @type object
  12109. * @deprecated Since v1.10
  12110. */
  12111. oJUIClasses: {},
  12112. /**
  12113. * Software version
  12114. * @type string
  12115. * @deprecated Since v1.10
  12116. */
  12117. sVersion: DataTable.version
  12118. };
  12119. //
  12120. // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
  12121. //
  12122. $.extend(_ext, {
  12123. afnFiltering: _ext.search,
  12124. aTypes: _ext.type.detect,
  12125. ofnSearch: _ext.type.search,
  12126. oSort: _ext.type.order,
  12127. afnSortData: _ext.order,
  12128. aoFeatures: _ext.feature,
  12129. oApi: _ext.internal,
  12130. oStdClasses: _ext.classes,
  12131. oPagination: _ext.pager
  12132. });
  12133. $.extend(DataTable.ext.classes, {
  12134. "sTable": "dataTable",
  12135. "sNoFooter": "no-footer",
  12136. /* Paging buttons */
  12137. "sPageButton": "paginate_button",
  12138. "sPageButtonActive": "current",
  12139. "sPageButtonDisabled": "disabled",
  12140. /* Striping classes */
  12141. "sStripeOdd": "odd",
  12142. "sStripeEven": "even",
  12143. /* Empty row */
  12144. "sRowEmpty": "dataTables_empty",
  12145. /* Features */
  12146. "sWrapper": "dataTables_wrapper",
  12147. "sFilter": "dataTables_filter",
  12148. "sInfo": "dataTables_info",
  12149. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  12150. "sLength": "dataTables_length",
  12151. "sProcessing": "dataTables_processing",
  12152. /* Sorting */
  12153. "sSortAsc": "sorting_asc",
  12154. "sSortDesc": "sorting_desc",
  12155. "sSortable": "sorting", /* Sortable in both directions */
  12156. "sSortableAsc": "sorting_desc_disabled",
  12157. "sSortableDesc": "sorting_asc_disabled",
  12158. "sSortableNone": "sorting_disabled",
  12159. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  12160. /* Filtering */
  12161. "sFilterInput": "",
  12162. /* Page length */
  12163. "sLengthSelect": "",
  12164. /* Scrolling */
  12165. "sScrollWrapper": "dataTables_scroll",
  12166. "sScrollHead": "dataTables_scrollHead",
  12167. "sScrollHeadInner": "dataTables_scrollHeadInner",
  12168. "sScrollBody": "dataTables_scrollBody",
  12169. "sScrollFoot": "dataTables_scrollFoot",
  12170. "sScrollFootInner": "dataTables_scrollFootInner",
  12171. /* Misc */
  12172. "sHeaderTH": "",
  12173. "sFooterTH": "",
  12174. // Deprecated
  12175. "sSortJUIAsc": "",
  12176. "sSortJUIDesc": "",
  12177. "sSortJUI": "",
  12178. "sSortJUIAscAllowed": "",
  12179. "sSortJUIDescAllowed": "",
  12180. "sSortJUIWrapper": "",
  12181. "sSortIcon": "",
  12182. "sJUIHeader": "",
  12183. "sJUIFooter": ""
  12184. });
  12185. var extPagination = DataTable.ext.pager;
  12186. function _numbers(page, pages) {
  12187. var
  12188. numbers = [],
  12189. buttons = extPagination.numbers_length,
  12190. half = Math.floor(buttons / 2),
  12191. i = 1;
  12192. if (pages <= buttons) {
  12193. numbers = _range(0, pages);
  12194. } else if (page <= half) {
  12195. numbers = _range(0, buttons - 2);
  12196. numbers.push('ellipsis');
  12197. numbers.push(pages - 1);
  12198. } else if (page >= pages - 1 - half) {
  12199. numbers = _range(pages - (buttons - 2), pages);
  12200. numbers.splice(0, 0, 'ellipsis'); // no unshift in ie6
  12201. numbers.splice(0, 0, 0);
  12202. } else {
  12203. numbers = _range(page - half + 2, page + half - 1);
  12204. numbers.push('ellipsis');
  12205. numbers.push(pages - 1);
  12206. numbers.splice(0, 0, 'ellipsis');
  12207. numbers.splice(0, 0, 0);
  12208. }
  12209. numbers.DT_el = 'span';
  12210. return numbers;
  12211. }
  12212. $.extend(extPagination, {
  12213. simple: function (page, pages) {
  12214. return ['previous', 'next'];
  12215. },
  12216. full: function (page, pages) {
  12217. return ['first', 'previous', 'next', 'last'];
  12218. },
  12219. numbers: function (page, pages) {
  12220. return [_numbers(page, pages)];
  12221. },
  12222. simple_numbers: function (page, pages) {
  12223. return ['previous', _numbers(page, pages), 'next'];
  12224. },
  12225. full_numbers: function (page, pages) {
  12226. return ['first', 'previous', _numbers(page, pages), 'next', 'last'];
  12227. },
  12228. first_last_numbers: function (page, pages) {
  12229. return ['first', _numbers(page, pages), 'last'];
  12230. },
  12231. // For testing and plug-ins to use
  12232. _numbers: _numbers,
  12233. // Number of number buttons (including ellipsis) to show. _Must be odd!_
  12234. numbers_length: 7
  12235. });
  12236. $.extend(true, DataTable.ext.renderer, {
  12237. pageButton: {
  12238. _: function (settings, host, idx, buttons, page, pages) {
  12239. var classes = settings.oClasses;
  12240. var lang = settings.oLanguage.oPaginate;
  12241. var aria = settings.oLanguage.oAria.paginate || {};
  12242. var btnDisplay, btnClass, counter = 0;
  12243. var attach = function (container, buttons) {
  12244. var i, ien, node, button, tabIndex;
  12245. var disabledClass = classes.sPageButtonDisabled;
  12246. var clickHandler = function (e) {
  12247. _fnPageChange(settings, e.data.action, true);
  12248. };
  12249. for (i = 0, ien = buttons.length; i < ien; i++) {
  12250. button = buttons[i];
  12251. if (Array.isArray(button)) {
  12252. var inner = $('<' + (button.DT_el || 'div') + '/>')
  12253. .appendTo(container);
  12254. attach(inner, button);
  12255. } else {
  12256. btnDisplay = null;
  12257. btnClass = button;
  12258. tabIndex = settings.iTabIndex;
  12259. switch (button) {
  12260. case 'ellipsis':
  12261. container.append('<span class="ellipsis">&#x2026;</span>');
  12262. break;
  12263. case 'first':
  12264. btnDisplay = lang.sFirst;
  12265. if (page === 0) {
  12266. tabIndex = -1;
  12267. btnClass += ' ' + disabledClass;
  12268. }
  12269. break;
  12270. case 'previous':
  12271. btnDisplay = lang.sPrevious;
  12272. if (page === 0) {
  12273. tabIndex = -1;
  12274. btnClass += ' ' + disabledClass;
  12275. }
  12276. break;
  12277. case 'next':
  12278. btnDisplay = lang.sNext;
  12279. if (pages === 0 || page === pages - 1) {
  12280. tabIndex = -1;
  12281. btnClass += ' ' + disabledClass;
  12282. }
  12283. break;
  12284. case 'last':
  12285. btnDisplay = lang.sLast;
  12286. if (pages === 0 || page === pages - 1) {
  12287. tabIndex = -1;
  12288. btnClass += ' ' + disabledClass;
  12289. }
  12290. break;
  12291. default:
  12292. btnDisplay = settings.fnFormatNumber(button + 1);
  12293. btnClass = page === button ?
  12294. classes.sPageButtonActive : '';
  12295. break;
  12296. }
  12297. if (btnDisplay !== null) {
  12298. node = $('<a>', {
  12299. 'class': classes.sPageButton + ' ' + btnClass,
  12300. 'aria-controls': settings.sTableId,
  12301. 'aria-label': aria[button],
  12302. 'data-dt-idx': counter,
  12303. 'tabindex': tabIndex,
  12304. 'id': idx === 0 && typeof button === 'string' ?
  12305. settings.sTableId + '_' + button :
  12306. null
  12307. })
  12308. .html(btnDisplay)
  12309. .appendTo(container);
  12310. _fnBindAction(
  12311. node, {action: button}, clickHandler
  12312. );
  12313. counter++;
  12314. }
  12315. }
  12316. }
  12317. };
  12318. // IE9 throws an 'unknown error' if document.activeElement is used
  12319. // inside an iframe or frame. Try / catch the error. Not good for
  12320. // accessibility, but neither are frames.
  12321. var activeEl;
  12322. try {
  12323. // Because this approach is destroying and recreating the paging
  12324. // elements, focus is lost on the select button which is bad for
  12325. // accessibility. So we want to restore focus once the draw has
  12326. // completed
  12327. activeEl = $(host).find(document.activeElement).data('dt-idx');
  12328. } catch (e) {
  12329. }
  12330. attach($(host).empty(), buttons);
  12331. if (activeEl !== undefined) {
  12332. $(host).find('[data-dt-idx=' + activeEl + ']').trigger('focus');
  12333. }
  12334. }
  12335. }
  12336. });
  12337. // Built in type detection. See model.ext.aTypes for information about
  12338. // what is required from this methods.
  12339. $.extend(DataTable.ext.type.detect, [
  12340. // Plain numbers - first since V8 detects some plain numbers as dates
  12341. // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
  12342. function (d, settings) {
  12343. var decimal = settings.oLanguage.sDecimal;
  12344. return _isNumber(d, decimal) ? 'num' + decimal : null;
  12345. },
  12346. // Dates (only those recognised by the browser's Date.parse)
  12347. function (d, settings) {
  12348. // V8 tries _very_ hard to make a string passed into `Date.parse()`
  12349. // valid, so we need to use a regex to restrict date formats. Use a
  12350. // plug-in for anything other than ISO8601 style strings
  12351. if (d && !(d instanceof Date) && !_re_date.test(d)) {
  12352. return null;
  12353. }
  12354. var parsed = Date.parse(d);
  12355. return (parsed !== null && !isNaN(parsed)) || _empty(d) ? 'date' : null;
  12356. },
  12357. // Formatted numbers
  12358. function (d, settings) {
  12359. var decimal = settings.oLanguage.sDecimal;
  12360. return _isNumber(d, decimal, true) ? 'num-fmt' + decimal : null;
  12361. },
  12362. // HTML numeric
  12363. function (d, settings) {
  12364. var decimal = settings.oLanguage.sDecimal;
  12365. return _htmlNumeric(d, decimal) ? 'html-num' + decimal : null;
  12366. },
  12367. // HTML numeric, formatted
  12368. function (d, settings) {
  12369. var decimal = settings.oLanguage.sDecimal;
  12370. return _htmlNumeric(d, decimal, true) ? 'html-num-fmt' + decimal : null;
  12371. },
  12372. // HTML (this is strict checking - there must be html)
  12373. function (d, settings) {
  12374. return _empty(d) || (typeof d === 'string' && d.indexOf('<') !== -1) ?
  12375. 'html' : null;
  12376. }
  12377. ]);
  12378. // Filter formatting functions. See model.ext.ofnSearch for information about
  12379. // what is required from these methods.
  12380. //
  12381. // Note that additional search methods are added for the html numbers and
  12382. // html formatted numbers by `_addNumericSort()` when we know what the decimal
  12383. // place is
  12384. $.extend(DataTable.ext.type.search, {
  12385. html: function (data) {
  12386. return _empty(data) ?
  12387. data :
  12388. typeof data === 'string' ?
  12389. data
  12390. .replace(_re_new_lines, " ")
  12391. .replace(_re_html, "") :
  12392. '';
  12393. },
  12394. string: function (data) {
  12395. return _empty(data) ?
  12396. data :
  12397. typeof data === 'string' ?
  12398. data.replace(_re_new_lines, " ") :
  12399. data;
  12400. }
  12401. });
  12402. var __numericReplace = function (d, decimalPlace, re1, re2) {
  12403. if (d !== 0 && (!d || d === '-')) {
  12404. return -Infinity;
  12405. }
  12406. // If a decimal place other than `.` is used, it needs to be given to the
  12407. // function so we can detect it and replace with a `.` which is the only
  12408. // decimal place Javascript recognises - it is not locale aware.
  12409. if (decimalPlace) {
  12410. d = _numToDecimal(d, decimalPlace);
  12411. }
  12412. if (d.replace) {
  12413. if (re1) {
  12414. d = d.replace(re1, '');
  12415. }
  12416. if (re2) {
  12417. d = d.replace(re2, '');
  12418. }
  12419. }
  12420. return d * 1;
  12421. };
  12422. // Add the numeric 'deformatting' functions for sorting and search. This is done
  12423. // in a function to provide an easy ability for the language options to add
  12424. // additional methods if a non-period decimal place is used.
  12425. function _addNumericSort(decimalPlace) {
  12426. $.each(
  12427. {
  12428. // Plain numbers
  12429. "num": function (d) {
  12430. return __numericReplace(d, decimalPlace);
  12431. },
  12432. // Formatted numbers
  12433. "num-fmt": function (d) {
  12434. return __numericReplace(d, decimalPlace, _re_formatted_numeric);
  12435. },
  12436. // HTML numeric
  12437. "html-num": function (d) {
  12438. return __numericReplace(d, decimalPlace, _re_html);
  12439. },
  12440. // HTML numeric, formatted
  12441. "html-num-fmt": function (d) {
  12442. return __numericReplace(d, decimalPlace, _re_html, _re_formatted_numeric);
  12443. }
  12444. },
  12445. function (key, fn) {
  12446. // Add the ordering method
  12447. _ext.type.order[key + decimalPlace + '-pre'] = fn;
  12448. // For HTML types add a search formatter that will strip the HTML
  12449. if (key.match(/^html\-/)) {
  12450. _ext.type.search[key + decimalPlace] = _ext.type.search.html;
  12451. }
  12452. }
  12453. );
  12454. }
  12455. // Default sort methods
  12456. $.extend(_ext.type.order, {
  12457. // Dates
  12458. "date-pre": function (d) {
  12459. var ts = Date.parse(d);
  12460. return isNaN(ts) ? -Infinity : ts;
  12461. },
  12462. // html
  12463. "html-pre": function (a) {
  12464. return _empty(a) ?
  12465. '' :
  12466. a.replace ?
  12467. a.replace(/<.*?>/g, "").toLowerCase() :
  12468. a + '';
  12469. },
  12470. // string
  12471. "string-pre": function (a) {
  12472. // This is a little complex, but faster than always calling toString,
  12473. // http://jsperf.com/tostring-v-check
  12474. return _empty(a) ?
  12475. '' :
  12476. typeof a === 'string' ?
  12477. a.toLowerCase() :
  12478. !a.toString ?
  12479. '' :
  12480. a.toString();
  12481. },
  12482. // string-asc and -desc are retained only for compatibility with the old
  12483. // sort methods
  12484. "string-asc": function (x, y) {
  12485. return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12486. },
  12487. "string-desc": function (x, y) {
  12488. return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12489. }
  12490. });
  12491. // Numeric sorting types - order doesn't matter here
  12492. _addNumericSort('');
  12493. $.extend(true, DataTable.ext.renderer, {
  12494. header: {
  12495. _: function (settings, cell, column, classes) {
  12496. // No additional mark-up required
  12497. // Attach a sort listener to update on sort - note that using the
  12498. // `DT` namespace will allow the event to be removed automatically
  12499. // on destroy, while the `dt` namespaced event is the one we are
  12500. // listening for
  12501. $(settings.nTable).on('order.dt.DT', function (e, ctx, sorting, columns) {
  12502. if (settings !== ctx) { // need to check this this is the host
  12503. return; // table, not a nested one
  12504. }
  12505. var colIdx = column.idx;
  12506. cell
  12507. .removeClass(
  12508. classes.sSortAsc + ' ' +
  12509. classes.sSortDesc
  12510. )
  12511. .addClass(columns[colIdx] == 'asc' ?
  12512. classes.sSortAsc : columns[colIdx] == 'desc' ?
  12513. classes.sSortDesc :
  12514. column.sSortingClass
  12515. );
  12516. });
  12517. },
  12518. jqueryui: function (settings, cell, column, classes) {
  12519. $('<div/>')
  12520. .addClass(classes.sSortJUIWrapper)
  12521. .append(cell.contents())
  12522. .append($('<span/>')
  12523. .addClass(classes.sSortIcon + ' ' + column.sSortingClassJUI)
  12524. )
  12525. .appendTo(cell);
  12526. // Attach a sort listener to update on sort
  12527. $(settings.nTable).on('order.dt.DT', function (e, ctx, sorting, columns) {
  12528. if (settings !== ctx) {
  12529. return;
  12530. }
  12531. var colIdx = column.idx;
  12532. cell
  12533. .removeClass(classes.sSortAsc + " " + classes.sSortDesc)
  12534. .addClass(columns[colIdx] == 'asc' ?
  12535. classes.sSortAsc : columns[colIdx] == 'desc' ?
  12536. classes.sSortDesc :
  12537. column.sSortingClass
  12538. );
  12539. cell
  12540. .find('span.' + classes.sSortIcon)
  12541. .removeClass(
  12542. classes.sSortJUIAsc + " " +
  12543. classes.sSortJUIDesc + " " +
  12544. classes.sSortJUI + " " +
  12545. classes.sSortJUIAscAllowed + " " +
  12546. classes.sSortJUIDescAllowed
  12547. )
  12548. .addClass(columns[colIdx] == 'asc' ?
  12549. classes.sSortJUIAsc : columns[colIdx] == 'desc' ?
  12550. classes.sSortJUIDesc :
  12551. column.sSortingClassJUI
  12552. );
  12553. });
  12554. }
  12555. }
  12556. });
  12557. /*
  12558. * Public helper functions. These aren't used internally by DataTables, or
  12559. * called by any of the options passed into DataTables, but they can be used
  12560. * externally by developers working with DataTables. They are helper functions
  12561. * to make working with DataTables a little bit easier.
  12562. */
  12563. var __htmlEscapeEntities = function (d) {
  12564. return typeof d === 'string' ?
  12565. d
  12566. .replace(/&/g, '&amp;')
  12567. .replace(/</g, '&lt;')
  12568. .replace(/>/g, '&gt;')
  12569. .replace(/"/g, '&quot;') :
  12570. d;
  12571. };
  12572. /**
  12573. * Helpers for `columns.render`.
  12574. *
  12575. * The options defined here can be used with the `columns.render` initialisation
  12576. * option to provide a display renderer. The following functions are defined:
  12577. *
  12578. * * `number` - Will format numeric data (defined by `columns.data`) for
  12579. * display, retaining the original unformatted data for sorting and filtering.
  12580. * It takes 5 parameters:
  12581. * * `string` - Thousands grouping separator
  12582. * * `string` - Decimal point indicator
  12583. * * `integer` - Number of decimal points to show
  12584. * * `string` (optional) - Prefix.
  12585. * * `string` (optional) - Postfix (/suffix).
  12586. * * `text` - Escape HTML to help prevent XSS attacks. It has no optional
  12587. * parameters.
  12588. *
  12589. * @example
  12590. * // Column definition using the number renderer
  12591. * {
  12592. * data: "salary",
  12593. * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
  12594. * }
  12595. *
  12596. * @namespace
  12597. */
  12598. DataTable.render = {
  12599. number: function (thousands, decimal, precision, prefix, postfix) {
  12600. return {
  12601. display: function (d) {
  12602. if (typeof d !== 'number' && typeof d !== 'string') {
  12603. return d;
  12604. }
  12605. var negative = d < 0 ? '-' : '';
  12606. var flo = parseFloat(d);
  12607. // If NaN then there isn't much formatting that we can do - just
  12608. // return immediately, escaping any HTML (this was supposed to
  12609. // be a number after all)
  12610. if (isNaN(flo)) {
  12611. return __htmlEscapeEntities(d);
  12612. }
  12613. flo = flo.toFixed(precision);
  12614. d = Math.abs(flo);
  12615. var intPart = parseInt(d, 10);
  12616. var floatPart = precision ?
  12617. decimal + (d - intPart).toFixed(precision).substring(2) :
  12618. '';
  12619. return negative + (prefix || '') +
  12620. intPart.toString().replace(
  12621. /\B(?=(\d{3})+(?!\d))/g, thousands
  12622. ) +
  12623. floatPart +
  12624. (postfix || '');
  12625. }
  12626. };
  12627. },
  12628. text: function () {
  12629. return {
  12630. display: __htmlEscapeEntities,
  12631. filter: __htmlEscapeEntities
  12632. };
  12633. }
  12634. };
  12635. /*
  12636. * This is really a good bit rubbish this method of exposing the internal methods
  12637. * publicly... - To be fixed in 2.0 using methods on the prototype
  12638. */
  12639. /**
  12640. * Create a wrapper function for exporting an internal functions to an external API.
  12641. * @param {string} fn API function name
  12642. * @returns {function} wrapped function
  12643. * @memberof DataTable#internal
  12644. */
  12645. function _fnExternApiFunc(fn) {
  12646. return function () {
  12647. var args = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat(
  12648. Array.prototype.slice.call(arguments)
  12649. );
  12650. return DataTable.ext.internal[fn].apply(this, args);
  12651. };
  12652. }
  12653. /**
  12654. * Reference to internal functions for use by plug-in developers. Note that
  12655. * these methods are references to internal functions and are considered to be
  12656. * private. If you use these methods, be aware that they are liable to change
  12657. * between versions.
  12658. * @namespace
  12659. */
  12660. $.extend(DataTable.ext.internal, {
  12661. _fnExternApiFunc: _fnExternApiFunc,
  12662. _fnBuildAjax: _fnBuildAjax,
  12663. _fnAjaxUpdate: _fnAjaxUpdate,
  12664. _fnAjaxParameters: _fnAjaxParameters,
  12665. _fnAjaxUpdateDraw: _fnAjaxUpdateDraw,
  12666. _fnAjaxDataSrc: _fnAjaxDataSrc,
  12667. _fnAddColumn: _fnAddColumn,
  12668. _fnColumnOptions: _fnColumnOptions,
  12669. _fnAdjustColumnSizing: _fnAdjustColumnSizing,
  12670. _fnVisibleToColumnIndex: _fnVisibleToColumnIndex,
  12671. _fnColumnIndexToVisible: _fnColumnIndexToVisible,
  12672. _fnVisbleColumns: _fnVisbleColumns,
  12673. _fnGetColumns: _fnGetColumns,
  12674. _fnColumnTypes: _fnColumnTypes,
  12675. _fnApplyColumnDefs: _fnApplyColumnDefs,
  12676. _fnHungarianMap: _fnHungarianMap,
  12677. _fnCamelToHungarian: _fnCamelToHungarian,
  12678. _fnLanguageCompat: _fnLanguageCompat,
  12679. _fnBrowserDetect: _fnBrowserDetect,
  12680. _fnAddData: _fnAddData,
  12681. _fnAddTr: _fnAddTr,
  12682. _fnNodeToDataIndex: _fnNodeToDataIndex,
  12683. _fnNodeToColumnIndex: _fnNodeToColumnIndex,
  12684. _fnGetCellData: _fnGetCellData,
  12685. _fnSetCellData: _fnSetCellData,
  12686. _fnSplitObjNotation: _fnSplitObjNotation,
  12687. _fnGetObjectDataFn: _fnGetObjectDataFn,
  12688. _fnSetObjectDataFn: _fnSetObjectDataFn,
  12689. _fnGetDataMaster: _fnGetDataMaster,
  12690. _fnClearTable: _fnClearTable,
  12691. _fnDeleteIndex: _fnDeleteIndex,
  12692. _fnInvalidate: _fnInvalidate,
  12693. _fnGetRowElements: _fnGetRowElements,
  12694. _fnCreateTr: _fnCreateTr,
  12695. _fnBuildHead: _fnBuildHead,
  12696. _fnDrawHead: _fnDrawHead,
  12697. _fnDraw: _fnDraw,
  12698. _fnReDraw: _fnReDraw,
  12699. _fnAddOptionsHtml: _fnAddOptionsHtml,
  12700. _fnDetectHeader: _fnDetectHeader,
  12701. _fnGetUniqueThs: _fnGetUniqueThs,
  12702. _fnFeatureHtmlFilter: _fnFeatureHtmlFilter,
  12703. _fnFilterComplete: _fnFilterComplete,
  12704. _fnFilterCustom: _fnFilterCustom,
  12705. _fnFilterColumn: _fnFilterColumn,
  12706. _fnFilter: _fnFilter,
  12707. _fnFilterCreateSearch: _fnFilterCreateSearch,
  12708. _fnEscapeRegex: _fnEscapeRegex,
  12709. _fnFilterData: _fnFilterData,
  12710. _fnFeatureHtmlInfo: _fnFeatureHtmlInfo,
  12711. _fnUpdateInfo: _fnUpdateInfo,
  12712. _fnInfoMacros: _fnInfoMacros,
  12713. _fnInitialise: _fnInitialise,
  12714. _fnInitComplete: _fnInitComplete,
  12715. _fnLengthChange: _fnLengthChange,
  12716. _fnFeatureHtmlLength: _fnFeatureHtmlLength,
  12717. _fnFeatureHtmlPaginate: _fnFeatureHtmlPaginate,
  12718. _fnPageChange: _fnPageChange,
  12719. _fnFeatureHtmlProcessing: _fnFeatureHtmlProcessing,
  12720. _fnProcessingDisplay: _fnProcessingDisplay,
  12721. _fnFeatureHtmlTable: _fnFeatureHtmlTable,
  12722. _fnScrollDraw: _fnScrollDraw,
  12723. _fnApplyToChildren: _fnApplyToChildren,
  12724. _fnCalculateColumnWidths: _fnCalculateColumnWidths,
  12725. _fnThrottle: _fnThrottle,
  12726. _fnConvertToWidth: _fnConvertToWidth,
  12727. _fnGetWidestNode: _fnGetWidestNode,
  12728. _fnGetMaxLenString: _fnGetMaxLenString,
  12729. _fnStringToCss: _fnStringToCss,
  12730. _fnSortFlatten: _fnSortFlatten,
  12731. _fnSort: _fnSort,
  12732. _fnSortAria: _fnSortAria,
  12733. _fnSortListener: _fnSortListener,
  12734. _fnSortAttachListener: _fnSortAttachListener,
  12735. _fnSortingClasses: _fnSortingClasses,
  12736. _fnSortData: _fnSortData,
  12737. _fnSaveState: _fnSaveState,
  12738. _fnLoadState: _fnLoadState,
  12739. _fnSettingsFromNode: _fnSettingsFromNode,
  12740. _fnLog: _fnLog,
  12741. _fnMap: _fnMap,
  12742. _fnBindAction: _fnBindAction,
  12743. _fnCallbackReg: _fnCallbackReg,
  12744. _fnCallbackFire: _fnCallbackFire,
  12745. _fnLengthOverflow: _fnLengthOverflow,
  12746. _fnRenderer: _fnRenderer,
  12747. _fnDataSource: _fnDataSource,
  12748. _fnRowAttributes: _fnRowAttributes,
  12749. _fnExtend: _fnExtend,
  12750. _fnCalculateEnd: function () {
  12751. } // Used by a lot of plug-ins, but redundant
  12752. // in 1.10, so this dead-end function is
  12753. // added to prevent errors
  12754. });
  12755. // jQuery access
  12756. $.fn.dataTable = DataTable;
  12757. // Provide access to the host jQuery object (circular reference)
  12758. DataTable.$ = $;
  12759. // Legacy aliases
  12760. $.fn.dataTableSettings = DataTable.settings;
  12761. $.fn.dataTableExt = DataTable.ext;
  12762. // With a capital `D` we return a DataTables API instance rather than a
  12763. // jQuery object
  12764. $.fn.DataTable = function (opts) {
  12765. return $(this).dataTable(opts).api();
  12766. };
  12767. // All properties that are available to $.fn.dataTable should also be
  12768. // available on $.fn.DataTable
  12769. $.each(DataTable, function (prop, val) {
  12770. $.fn.DataTable[prop] = val;
  12771. });
  12772. // Information about events fired by DataTables - for documentation.
  12773. /**
  12774. * Draw event, fired whenever the table is redrawn on the page, at the same
  12775. * point as fnDrawCallback. This may be useful for binding events or
  12776. * performing calculations when the table is altered at all.
  12777. * @name DataTable#draw.dt
  12778. * @event
  12779. * @param {event} e jQuery event object
  12780. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12781. */
  12782. /**
  12783. * Search event, fired when the searching applied to the table (using the
  12784. * built-in global search, or column filters) is altered.
  12785. * @name DataTable#search.dt
  12786. * @event
  12787. * @param {event} e jQuery event object
  12788. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12789. */
  12790. /**
  12791. * Page change event, fired when the paging of the table is altered.
  12792. * @name DataTable#page.dt
  12793. * @event
  12794. * @param {event} e jQuery event object
  12795. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12796. */
  12797. /**
  12798. * Order event, fired when the ordering applied to the table is altered.
  12799. * @name DataTable#order.dt
  12800. * @event
  12801. * @param {event} e jQuery event object
  12802. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12803. */
  12804. /**
  12805. * DataTables initialisation complete event, fired when the table is fully
  12806. * drawn, including Ajax data loaded, if Ajax data is required.
  12807. * @name DataTable#init.dt
  12808. * @event
  12809. * @param {event} e jQuery event object
  12810. * @param {object} oSettings DataTables settings object
  12811. * @param {object} json The JSON object request from the server - only
  12812. * present if client-side Ajax sourced data is used</li></ol>
  12813. */
  12814. /**
  12815. * State save event, fired when the table has changed state a new state save
  12816. * is required. This event allows modification of the state saving object
  12817. * prior to actually doing the save, including addition or other state
  12818. * properties (for plug-ins) or modification of a DataTables core property.
  12819. * @name DataTable#stateSaveParams.dt
  12820. * @event
  12821. * @param {event} e jQuery event object
  12822. * @param {object} oSettings DataTables settings object
  12823. * @param {object} json The state information to be saved
  12824. */
  12825. /**
  12826. * State load event, fired when the table is loading state from the stored
  12827. * data, but prior to the settings object being modified by the saved state
  12828. * - allowing modification of the saved state is required or loading of
  12829. * state for a plug-in.
  12830. * @name DataTable#stateLoadParams.dt
  12831. * @event
  12832. * @param {event} e jQuery event object
  12833. * @param {object} oSettings DataTables settings object
  12834. * @param {object} json The saved state information
  12835. */
  12836. /**
  12837. * State loaded event, fired when state has been loaded from stored data and
  12838. * the settings object has been modified by the loaded data.
  12839. * @name DataTable#stateLoaded.dt
  12840. * @event
  12841. * @param {event} e jQuery event object
  12842. * @param {object} oSettings DataTables settings object
  12843. * @param {object} json The saved state information
  12844. */
  12845. /**
  12846. * Processing event, fired when DataTables is doing some kind of processing
  12847. * (be it, order, search or anything else). It can be used to indicate to
  12848. * the end user that there is something happening, or that something has
  12849. * finished.
  12850. * @name DataTable#processing.dt
  12851. * @event
  12852. * @param {event} e jQuery event object
  12853. * @param {object} oSettings DataTables settings object
  12854. * @param {boolean} bShow Flag for if DataTables is doing processing or not
  12855. */
  12856. /**
  12857. * Ajax (XHR) event, fired whenever an Ajax request is completed from a
  12858. * request to made to the server for new data. This event is called before
  12859. * DataTables processed the returned data, so it can also be used to pre-
  12860. * process the data returned from the server, if needed.
  12861. *
  12862. * Note that this trigger is called in `fnServerData`, if you override
  12863. * `fnServerData` and which to use this event, you need to trigger it in you
  12864. * success function.
  12865. * @name DataTable#xhr.dt
  12866. * @event
  12867. * @param {event} e jQuery event object
  12868. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12869. * @param {object} json JSON returned from the server
  12870. *
  12871. * @example
  12872. * // Use a custom property returned from the server in another DOM element
  12873. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  12874. * $('#status').html( json.status );
  12875. * } );
  12876. *
  12877. * @example
  12878. * // Pre-process the data returned from the server
  12879. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  12880. * for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
  12881. * json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
  12882. * }
  12883. * // Note no return - manipulate the data directly in the JSON object.
  12884. * } );
  12885. */
  12886. /**
  12887. * Destroy event, fired when the DataTable is destroyed by calling fnDestroy
  12888. * or passing the bDestroy:true parameter in the initialisation object. This
  12889. * can be used to remove bound events, added DOM nodes, etc.
  12890. * @name DataTable#destroy.dt
  12891. * @event
  12892. * @param {event} e jQuery event object
  12893. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12894. */
  12895. /**
  12896. * Page length change event, fired when number of records to show on each
  12897. * page (the length) is changed.
  12898. * @name DataTable#length.dt
  12899. * @event
  12900. * @param {event} e jQuery event object
  12901. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12902. * @param {integer} len New length
  12903. */
  12904. /**
  12905. * Column sizing has changed.
  12906. * @name DataTable#column-sizing.dt
  12907. * @event
  12908. * @param {event} e jQuery event object
  12909. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12910. */
  12911. /**
  12912. * Column visibility has changed.
  12913. * @name DataTable#column-visibility.dt
  12914. * @event
  12915. * @param {event} e jQuery event object
  12916. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  12917. * @param {int} column Column index
  12918. * @param {bool} vis `false` if column now hidden, or `true` if visible
  12919. */
  12920. return $.fn.dataTable;
  12921. }));