layers-ui-table.js 523 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // identity function for calling harmony imports with the correct context
  37. /******/ __webpack_require__.i = function(value) { return value; };
  38. /******/
  39. /******/ // define getter function for harmony exports
  40. /******/ __webpack_require__.d = function(exports, name, getter) {
  41. /******/ if(!__webpack_require__.o(exports, name)) {
  42. /******/ Object.defineProperty(exports, name, {
  43. /******/ configurable: false,
  44. /******/ enumerable: true,
  45. /******/ get: getter
  46. /******/ });
  47. /******/ }
  48. /******/ };
  49. /******/
  50. /******/ // getDefaultExport function for compatibility with non-harmony modules
  51. /******/ __webpack_require__.n = function(module) {
  52. /******/ var getter = module && module.__esModule ?
  53. /******/ function getDefault() { return module['default']; } :
  54. /******/ function getModuleExports() { return module; };
  55. /******/ __webpack_require__.d(getter, 'a', getter);
  56. /******/ return getter;
  57. /******/ };
  58. /******/
  59. /******/ // Object.prototype.hasOwnProperty.call
  60. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  61. /******/
  62. /******/ // __webpack_public_path__
  63. /******/ __webpack_require__.p = "";
  64. /******/
  65. /******/ // Load entry module and return exports
  66. /******/ return __webpack_require__(__webpack_require__.s = 40);
  67. /******/ })
  68. /************************************************************************/
  69. /******/ ({
  70. /***/ 0:
  71. /***/ (function(module, exports, __webpack_require__) {
  72. "use strict";
  73. Object.defineProperty(exports, "__esModule", {
  74. value: true
  75. });
  76. var _jquery = __webpack_require__(1);
  77. var _jquery2 = _interopRequireDefault(_jquery);
  78. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  79. /**
  80. * --------------------------------------------------------------------------
  81. * Bootstrap (v4.0.0-beta): util.js
  82. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  83. * --------------------------------------------------------------------------
  84. */
  85. var Util = function () {
  86. /**
  87. * ------------------------------------------------------------------------
  88. * Private TransitionEnd Helpers
  89. * ------------------------------------------------------------------------
  90. */
  91. var transition = false;
  92. var MAX_UID = 1000000;
  93. var TransitionEndEvent = {
  94. WebkitTransition: 'webkitTransitionEnd',
  95. MozTransition: 'transitionend',
  96. OTransition: 'oTransitionEnd otransitionend',
  97. transition: 'transitionend'
  98. // shoutout AngusCroll (https://goo.gl/pxwQGp)
  99. };function toType(obj) {
  100. return {}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
  101. }
  102. function getSpecialTransitionEndEvent() {
  103. return {
  104. bindType: transition.end,
  105. delegateType: transition.end,
  106. handle: function handle(event) {
  107. if ((0, _jquery2.default)(event.target).is(this)) {
  108. return event.handleObj.handler.apply(this, arguments); // eslint-disable-line prefer-rest-params
  109. }
  110. return undefined; // eslint-disable-line no-undefined
  111. }
  112. };
  113. }
  114. function transitionEndTest() {
  115. if (window.QUnit) {
  116. return false;
  117. }
  118. var el = document.createElement('bootstrap');
  119. for (var name in TransitionEndEvent) {
  120. if (typeof el.style[name] !== 'undefined') {
  121. return {
  122. end: TransitionEndEvent[name]
  123. };
  124. }
  125. }
  126. return false;
  127. }
  128. function transitionEndEmulator(duration) {
  129. var _this = this;
  130. var called = false;
  131. (0, _jquery2.default)(this).one(Util.TRANSITION_END, function () {
  132. called = true;
  133. });
  134. setTimeout(function () {
  135. if (!called) {
  136. Util.triggerTransitionEnd(_this);
  137. }
  138. }, duration);
  139. return this;
  140. }
  141. function setTransitionEndSupport() {
  142. transition = transitionEndTest();
  143. _jquery2.default.fn.emulateTransitionEnd = transitionEndEmulator;
  144. if (Util.supportsTransitionEnd()) {
  145. _jquery2.default.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
  146. }
  147. }
  148. function parseOption(item) {
  149. if ('true' === item) {
  150. return true;
  151. } else if ('false' === item) {
  152. return false;
  153. } else if (!isNaN(item * 1)) {
  154. return parseFloat(item);
  155. } else {
  156. return item;
  157. }
  158. }
  159. /**
  160. * --------------------------------------------------------------------------
  161. * Public Util Api
  162. * --------------------------------------------------------------------------
  163. */
  164. var Util = {
  165. TRANSITION_END: 'bsTransitionEnd',
  166. getUID: function getUID(prefix) {
  167. do {
  168. // eslint-disable-next-line no-bitwise
  169. prefix += ~~(Math.random() * MAX_UID); // "~~" acts like a faster Math.floor() here
  170. } while (document.getElementById(prefix));
  171. return prefix;
  172. },
  173. getSelectorFromElement: function getSelectorFromElement(element) {
  174. var selector = element.getAttribute('data-target');
  175. if (!selector || selector === '#') {
  176. selector = element.getAttribute('href') || '';
  177. }
  178. try {
  179. var $selector = (0, _jquery2.default)(document).find(selector);
  180. return $selector.length > 0 ? selector : null;
  181. } catch (error) {
  182. return null;
  183. }
  184. },
  185. reflow: function reflow(element) {
  186. return element.offsetHeight;
  187. },
  188. triggerTransitionEnd: function triggerTransitionEnd(element) {
  189. (0, _jquery2.default)(element).trigger(transition.end);
  190. },
  191. supportsTransitionEnd: function supportsTransitionEnd() {
  192. return Boolean(transition);
  193. },
  194. isElement: function isElement(obj) {
  195. return (obj[0] || obj).nodeType;
  196. },
  197. typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
  198. for (var property in configTypes) {
  199. if (Object.prototype.hasOwnProperty.call(configTypes, property)) {
  200. var expectedTypes = configTypes[property];
  201. var value = config[property];
  202. var valueType = value && Util.isElement(value) ? 'element' : toType(value);
  203. if (!new RegExp(expectedTypes).test(valueType)) {
  204. throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".'));
  205. }
  206. }
  207. }
  208. },
  209. parseDataOptions: function parseDataOptions(dataOptions) {
  210. var options = [];
  211. var string = dataOptions.split(';');
  212. string.forEach(function (item, index) {
  213. var option = item.split(':');
  214. option = option.map(function (item) {
  215. return item.trim();
  216. });
  217. if (option[0]) {
  218. options[option[0]] = parseOption(option[1]);
  219. }
  220. });
  221. return options;
  222. }
  223. };
  224. setTransitionEndSupport();
  225. return Util;
  226. }(_jquery2.default);
  227. exports.default = Util;
  228. /***/ }),
  229. /***/ 1:
  230. /***/ (function(module, exports) {
  231. module.exports = jQuery;
  232. /***/ }),
  233. /***/ 10:
  234. /***/ (function(module, exports, __webpack_require__) {
  235. "use strict";
  236. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  237. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  238. /*! Responsive 2.2.0
  239. * 2014-2017 SpryMedia Ltd - datatables.net/license
  240. */
  241. /**
  242. * @summary Responsive
  243. * @description Responsive tables plug-in for DataTables
  244. * @version 2.2.0
  245. * @file dataTables.responsive.js
  246. * @autor ThurData <info@thurdata.ch>
  247. * @contact www.sprymedia.co.uk/contact
  248. * @copyright Copyright 2014-2017 SpryMedia Ltd.
  249. *
  250. * This source file is free software, available under the following license:
  251. * MIT license - http://datatables.net/license/mit
  252. *
  253. * This source file is distributed in the hope that it will be useful, but
  254. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  255. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  256. *
  257. * For details please refer to: http://www.datatables.net
  258. */
  259. (function (factory) {
  260. if (true) {
  261. // AMD
  262. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1), __webpack_require__(2)], __WEBPACK_AMD_DEFINE_RESULT__ = function ($) {
  263. return factory($, window, document);
  264. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  265. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  266. } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
  267. // CommonJS
  268. module.exports = function (root, $) {
  269. if (!root) {
  270. root = window;
  271. }
  272. if (!$ || !$.fn.dataTable) {
  273. $ = require('datatables.net')(root, $).$;
  274. }
  275. return factory($, root, root.document);
  276. };
  277. } else {
  278. // Browser
  279. factory(jQuery, window, document);
  280. }
  281. })(function ($, window, document, undefined) {
  282. 'use strict';
  283. var DataTable = $.fn.dataTable;
  284. /**
  285. * Responsive is a plug-in for the DataTables library that makes use of
  286. * DataTables' ability to change the visibility of columns, changing the
  287. * visibility of columns so the displayed columns fit into the table container.
  288. * The end result is that complex tables will be dynamically adjusted to fit
  289. * into the viewport, be it on a desktop, tablet or mobile browser.
  290. *
  291. * Responsive for DataTables has two modes of operation, which can used
  292. * individually or combined:
  293. *
  294. * * Class name based control - columns assigned class names that match the
  295. * breakpoint logic can be shown / hidden as required for each breakpoint.
  296. * * Automatic control - columns are automatically hidden when there is no
  297. * room left to display them. Columns removed from the right.
  298. *
  299. * In additional to column visibility control, Responsive also has built into
  300. * options to use DataTables' child row display to show / hide the information
  301. * from the table that has been hidden. There are also two modes of operation
  302. * for this child row display:
  303. *
  304. * * Inline - when the control element that the user can use to show / hide
  305. * child rows is displayed inside the first column of the table.
  306. * * Column - where a whole column is dedicated to be the show / hide control.
  307. *
  308. * Initialisation of Responsive is performed by:
  309. *
  310. * * Adding the class `responsive` or `dt-responsive` to the table. In this case
  311. * Responsive will automatically be initialised with the default configuration
  312. * options when the DataTable is created.
  313. * * Using the `responsive` option in the DataTables configuration options. This
  314. * can also be used to specify the configuration options, or simply set to
  315. * `true` to use the defaults.
  316. *
  317. * @class
  318. * @param {object} settings DataTables settings object for the host table
  319. * @param {object} [opts] Configuration options
  320. * @requires jQuery 1.7+
  321. * @requires DataTables 1.10.3+
  322. *
  323. * @example
  324. * $('#example').DataTable( {
  325. * responsive: true
  326. * } );
  327. * } );
  328. */
  329. var Responsive = function Responsive(settings, opts) {
  330. // Sanity check that we are using DataTables 1.10 or newer
  331. if (!DataTable.versionCheck || !DataTable.versionCheck('1.10.3')) {
  332. throw 'DataTables Responsive requires DataTables 1.10.3 or newer';
  333. }
  334. this.s = {
  335. dt: new DataTable.Api(settings),
  336. columns: [],
  337. current: []
  338. };
  339. // Check if responsive has already been initialised on this table
  340. if (this.s.dt.settings()[0].responsive) {
  341. return;
  342. }
  343. // details is an object, but for simplicity the user can give it as a string
  344. // or a boolean
  345. if (opts && typeof opts.details === 'string') {
  346. opts.details = { type: opts.details };
  347. } else if (opts && opts.details === false) {
  348. opts.details = { type: false };
  349. } else if (opts && opts.details === true) {
  350. opts.details = { type: 'inline' };
  351. }
  352. this.c = $.extend(true, {}, Responsive.defaults, DataTable.defaults.responsive, opts);
  353. settings.responsive = this;
  354. this._constructor();
  355. };
  356. $.extend(Responsive.prototype, {
  357. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  358. * Constructor
  359. */
  360. /**
  361. * Initialise the Responsive instance
  362. *
  363. * @private
  364. */
  365. _constructor: function _constructor() {
  366. var that = this;
  367. var dt = this.s.dt;
  368. var dtPrivateSettings = dt.settings()[0];
  369. var oldWindowWidth = $(window).width();
  370. dt.settings()[0]._responsive = this;
  371. // Use DataTables' throttle function to avoid processor thrashing on
  372. // resize
  373. $(window).on('resize.dtr orientationchange.dtr', DataTable.util.throttle(function () {
  374. // iOS has a bug whereby resize can fire when only scrolling
  375. // See: http://stackoverflow.com/questions/8898412
  376. var width = $(window).width();
  377. if (width !== oldWindowWidth) {
  378. that._resize();
  379. oldWindowWidth = width;
  380. }
  381. }));
  382. // DataTables doesn't currently trigger an event when a row is added, so
  383. // we need to hook into its private API to enforce the hidden rows when
  384. // new data is added
  385. dtPrivateSettings.oApi._fnCallbackReg(dtPrivateSettings, 'aoRowCreatedCallback', function (tr, data, idx) {
  386. if ($.inArray(false, that.s.current) !== -1) {
  387. $('>td, >th', tr).each(function (i) {
  388. var idx = dt.column.index('toData', i);
  389. if (that.s.current[idx] === false) {
  390. $(this).css('display', 'none');
  391. }
  392. });
  393. }
  394. });
  395. // Destroy event handler
  396. dt.on('destroy.dtr', function () {
  397. dt.off('.dtr');
  398. $(dt.table().body()).off('.dtr');
  399. $(window).off('resize.dtr orientationchange.dtr');
  400. // Restore the columns that we've hidden
  401. $.each(that.s.current, function (i, val) {
  402. if (val === false) {
  403. that._setColumnVis(i, true);
  404. }
  405. });
  406. });
  407. // Reorder the breakpoints array here in case they have been added out
  408. // of order
  409. this.c.breakpoints.sort(function (a, b) {
  410. return a.width < b.width ? 1 : a.width > b.width ? -1 : 0;
  411. });
  412. this._classLogic();
  413. this._resizeAuto();
  414. // Details handler
  415. var details = this.c.details;
  416. if (details.type !== false) {
  417. that._detailsInit();
  418. // DataTables will trigger this event on every column it shows and
  419. // hides individually
  420. dt.on('column-visibility.dtr', function (e, ctx, col, vis) {
  421. that._classLogic();
  422. that._resizeAuto();
  423. that._resize();
  424. });
  425. // Redraw the details box on each draw which will happen if the data
  426. // has changed. This is used until DataTables implements a native
  427. // `updated` event for rows
  428. dt.on('draw.dtr', function () {
  429. that._redrawChildren();
  430. });
  431. $(dt.table().node()).addClass('dtr-' + details.type);
  432. }
  433. dt.on('column-reorder.dtr', function (e, settings, details) {
  434. that._classLogic();
  435. that._resizeAuto();
  436. that._resize();
  437. });
  438. // Change in column sizes means we need to calc
  439. dt.on('column-sizing.dtr', function () {
  440. that._resizeAuto();
  441. that._resize();
  442. });
  443. // On Ajax reload we want to reopen any child rows which are displayed
  444. // by responsive
  445. dt.on('preXhr.dtr', function () {
  446. var rowIds = [];
  447. dt.rows().every(function () {
  448. if (this.child.isShown()) {
  449. rowIds.push(this.id(true));
  450. }
  451. });
  452. dt.one('draw.dtr', function () {
  453. dt.rows(rowIds).every(function () {
  454. that._detailsDisplay(this, false);
  455. });
  456. });
  457. });
  458. dt.on('init.dtr', function (e, settings, details) {
  459. that._resizeAuto();
  460. that._resize();
  461. // If columns were hidden, then DataTables needs to adjust the
  462. // column sizing
  463. if ($.inArray(false, that.s.current)) {
  464. dt.columns.adjust();
  465. }
  466. });
  467. // First pass - draw the table for the current viewport size
  468. this._resize();
  469. },
  470. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  471. * Private methods
  472. */
  473. /**
  474. * Calculate the visibility for the columns in a table for a given
  475. * breakpoint. The result is pre-determined based on the class logic if
  476. * class names are used to control all columns, but the width of the table
  477. * is also used if there are columns which are to be automatically shown
  478. * and hidden.
  479. *
  480. * @param {string} breakpoint Breakpoint name to use for the calculation
  481. * @return {array} Array of boolean values initiating the visibility of each
  482. * column.
  483. * @private
  484. */
  485. _columnsVisiblity: function _columnsVisiblity(breakpoint) {
  486. var dt = this.s.dt;
  487. var columns = this.s.columns;
  488. var i, ien;
  489. // Create an array that defines the column ordering based first on the
  490. // column's priority, and secondly the column index. This allows the
  491. // columns to be removed from the right if the priority matches
  492. var order = columns.map(function (col, idx) {
  493. return {
  494. columnIdx: idx,
  495. priority: col.priority
  496. };
  497. }).sort(function (a, b) {
  498. if (a.priority !== b.priority) {
  499. return a.priority - b.priority;
  500. }
  501. return a.columnIdx - b.columnIdx;
  502. });
  503. // Class logic - determine which columns are in this breakpoint based
  504. // on the classes. If no class control (i.e. `auto`) then `-` is used
  505. // to indicate this to the rest of the function
  506. var display = $.map(columns, function (col) {
  507. return col.auto && col.minWidth === null ? false : col.auto === true ? '-' : $.inArray(breakpoint, col.includeIn) !== -1;
  508. });
  509. // Auto column control - first pass: how much width is taken by the
  510. // ones that must be included from the non-auto columns
  511. var requiredWidth = 0;
  512. for (i = 0, ien = display.length; i < ien; i++) {
  513. if (display[i] === true) {
  514. requiredWidth += columns[i].minWidth;
  515. }
  516. }
  517. // Second pass, use up any remaining width for other columns. For
  518. // scrolling tables we need to subtract the width of the scrollbar. It
  519. // may not be requires which makes this sub-optimal, but it would
  520. // require another full redraw to make complete use of those extra few
  521. // pixels
  522. var scrolling = dt.settings()[0].oScroll;
  523. var bar = scrolling.sY || scrolling.sX ? scrolling.iBarWidth : 0;
  524. var widthAvailable = dt.table().container().offsetWidth - bar;
  525. var usedWidth = widthAvailable - requiredWidth;
  526. // Control column needs to always be included. This makes it sub-
  527. // optimal in terms of using the available with, but to stop layout
  528. // thrashing or overflow. Also we need to account for the control column
  529. // width first so we know how much width is available for the other
  530. // columns, since the control column might not be the first one shown
  531. for (i = 0, ien = display.length; i < ien; i++) {
  532. if (columns[i].control) {
  533. usedWidth -= columns[i].minWidth;
  534. }
  535. }
  536. // Allow columns to be shown (counting by priority and then right to
  537. // left) until we run out of room
  538. var empty = false;
  539. for (i = 0, ien = order.length; i < ien; i++) {
  540. var colIdx = order[i].columnIdx;
  541. if (display[colIdx] === '-' && !columns[colIdx].control && columns[colIdx].minWidth) {
  542. // Once we've found a column that won't fit we don't let any
  543. // others display either, or columns might disappear in the
  544. // middle of the table
  545. if (empty || usedWidth - columns[colIdx].minWidth < 0) {
  546. empty = true;
  547. display[colIdx] = false;
  548. } else {
  549. display[colIdx] = true;
  550. }
  551. usedWidth -= columns[colIdx].minWidth;
  552. }
  553. }
  554. // Determine if the 'control' column should be shown (if there is one).
  555. // This is the case when there is a hidden column (that is not the
  556. // control column). The two loops look inefficient here, but they are
  557. // trivial and will fly through. We need to know the outcome from the
  558. // first , before the action in the second can be taken
  559. var showControl = false;
  560. for (i = 0, ien = columns.length; i < ien; i++) {
  561. if (!columns[i].control && !columns[i].never && !display[i]) {
  562. showControl = true;
  563. break;
  564. }
  565. }
  566. for (i = 0, ien = columns.length; i < ien; i++) {
  567. if (columns[i].control) {
  568. display[i] = showControl;
  569. }
  570. }
  571. // Finally we need to make sure that there is at least one column that
  572. // is visible
  573. if ($.inArray(true, display) === -1) {
  574. display[0] = true;
  575. }
  576. return display;
  577. },
  578. /**
  579. * Create the internal `columns` array with information about the columns
  580. * for the table. This includes determining which breakpoints the column
  581. * will appear in, based upon class names in the column, which makes up the
  582. * vast majority of this method.
  583. *
  584. * @private
  585. */
  586. _classLogic: function _classLogic() {
  587. var that = this;
  588. var calc = {};
  589. var breakpoints = this.c.breakpoints;
  590. var dt = this.s.dt;
  591. var columns = dt.columns().eq(0).map(function (i) {
  592. var column = this.column(i);
  593. var className = column.header().className;
  594. var priority = dt.settings()[0].aoColumns[i].responsivePriority;
  595. if (priority === undefined) {
  596. var dataPriority = $(column.header()).data('priority');
  597. priority = dataPriority !== undefined ? dataPriority * 1 : 10000;
  598. }
  599. return {
  600. className: className,
  601. includeIn: [],
  602. auto: false,
  603. control: false,
  604. never: className.match(/\bnever\b/) ? true : false,
  605. priority: priority
  606. };
  607. });
  608. // Simply add a breakpoint to `includeIn` array, ensuring that there are
  609. // no duplicates
  610. var add = function add(colIdx, name) {
  611. var includeIn = columns[colIdx].includeIn;
  612. if ($.inArray(name, includeIn) === -1) {
  613. includeIn.push(name);
  614. }
  615. };
  616. var column = function column(colIdx, name, operator, matched) {
  617. var size, i, ien;
  618. if (!operator) {
  619. columns[colIdx].includeIn.push(name);
  620. } else if (operator === 'max-') {
  621. // Add this breakpoint and all smaller
  622. size = that._find(name).width;
  623. for (i = 0, ien = breakpoints.length; i < ien; i++) {
  624. if (breakpoints[i].width <= size) {
  625. add(colIdx, breakpoints[i].name);
  626. }
  627. }
  628. } else if (operator === 'min-') {
  629. // Add this breakpoint and all larger
  630. size = that._find(name).width;
  631. for (i = 0, ien = breakpoints.length; i < ien; i++) {
  632. if (breakpoints[i].width >= size) {
  633. add(colIdx, breakpoints[i].name);
  634. }
  635. }
  636. } else if (operator === 'not-') {
  637. // Add all but this breakpoint
  638. for (i = 0, ien = breakpoints.length; i < ien; i++) {
  639. if (breakpoints[i].name.indexOf(matched) === -1) {
  640. add(colIdx, breakpoints[i].name);
  641. }
  642. }
  643. }
  644. };
  645. // Loop over each column and determine if it has a responsive control
  646. // class
  647. columns.each(function (col, i) {
  648. var classNames = col.className.split(' ');
  649. var hasClass = false;
  650. // Split the class name up so multiple rules can be applied if needed
  651. for (var k = 0, ken = classNames.length; k < ken; k++) {
  652. var className = $.trim(classNames[k]);
  653. if (className === 'all') {
  654. // Include in all
  655. hasClass = true;
  656. col.includeIn = $.map(breakpoints, function (a) {
  657. return a.name;
  658. });
  659. return;
  660. } else if (className === 'none' || col.never) {
  661. // Include in none (default) and no auto
  662. hasClass = true;
  663. return;
  664. } else if (className === 'control') {
  665. // Special column that is only visible, when one of the other
  666. // columns is hidden. This is used for the details control
  667. hasClass = true;
  668. col.control = true;
  669. return;
  670. }
  671. $.each(breakpoints, function (j, breakpoint) {
  672. // Does this column have a class that matches this breakpoint?
  673. var brokenPoint = breakpoint.name.split('-');
  674. var re = new RegExp('(min\\-|max\\-|not\\-)?(' + brokenPoint[0] + ')(\\-[_a-zA-Z0-9])?');
  675. var match = className.match(re);
  676. if (match) {
  677. hasClass = true;
  678. if (match[2] === brokenPoint[0] && match[3] === '-' + brokenPoint[1]) {
  679. // Class name matches breakpoint name fully
  680. column(i, breakpoint.name, match[1], match[2] + match[3]);
  681. } else if (match[2] === brokenPoint[0] && !match[3]) {
  682. // Class name matched primary breakpoint name with no qualifier
  683. column(i, breakpoint.name, match[1], match[2]);
  684. }
  685. }
  686. });
  687. }
  688. // If there was no control class, then automatic sizing is used
  689. if (!hasClass) {
  690. col.auto = true;
  691. }
  692. });
  693. this.s.columns = columns;
  694. },
  695. /**
  696. * Show the details for the child row
  697. *
  698. * @param {DataTables.Api} row API instance for the row
  699. * @param {boolean} update Update flag
  700. * @private
  701. */
  702. _detailsDisplay: function _detailsDisplay(row, update) {
  703. var that = this;
  704. var dt = this.s.dt;
  705. var details = this.c.details;
  706. if (details && details.type !== false) {
  707. var res = details.display(row, update, function () {
  708. return details.renderer(dt, row[0], that._detailsObj(row[0]));
  709. });
  710. if (res === true || res === false) {
  711. $(dt.table().node()).triggerHandler('responsive-display.dt', [dt, row, res, update]);
  712. }
  713. }
  714. },
  715. /**
  716. * Initialisation for the details handler
  717. *
  718. * @private
  719. */
  720. _detailsInit: function _detailsInit() {
  721. var that = this;
  722. var dt = this.s.dt;
  723. var details = this.c.details;
  724. // The inline type always uses the first child as the target
  725. if (details.type === 'inline') {
  726. details.target = 'td:first-child, th:first-child';
  727. }
  728. // Keyboard accessibility
  729. dt.on('draw.dtr', function () {
  730. that._tabIndexes();
  731. });
  732. that._tabIndexes(); // Initial draw has already happened
  733. $(dt.table().body()).on('keyup.dtr', 'td, th', function (e) {
  734. if (e.keyCode === 13 && $(this).data('dtr-keyboard')) {
  735. $(this).click();
  736. }
  737. });
  738. // type.target can be a string jQuery selector or a column index
  739. var target = details.target;
  740. var selector = typeof target === 'string' ? target : 'td, th';
  741. // Click handler to show / hide the details rows when they are available
  742. $(dt.table().body()).on('click.dtr mousedown.dtr mouseup.dtr', selector, function (e) {
  743. // If the table is not collapsed (i.e. there is no hidden columns)
  744. // then take no action
  745. if (!$(dt.table().node()).hasClass('collapsed')) {
  746. return;
  747. }
  748. // Check that the row is actually a DataTable's controlled node
  749. if ($.inArray($(this).closest('tr').get(0), dt.rows().nodes().toArray()) === -1) {
  750. return;
  751. }
  752. // For column index, we determine if we should act or not in the
  753. // handler - otherwise it is already okay
  754. if (typeof target === 'number') {
  755. var targetIdx = target < 0 ? dt.columns().eq(0).length + target : target;
  756. if (dt.cell(this).index().column !== targetIdx) {
  757. return;
  758. }
  759. }
  760. // $().closest() includes itself in its check
  761. var row = dt.row($(this).closest('tr'));
  762. // Check event type to do an action
  763. if (e.type === 'click') {
  764. // The renderer is given as a function so the caller can execute it
  765. // only when they need (i.e. if hiding there is no point is running
  766. // the renderer)
  767. that._detailsDisplay(row, false);
  768. } else if (e.type === 'mousedown') {
  769. // For mouse users, prevent the focus ring from showing
  770. $(this).css('outline', 'none');
  771. } else if (e.type === 'mouseup') {
  772. // And then re-allow at the end of the click
  773. $(this).blur().css('outline', '');
  774. }
  775. });
  776. },
  777. /**
  778. * Get the details to pass to a renderer for a row
  779. * @param {int} rowIdx Row index
  780. * @private
  781. */
  782. _detailsObj: function _detailsObj(rowIdx) {
  783. var that = this;
  784. var dt = this.s.dt;
  785. return $.map(this.s.columns, function (col, i) {
  786. // Never and control columns should not be passed to the renderer
  787. if (col.never || col.control) {
  788. return;
  789. }
  790. return {
  791. title: dt.settings()[0].aoColumns[i].sTitle,
  792. data: dt.cell(rowIdx, i).render(that.c.orthogonal),
  793. hidden: dt.column(i).visible() && !that.s.current[i],
  794. columnIndex: i,
  795. rowIndex: rowIdx
  796. };
  797. });
  798. },
  799. /**
  800. * Find a breakpoint object from a name
  801. *
  802. * @param {string} name Breakpoint name to find
  803. * @return {object} Breakpoint description object
  804. * @private
  805. */
  806. _find: function _find(name) {
  807. var breakpoints = this.c.breakpoints;
  808. for (var i = 0, ien = breakpoints.length; i < ien; i++) {
  809. if (breakpoints[i].name === name) {
  810. return breakpoints[i];
  811. }
  812. }
  813. },
  814. /**
  815. * Re-create the contents of the child rows as the display has changed in
  816. * some way.
  817. *
  818. * @private
  819. */
  820. _redrawChildren: function _redrawChildren() {
  821. var that = this;
  822. var dt = this.s.dt;
  823. dt.rows({ page: 'current' }).iterator('row', function (settings, idx) {
  824. var row = dt.row(idx);
  825. that._detailsDisplay(dt.row(idx), true);
  826. });
  827. },
  828. /**
  829. * Alter the table display for a resized viewport. This involves first
  830. * determining what breakpoint the window currently is in, getting the
  831. * column visibilities to apply and then setting them.
  832. *
  833. * @private
  834. */
  835. _resize: function _resize() {
  836. var that = this;
  837. var dt = this.s.dt;
  838. var width = $(window).width();
  839. var breakpoints = this.c.breakpoints;
  840. var breakpoint = breakpoints[0].name;
  841. var columns = this.s.columns;
  842. var i, ien;
  843. var oldVis = this.s.current.slice();
  844. // Determine what breakpoint we are currently at
  845. for (i = breakpoints.length - 1; i >= 0; i--) {
  846. if (width <= breakpoints[i].width) {
  847. breakpoint = breakpoints[i].name;
  848. break;
  849. }
  850. }
  851. // Show the columns for that break point
  852. var columnsVis = this._columnsVisiblity(breakpoint);
  853. this.s.current = columnsVis;
  854. // Set the class before the column visibility is changed so event
  855. // listeners know what the state is. Need to determine if there are
  856. // any columns that are not visible but can be shown
  857. var collapsedClass = false;
  858. for (i = 0, ien = columns.length; i < ien; i++) {
  859. if (columnsVis[i] === false && !columns[i].never && !columns[i].control) {
  860. collapsedClass = true;
  861. break;
  862. }
  863. }
  864. $(dt.table().node()).toggleClass('collapsed', collapsedClass);
  865. var changed = false;
  866. dt.columns().eq(0).each(function (colIdx, i) {
  867. if (columnsVis[i] !== oldVis[i]) {
  868. changed = true;
  869. that._setColumnVis(colIdx, columnsVis[i]);
  870. }
  871. });
  872. if (changed) {
  873. this._redrawChildren();
  874. // Inform listeners of the change
  875. $(dt.table().node()).trigger('responsive-resize.dt', [dt, this.s.current]);
  876. // If no records, update the "No records" display element
  877. if (dt.page.info().recordsDisplay === 0) {
  878. dt.draw();
  879. }
  880. }
  881. },
  882. /**
  883. * Determine the width of each column in the table so the auto column hiding
  884. * has that information to work with. This method is never going to be 100%
  885. * perfect since column widths can change slightly per page, but without
  886. * seriously compromising performance this is quite effective.
  887. *
  888. * @private
  889. */
  890. _resizeAuto: function _resizeAuto() {
  891. var dt = this.s.dt;
  892. var columns = this.s.columns;
  893. // Are we allowed to do auto sizing?
  894. if (!this.c.auto) {
  895. return;
  896. }
  897. // Are there any columns that actually need auto-sizing, or do they all
  898. // have classes defined
  899. if ($.inArray(true, $.map(columns, function (c) {
  900. return c.auto;
  901. })) === -1) {
  902. return;
  903. }
  904. // Need to restore all children. They will be reinstated by a re-render
  905. if (!$.isEmptyObject(_childNodeStore)) {
  906. $.each(_childNodeStore, function (key) {
  907. var idx = key.split('-');
  908. _childNodesRestore(dt, idx[0] * 1, idx[1] * 1);
  909. });
  910. }
  911. // Clone the table with the current data in it
  912. var tableWidth = dt.table().node().offsetWidth;
  913. var columnWidths = dt.columns;
  914. var clonedTable = dt.table().node().cloneNode(false);
  915. var clonedHeader = $(dt.table().header().cloneNode(false)).appendTo(clonedTable);
  916. var clonedBody = $(dt.table().body()).clone(false, false).empty().appendTo(clonedTable); // use jQuery because of IE8
  917. // Header
  918. var headerCells = dt.columns().header().filter(function (idx) {
  919. return dt.column(idx).visible();
  920. }).to$().clone(false).css('display', 'table-cell');
  921. // Body rows - we don't need to take account of DataTables' column
  922. // visibility since we implement our own here (hence the `display` set)
  923. $(clonedBody).append($(dt.rows({ page: 'current' }).nodes()).clone(false)).find('th, td').css('display', '');
  924. // Footer
  925. var footer = dt.table().footer();
  926. if (footer) {
  927. var clonedFooter = $(footer.cloneNode(false)).appendTo(clonedTable);
  928. var footerCells = dt.columns().footer().filter(function (idx) {
  929. return dt.column(idx).visible();
  930. }).to$().clone(false).css('display', 'table-cell');
  931. $('<tr/>').append(footerCells).appendTo(clonedFooter);
  932. }
  933. $('<tr/>').append(headerCells).appendTo(clonedHeader);
  934. // In the inline case extra padding is applied to the first column to
  935. // give space for the show / hide icon. We need to use this in the
  936. // calculation
  937. if (this.c.details.type === 'inline') {
  938. $(clonedTable).addClass('dtr-inline collapsed');
  939. }
  940. // It is unsafe to insert elements with the same name into the DOM
  941. // multiple times. For example, cloning and inserting a checked radio
  942. // clears the chcecked state of the original radio.
  943. $(clonedTable).find('[name]').removeAttr('name');
  944. var inserted = $('<div/>').css({
  945. width: 1,
  946. height: 1,
  947. overflow: 'hidden',
  948. clear: 'both'
  949. }).append(clonedTable);
  950. inserted.insertBefore(dt.table().node());
  951. // The cloned header now contains the smallest that each column can be
  952. headerCells.each(function (i) {
  953. var idx = dt.column.index('fromVisible', i);
  954. columns[idx].minWidth = this.offsetWidth || 0;
  955. });
  956. inserted.remove();
  957. },
  958. /**
  959. * Set a column's visibility.
  960. *
  961. * We don't use DataTables' column visibility controls in order to ensure
  962. * that column visibility can Responsive can no-exist. Since only IE8+ is
  963. * supported (and all evergreen browsers of course) the control of the
  964. * display attribute works well.
  965. *
  966. * @param {integer} col Column index
  967. * @param {boolean} showHide Show or hide (true or false)
  968. * @private
  969. */
  970. _setColumnVis: function _setColumnVis(col, showHide) {
  971. var dt = this.s.dt;
  972. var display = showHide ? '' : 'none'; // empty string will remove the attr
  973. $(dt.column(col).header()).css('display', display);
  974. $(dt.column(col).footer()).css('display', display);
  975. dt.column(col).nodes().to$().css('display', display);
  976. // If the are child nodes stored, we might need to reinsert them
  977. if (!$.isEmptyObject(_childNodeStore)) {
  978. dt.cells(null, col).indexes().each(function (idx) {
  979. _childNodesRestore(dt, idx.row, idx.column);
  980. });
  981. }
  982. },
  983. /**
  984. * Update the cell tab indexes for keyboard accessibility. This is called on
  985. * every table draw - that is potentially inefficient, but also the least
  986. * complex option given that column visibility can change on the fly. Its a
  987. * shame user-focus was removed from CSS 3 UI, as it would have solved this
  988. * issue with a single CSS statement.
  989. *
  990. * @private
  991. */
  992. _tabIndexes: function _tabIndexes() {
  993. var dt = this.s.dt;
  994. var cells = dt.cells({ page: 'current' }).nodes().to$();
  995. var ctx = dt.settings()[0];
  996. var target = this.c.details.target;
  997. cells.filter('[data-dtr-keyboard]').removeData('[data-dtr-keyboard]');
  998. var selector = typeof target === 'number' ? ':eq(' + target + ')' : target;
  999. // This is a bit of a hack - we need to limit the selected nodes to just
  1000. // those of this table
  1001. if (selector === 'td:first-child, th:first-child') {
  1002. selector = '>td:first-child, >th:first-child';
  1003. }
  1004. $(selector, dt.rows({ page: 'current' }).nodes()).attr('tabIndex', ctx.iTabIndex).data('dtr-keyboard', 1);
  1005. }
  1006. });
  1007. /**
  1008. * List of default breakpoints. Each item in the array is an object with two
  1009. * properties:
  1010. *
  1011. * * `name` - the breakpoint name.
  1012. * * `width` - the breakpoint width
  1013. *
  1014. * @name Responsive.breakpoints
  1015. * @static
  1016. */
  1017. Responsive.breakpoints = [{ name: 'desktop', width: Infinity }, { name: 'tablet-l', width: 1024 }, { name: 'tablet-p', width: 768 }, { name: 'mobile-l', width: 480 }, { name: 'mobile-p', width: 320 }];
  1018. /**
  1019. * Display methods - functions which define how the hidden data should be shown
  1020. * in the table.
  1021. *
  1022. * @namespace
  1023. * @name Responsive.defaults
  1024. * @static
  1025. */
  1026. Responsive.display = {
  1027. childRow: function childRow(row, update, render) {
  1028. if (update) {
  1029. if ($(row.node()).hasClass('parent')) {
  1030. row.child(render(), 'child').show();
  1031. return true;
  1032. }
  1033. } else {
  1034. if (!row.child.isShown()) {
  1035. row.child(render(), 'child').show();
  1036. $(row.node()).addClass('parent');
  1037. return true;
  1038. } else {
  1039. row.child(false);
  1040. $(row.node()).removeClass('parent');
  1041. return false;
  1042. }
  1043. }
  1044. },
  1045. childRowImmediate: function childRowImmediate(row, update, render) {
  1046. if (!update && row.child.isShown() || !row.responsive.hasHidden()) {
  1047. // User interaction and the row is show, or nothing to show
  1048. row.child(false);
  1049. $(row.node()).removeClass('parent');
  1050. return false;
  1051. } else {
  1052. // Display
  1053. row.child(render(), 'child').show();
  1054. $(row.node()).addClass('parent');
  1055. return true;
  1056. }
  1057. },
  1058. // This is a wrapper so the modal options for Bootstrap and jQuery UI can
  1059. // have options passed into them. This specific one doesn't need to be a
  1060. // function but it is for consistency in the `modal` name
  1061. modal: function modal(options) {
  1062. return function (row, update, render) {
  1063. if (!update) {
  1064. // Show a modal
  1065. var close = function close() {
  1066. modal.remove(); // will tidy events for us
  1067. $(document).off('keypress.dtr');
  1068. };
  1069. var modal = $('<div class="dtr-modal"/>').append($('<div class="dtr-modal-display"/>').append($('<div class="dtr-modal-content"/>').append(render())).append($('<div class="dtr-modal-close">&times;</div>').click(function () {
  1070. close();
  1071. }))).append($('<div class="dtr-modal-background"/>').click(function () {
  1072. close();
  1073. })).appendTo('body');
  1074. $(document).on('keyup.dtr', function (e) {
  1075. if (e.keyCode === 27) {
  1076. e.stopPropagation();
  1077. close();
  1078. }
  1079. });
  1080. } else {
  1081. $('div.dtr-modal-content').empty().append(render());
  1082. }
  1083. if (options && options.header) {
  1084. $('div.dtr-modal-content').prepend('<h2>' + options.header(row) + '</h2>');
  1085. }
  1086. };
  1087. }
  1088. };
  1089. var _childNodeStore = {};
  1090. function _childNodes(dt, row, col) {
  1091. var name = row + '-' + col;
  1092. if (_childNodeStore[name]) {
  1093. return _childNodeStore[name];
  1094. }
  1095. // https://jsperf.com/childnodes-array-slice-vs-loop
  1096. var nodes = [];
  1097. var children = dt.cell(row, col).node().childNodes;
  1098. for (var i = 0, ien = children.length; i < ien; i++) {
  1099. nodes.push(children[i]);
  1100. }
  1101. _childNodeStore[name] = nodes;
  1102. return nodes;
  1103. }
  1104. function _childNodesRestore(dt, row, col) {
  1105. var name = row + '-' + col;
  1106. if (!_childNodeStore[name]) {
  1107. return;
  1108. }
  1109. var node = dt.cell(row, col).node();
  1110. var store = _childNodeStore[name];
  1111. var parent = store[0].parentNode;
  1112. var parentChildren = parent.childNodes;
  1113. var a = [];
  1114. for (var i = 0, ien = parentChildren.length; i < ien; i++) {
  1115. a.push(parentChildren[i]);
  1116. }
  1117. for (var j = 0, jen = a.length; j < jen; j++) {
  1118. node.appendChild(a[j]);
  1119. }
  1120. _childNodeStore[name] = undefined;
  1121. }
  1122. /**
  1123. * Display methods - functions which define how the hidden data should be shown
  1124. * in the table.
  1125. *
  1126. * @namespace
  1127. * @name Responsive.defaults
  1128. * @static
  1129. */
  1130. Responsive.renderer = {
  1131. listHiddenNodes: function listHiddenNodes() {
  1132. return function (api, rowIdx, columns) {
  1133. var ul = $('<ul data-dtr-index="' + rowIdx + '" class="dtr-details"/>');
  1134. var found = false;
  1135. var data = $.each(columns, function (i, col) {
  1136. if (col.hidden) {
  1137. $('<li data-dtr-index="' + col.columnIndex + '" data-dt-row="' + col.rowIndex + '" data-dt-column="' + col.columnIndex + '">' + '<span class="dtr-title">' + col.title + '</span> ' + '</li>').append($('<span class="dtr-data"/>').append(_childNodes(api, col.rowIndex, col.columnIndex))) // api.cell( col.rowIndex, col.columnIndex ).node().childNodes ) )
  1138. .appendTo(ul);
  1139. found = true;
  1140. }
  1141. });
  1142. return found ? ul : false;
  1143. };
  1144. },
  1145. listHidden: function listHidden() {
  1146. return function (api, rowIdx, columns) {
  1147. var data = $.map(columns, function (col) {
  1148. return col.hidden ? '<li data-dtr-index="' + col.columnIndex + '" data-dt-row="' + col.rowIndex + '" data-dt-column="' + col.columnIndex + '">' + '<span class="dtr-title">' + col.title + '</span> ' + '<span class="dtr-data">' + col.data + '</span>' + '</li>' : '';
  1149. }).join('');
  1150. return data ? $('<ul data-dtr-index="' + rowIdx + '" class="dtr-details"/>').append(data) : false;
  1151. };
  1152. },
  1153. tableAll: function tableAll(options) {
  1154. options = $.extend({
  1155. tableClass: ''
  1156. }, options);
  1157. return function (api, rowIdx, columns) {
  1158. var data = $.map(columns, function (col) {
  1159. return '<tr data-dt-row="' + col.rowIndex + '" data-dt-column="' + col.columnIndex + '">' + '<td>' + col.title + ':' + '</td> ' + '<td>' + col.data + '</td>' + '</tr>';
  1160. }).join('');
  1161. return $('<table class="' + options.tableClass + ' dtr-details" width="100%"/>').append(data);
  1162. };
  1163. }
  1164. };
  1165. /**
  1166. * Responsive default settings for initialisation
  1167. *
  1168. * @namespace
  1169. * @name Responsive.defaults
  1170. * @static
  1171. */
  1172. Responsive.defaults = {
  1173. /**
  1174. * List of breakpoints for the instance. Note that this means that each
  1175. * instance can have its own breakpoints. Additionally, the breakpoints
  1176. * cannot be changed once an instance has been creased.
  1177. *
  1178. * @type {Array}
  1179. * @default Takes the value of `Responsive.breakpoints`
  1180. */
  1181. breakpoints: Responsive.breakpoints,
  1182. /**
  1183. * Enable / disable auto hiding calculations. It can help to increase
  1184. * performance slightly if you disable this option, but all columns would
  1185. * need to have breakpoint classes assigned to them
  1186. *
  1187. * @type {Boolean}
  1188. * @default `true`
  1189. */
  1190. auto: true,
  1191. /**
  1192. * Details control. If given as a string value, the `type` property of the
  1193. * default object is set to that value, and the defaults used for the rest
  1194. * of the object - this is for ease of implementation.
  1195. *
  1196. * The object consists of the following properties:
  1197. *
  1198. * * `display` - A function that is used to show and hide the hidden details
  1199. * * `renderer` - function that is called for display of the child row data.
  1200. * The default function will show the data from the hidden columns
  1201. * * `target` - Used as the selector for what objects to attach the child
  1202. * open / close to
  1203. * * `type` - `false` to disable the details display, `inline` or `column`
  1204. * for the two control types
  1205. *
  1206. * @type {Object|string}
  1207. */
  1208. details: {
  1209. display: Responsive.display.childRow,
  1210. renderer: Responsive.renderer.listHidden(),
  1211. target: 0,
  1212. type: 'inline'
  1213. },
  1214. /**
  1215. * Orthogonal data request option. This is used to define the data type
  1216. * requested when Responsive gets the data to show in the child row.
  1217. *
  1218. * @type {String}
  1219. */
  1220. orthogonal: 'display'
  1221. };
  1222. /*
  1223. * API
  1224. */
  1225. var Api = $.fn.dataTable.Api;
  1226. // Doesn't do anything - work around for a bug in DT... Not documented
  1227. Api.register('responsive()', function () {
  1228. return this;
  1229. });
  1230. Api.register('responsive.index()', function (li) {
  1231. li = $(li);
  1232. return {
  1233. column: li.data('dtr-index'),
  1234. row: li.parent().data('dtr-index')
  1235. };
  1236. });
  1237. Api.register('responsive.rebuild()', function () {
  1238. return this.iterator('table', function (ctx) {
  1239. if (ctx._responsive) {
  1240. ctx._responsive._classLogic();
  1241. }
  1242. });
  1243. });
  1244. Api.register('responsive.recalc()', function () {
  1245. return this.iterator('table', function (ctx) {
  1246. if (ctx._responsive) {
  1247. ctx._responsive._resizeAuto();
  1248. ctx._responsive._resize();
  1249. }
  1250. });
  1251. });
  1252. Api.register('responsive.hasHidden()', function () {
  1253. var ctx = this.context[0];
  1254. return ctx._responsive ? $.inArray(false, ctx._responsive.s.current) !== -1 : false;
  1255. });
  1256. /**
  1257. * Version information
  1258. *
  1259. * @name Responsive.version
  1260. * @static
  1261. */
  1262. Responsive.version = '2.2.0';
  1263. $.fn.dataTable.Responsive = Responsive;
  1264. $.fn.DataTable.Responsive = Responsive;
  1265. // Attach a listener to the document which listens for DataTables initialisation
  1266. // events so we can automatically initialise
  1267. $(document).on('preInit.dt.dtr', function (e, settings, json) {
  1268. if (e.namespace !== 'dt') {
  1269. return;
  1270. }
  1271. if ($(settings.nTable).hasClass('responsive') || $(settings.nTable).hasClass('dt-responsive') || settings.oInit.responsive || DataTable.defaults.responsive) {
  1272. var init = settings.oInit.responsive;
  1273. if (init !== false) {
  1274. new Responsive(settings, $.isPlainObject(init) ? init : {});
  1275. }
  1276. }
  1277. });
  1278. return Responsive;
  1279. });
  1280. /***/ }),
  1281. /***/ 2:
  1282. /***/ (function(module, exports, __webpack_require__) {
  1283. "use strict";
  1284. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  1285. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  1286. /*! DataTables 1.10.16
  1287. * ©2008-2017 SpryMedia Ltd - datatables.net/license
  1288. */
  1289. /**
  1290. * @summary DataTables
  1291. * @description Paginate, search and order HTML tables
  1292. * @version 1.10.16
  1293. * @file jquery.dataTables.js
  1294. * @autor ThurData <info@thurdata.ch>
  1295. * @contact www.datatables.net
  1296. * @copyright Copyright 2008-2017 SpryMedia Ltd.
  1297. *
  1298. * This source file is free software, available under the following license:
  1299. * MIT license - http://datatables.net/license
  1300. *
  1301. * This source file is distributed in the hope that it will be useful, but
  1302. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  1303. * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
  1304. *
  1305. * For details please refer to: http://www.datatables.net
  1306. */
  1307. /*jslint evil: true, undef: true, browser: true */
  1308. /*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*/
  1309. (function (factory) {
  1310. "use strict";
  1311. if (true) {
  1312. // AMD
  1313. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1)], __WEBPACK_AMD_DEFINE_RESULT__ = function ($) {
  1314. return factory($, window, document);
  1315. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  1316. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  1317. } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
  1318. // CommonJS
  1319. module.exports = function (root, $) {
  1320. if (!root) {
  1321. // CommonJS environments without a window global must pass a
  1322. // root. This will give an error otherwise
  1323. root = window;
  1324. }
  1325. if (!$) {
  1326. $ = typeof window !== 'undefined' ? // jQuery's factory checks for a global window
  1327. require('jquery') : require('jquery')(root);
  1328. }
  1329. return factory($, root, root.document);
  1330. };
  1331. } else {
  1332. // Browser
  1333. factory(jQuery, window, document);
  1334. }
  1335. })(function ($, window, document, undefined) {
  1336. "use strict";
  1337. /**
  1338. * DataTables is a plug-in for the jQuery Javascript library. It is a highly
  1339. * flexible tool, based upon the foundations of progressive enhancement,
  1340. * which will add advanced interaction controls to any HTML table. For a
  1341. * full list of features please refer to
  1342. * [DataTables.net](href="http://datatables.net).
  1343. *
  1344. * Note that the `DataTable` object is not a global variable but is aliased
  1345. * to `jQuery.fn.DataTable` and `jQuery.fn.dataTable` through which it may
  1346. * be accessed.
  1347. *
  1348. * @class
  1349. * @param {object} [init={}] Configuration object for DataTables. Options
  1350. * are defined by {@link DataTable.defaults}
  1351. * @requires jQuery 1.7+
  1352. *
  1353. * @example
  1354. * // Basic initialisation
  1355. * $(document).ready( function {
  1356. * $('#example').dataTable();
  1357. * } );
  1358. *
  1359. * @example
  1360. * // Initialisation with configuration options - in this case, disable
  1361. * // pagination and sorting.
  1362. * $(document).ready( function {
  1363. * $('#example').dataTable( {
  1364. * "paginate": false,
  1365. * "sort": false
  1366. * } );
  1367. * } );
  1368. */
  1369. var DataTable = function DataTable(options) {
  1370. /**
  1371. * Perform a jQuery selector action on the table's TR elements (from the tbody) and
  1372. * return the resulting jQuery object.
  1373. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  1374. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  1375. * @param {string} [oOpts.filter=none] Select TR elements that meet the current filter
  1376. * criterion ("applied") or all TR elements (i.e. no filter).
  1377. * @param {string} [oOpts.order=current] Order of the TR elements in the processed array.
  1378. * Can be either 'current', whereby the current sorting of the table is used, or
  1379. * 'original' whereby the original order the data was read into the table is used.
  1380. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  1381. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  1382. * 'current' and filter is 'applied', regardless of what they might be given as.
  1383. * @returns {object} jQuery object, filtered by the given selector.
  1384. * @dtopt API
  1385. * @deprecated Since v1.10
  1386. *
  1387. * @example
  1388. * $(document).ready(function() {
  1389. * var oTable = $('#example').dataTable();
  1390. *
  1391. * // Highlight every second row
  1392. * oTable.$('tr:odd').css('backgroundColor', 'blue');
  1393. * } );
  1394. *
  1395. * @example
  1396. * $(document).ready(function() {
  1397. * var oTable = $('#example').dataTable();
  1398. *
  1399. * // Filter to rows with 'Webkit' in them, add a background colour and then
  1400. * // remove the filter, thus highlighting the 'Webkit' rows only.
  1401. * oTable.fnFilter('Webkit');
  1402. * oTable.$('tr', {"search": "applied"}).css('backgroundColor', 'blue');
  1403. * oTable.fnFilter('');
  1404. * } );
  1405. */
  1406. this.$ = function (sSelector, oOpts) {
  1407. return this.api(true).$(sSelector, oOpts);
  1408. };
  1409. /**
  1410. * Almost identical to $ in operation, but in this case returns the data for the matched
  1411. * rows - as such, the jQuery selector used should match TR row nodes or TD/TH cell nodes
  1412. * rather than any descendants, so the data can be obtained for the row/cell. If matching
  1413. * rows are found, the data returned is the original data array/object that was used to
  1414. * create the row (or a generated array if from a DOM source).
  1415. *
  1416. * This method is often useful in-combination with $ where both functions are given the
  1417. * same parameters and the array indexes will match identically.
  1418. * @param {string|node|jQuery} sSelector jQuery selector or node collection to act on
  1419. * @param {object} [oOpts] Optional parameters for modifying the rows to be included
  1420. * @param {string} [oOpts.filter=none] Select elements that meet the current filter
  1421. * criterion ("applied") or all elements (i.e. no filter).
  1422. * @param {string} [oOpts.order=current] Order of the data in the processed array.
  1423. * Can be either 'current', whereby the current sorting of the table is used, or
  1424. * 'original' whereby the original order the data was read into the table is used.
  1425. * @param {string} [oOpts.page=all] Limit the selection to the currently displayed page
  1426. * ("current") or not ("all"). If 'current' is given, then order is assumed to be
  1427. * 'current' and filter is 'applied', regardless of what they might be given as.
  1428. * @returns {array} Data for the matched elements. If any elements, as a result of the
  1429. * selector, were not TR, TD or TH elements in the DataTable, they will have a null
  1430. * entry in the array.
  1431. * @dtopt API
  1432. * @deprecated Since v1.10
  1433. *
  1434. * @example
  1435. * $(document).ready(function() {
  1436. * var oTable = $('#example').dataTable();
  1437. *
  1438. * // Get the data from the first row in the table
  1439. * var data = oTable._('tr:first');
  1440. *
  1441. * // Do something useful with the data
  1442. * alert( "First cell is: "+data[0] );
  1443. * } );
  1444. *
  1445. * @example
  1446. * $(document).ready(function() {
  1447. * var oTable = $('#example').dataTable();
  1448. *
  1449. * // Filter to 'Webkit' and get all data for
  1450. * oTable.fnFilter('Webkit');
  1451. * var data = oTable._('tr', {"search": "applied"});
  1452. *
  1453. * // Do something with the data
  1454. * alert( data.length+" rows matched the search" );
  1455. * } );
  1456. */
  1457. this._ = function (sSelector, oOpts) {
  1458. return this.api(true).rows(sSelector, oOpts).data();
  1459. };
  1460. /**
  1461. * Create a DataTables Api instance, with the currently selected tables for
  1462. * the Api's context.
  1463. * @param {boolean} [traditional=false] Set the API instance's context to be
  1464. * only the table referred to by the `DataTable.ext.iApiIndex` option, as was
  1465. * used in the API presented by DataTables 1.9- (i.e. the traditional mode),
  1466. * or if all tables captured in the jQuery object should be used.
  1467. * @return {DataTables.Api}
  1468. */
  1469. this.api = function (traditional) {
  1470. return traditional ? new _Api2(_fnSettingsFromNode(this[_ext.iApiIndex])) : new _Api2(this);
  1471. };
  1472. /**
  1473. * Add a single new row or multiple rows of data to the table. Please note
  1474. * that this is suitable for client-side processing only - if you are using
  1475. * server-side processing (i.e. "bServerSide": true), then to add data, you
  1476. * must add it to the data source, i.e. the server-side, through an Ajax call.
  1477. * @param {array|object} data The data to be added to the table. This can be:
  1478. * <ul>
  1479. * <li>1D array of data - add a single row with the data provided</li>
  1480. * <li>2D array of arrays - add multiple rows in a single call</li>
  1481. * <li>object - data object when using <i>mData</i></li>
  1482. * <li>array of objects - multiple data objects when using <i>mData</i></li>
  1483. * </ul>
  1484. * @param {bool} [redraw=true] redraw the table or not
  1485. * @returns {array} An array of integers, representing the list of indexes in
  1486. * <i>aoData</i> ({@link DataTable.models.oSettings}) that have been added to
  1487. * the table.
  1488. * @dtopt API
  1489. * @deprecated Since v1.10
  1490. *
  1491. * @example
  1492. * // Global var for counter
  1493. * var giCount = 2;
  1494. *
  1495. * $(document).ready(function() {
  1496. * $('#example').dataTable();
  1497. * } );
  1498. *
  1499. * function fnClickAddRow() {
  1500. * $('#example').dataTable().fnAddData( [
  1501. * giCount+".1",
  1502. * giCount+".2",
  1503. * giCount+".3",
  1504. * giCount+".4" ]
  1505. * );
  1506. *
  1507. * giCount++;
  1508. * }
  1509. */
  1510. this.fnAddData = function (data, redraw) {
  1511. var api = this.api(true);
  1512. /* Check if we want to add multiple rows or not */
  1513. var rows = $.isArray(data) && ($.isArray(data[0]) || $.isPlainObject(data[0])) ? api.rows.add(data) : api.row.add(data);
  1514. if (redraw === undefined || redraw) {
  1515. api.draw();
  1516. }
  1517. return rows.flatten().toArray();
  1518. };
  1519. /**
  1520. * This function will make DataTables recalculate the column sizes, based on the data
  1521. * contained in the table and the sizes applied to the columns (in the DOM, CSS or
  1522. * through the sWidth parameter). This can be useful when the width of the table's
  1523. * parent element changes (for example a window resize).
  1524. * @param {boolean} [bRedraw=true] Redraw the table or not, you will typically want to
  1525. * @dtopt API
  1526. * @deprecated Since v1.10
  1527. *
  1528. * @example
  1529. * $(document).ready(function() {
  1530. * var oTable = $('#example').dataTable( {
  1531. * "sScrollY": "200px",
  1532. * "bPaginate": false
  1533. * } );
  1534. *
  1535. * $(window).on('resize', function () {
  1536. * oTable.fnAdjustColumnSizing();
  1537. * } );
  1538. * } );
  1539. */
  1540. this.fnAdjustColumnSizing = function (bRedraw) {
  1541. var api = this.api(true).columns.adjust();
  1542. var settings = api.settings()[0];
  1543. var scroll = settings.oScroll;
  1544. if (bRedraw === undefined || bRedraw) {
  1545. api.draw(false);
  1546. } else if (scroll.sX !== "" || scroll.sY !== "") {
  1547. /* If not redrawing, but scrolling, we want to apply the new column sizes anyway */
  1548. _fnScrollDraw(settings);
  1549. }
  1550. };
  1551. /**
  1552. * Quickly and simply clear a table
  1553. * @param {bool} [bRedraw=true] redraw the table or not
  1554. * @dtopt API
  1555. * @deprecated Since v1.10
  1556. *
  1557. * @example
  1558. * $(document).ready(function() {
  1559. * var oTable = $('#example').dataTable();
  1560. *
  1561. * // Immediately 'nuke' the current rows (perhaps waiting for an Ajax callback...)
  1562. * oTable.fnClearTable();
  1563. * } );
  1564. */
  1565. this.fnClearTable = function (bRedraw) {
  1566. var api = this.api(true).clear();
  1567. if (bRedraw === undefined || bRedraw) {
  1568. api.draw();
  1569. }
  1570. };
  1571. /**
  1572. * The exact opposite of 'opening' a row, this function will close any rows which
  1573. * are currently 'open'.
  1574. * @param {node} nTr the table row to 'close'
  1575. * @returns {int} 0 on success, or 1 if failed (can't find the row)
  1576. * @dtopt API
  1577. * @deprecated Since v1.10
  1578. *
  1579. * @example
  1580. * $(document).ready(function() {
  1581. * var oTable;
  1582. *
  1583. * // 'open' an information row when a row is clicked on
  1584. * $('#example tbody tr').click( function () {
  1585. * if ( oTable.fnIsOpen(this) ) {
  1586. * oTable.fnClose( this );
  1587. * } else {
  1588. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  1589. * }
  1590. * } );
  1591. *
  1592. * oTable = $('#example').dataTable();
  1593. * } );
  1594. */
  1595. this.fnClose = function (nTr) {
  1596. this.api(true).row(nTr).child.hide();
  1597. };
  1598. /**
  1599. * Remove a row for the table
  1600. * @param {mixed} target The index of the row from aoData to be deleted, or
  1601. * the TR element you want to delete
  1602. * @param {function|null} [callBack] Callback function
  1603. * @param {bool} [redraw=true] Redraw the table or not
  1604. * @returns {array} The row that was deleted
  1605. * @dtopt API
  1606. * @deprecated Since v1.10
  1607. *
  1608. * @example
  1609. * $(document).ready(function() {
  1610. * var oTable = $('#example').dataTable();
  1611. *
  1612. * // Immediately remove the first row
  1613. * oTable.fnDeleteRow( 0 );
  1614. * } );
  1615. */
  1616. this.fnDeleteRow = function (target, callback, redraw) {
  1617. var api = this.api(true);
  1618. var rows = api.rows(target);
  1619. var settings = rows.settings()[0];
  1620. var data = settings.aoData[rows[0][0]];
  1621. rows.remove();
  1622. if (callback) {
  1623. callback.call(this, settings, data);
  1624. }
  1625. if (redraw === undefined || redraw) {
  1626. api.draw();
  1627. }
  1628. return data;
  1629. };
  1630. /**
  1631. * Restore the table to it's original state in the DOM by removing all of DataTables
  1632. * enhancements, alterations to the DOM structure of the table and event listeners.
  1633. * @param {boolean} [remove=false] Completely remove the table from the DOM
  1634. * @dtopt API
  1635. * @deprecated Since v1.10
  1636. *
  1637. * @example
  1638. * $(document).ready(function() {
  1639. * // This example is fairly pointless in reality, but shows how fnDestroy can be used
  1640. * var oTable = $('#example').dataTable();
  1641. * oTable.fnDestroy();
  1642. * } );
  1643. */
  1644. this.fnDestroy = function (remove) {
  1645. this.api(true).destroy(remove);
  1646. };
  1647. /**
  1648. * Redraw the table
  1649. * @param {bool} [complete=true] Re-filter and resort (if enabled) the table before the draw.
  1650. * @dtopt API
  1651. * @deprecated Since v1.10
  1652. *
  1653. * @example
  1654. * $(document).ready(function() {
  1655. * var oTable = $('#example').dataTable();
  1656. *
  1657. * // Re-draw the table - you wouldn't want to do it here, but it's an example :-)
  1658. * oTable.fnDraw();
  1659. * } );
  1660. */
  1661. this.fnDraw = function (complete) {
  1662. // Note that this isn't an exact match to the old call to _fnDraw - it takes
  1663. // into account the new data, but can hold position.
  1664. this.api(true).draw(complete);
  1665. };
  1666. /**
  1667. * Filter the input based on data
  1668. * @param {string} sInput String to filter the table on
  1669. * @param {int|null} [iColumn] Column to limit filtering to
  1670. * @param {bool} [bRegex=false] Treat as regular expression or not
  1671. * @param {bool} [bSmart=true] Perform smart filtering or not
  1672. * @param {bool} [bShowGlobal=true] Show the input global filter in it's input box(es)
  1673. * @param {bool} [bCaseInsensitive=true] Do case-insensitive matching (true) or not (false)
  1674. * @dtopt API
  1675. * @deprecated Since v1.10
  1676. *
  1677. * @example
  1678. * $(document).ready(function() {
  1679. * var oTable = $('#example').dataTable();
  1680. *
  1681. * // Sometime later - filter...
  1682. * oTable.fnFilter( 'test string' );
  1683. * } );
  1684. */
  1685. this.fnFilter = function (sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive) {
  1686. var api = this.api(true);
  1687. if (iColumn === null || iColumn === undefined) {
  1688. api.search(sInput, bRegex, bSmart, bCaseInsensitive);
  1689. } else {
  1690. api.column(iColumn).search(sInput, bRegex, bSmart, bCaseInsensitive);
  1691. }
  1692. api.draw();
  1693. };
  1694. /**
  1695. * Get the data for the whole table, an individual row or an individual cell based on the
  1696. * provided parameters.
  1697. * @param {int|node} [src] A TR row node, TD/TH cell node or an integer. If given as
  1698. * a TR node then the data source for the whole row will be returned. If given as a
  1699. * TD/TH cell node then iCol will be automatically calculated and the data for the
  1700. * cell returned. If given as an integer, then this is treated as the aoData internal
  1701. * data index for the row (see fnGetPosition) and the data for that row used.
  1702. * @param {int} [col] Optional column index that you want the data of.
  1703. * @returns {array|object|string} If mRow is undefined, then the data for all rows is
  1704. * returned. If mRow is defined, just data for that row, and is iCol is
  1705. * defined, only data for the designated cell is returned.
  1706. * @dtopt API
  1707. * @deprecated Since v1.10
  1708. *
  1709. * @example
  1710. * // Row data
  1711. * $(document).ready(function() {
  1712. * oTable = $('#example').dataTable();
  1713. *
  1714. * oTable.$('tr').click( function () {
  1715. * var data = oTable.fnGetData( this );
  1716. * // ... do something with the array / object of data for the row
  1717. * } );
  1718. * } );
  1719. *
  1720. * @example
  1721. * // Individual cell data
  1722. * $(document).ready(function() {
  1723. * oTable = $('#example').dataTable();
  1724. *
  1725. * oTable.$('td').click( function () {
  1726. * var sData = oTable.fnGetData( this );
  1727. * alert( 'The cell clicked on had the value of '+sData );
  1728. * } );
  1729. * } );
  1730. */
  1731. this.fnGetData = function (src, col) {
  1732. var api = this.api(true);
  1733. if (src !== undefined) {
  1734. var type = src.nodeName ? src.nodeName.toLowerCase() : '';
  1735. return col !== undefined || type == 'td' || type == 'th' ? api.cell(src, col).data() : api.row(src).data() || null;
  1736. }
  1737. return api.data().toArray();
  1738. };
  1739. /**
  1740. * Get an array of the TR nodes that are used in the table's body. Note that you will
  1741. * typically want to use the '$' API method in preference to this as it is more
  1742. * flexible.
  1743. * @param {int} [iRow] Optional row index for the TR element you want
  1744. * @returns {array|node} If iRow is undefined, returns an array of all TR elements
  1745. * in the table's body, or iRow is defined, just the TR element requested.
  1746. * @dtopt API
  1747. * @deprecated Since v1.10
  1748. *
  1749. * @example
  1750. * $(document).ready(function() {
  1751. * var oTable = $('#example').dataTable();
  1752. *
  1753. * // Get the nodes from the table
  1754. * var nNodes = oTable.fnGetNodes( );
  1755. * } );
  1756. */
  1757. this.fnGetNodes = function (iRow) {
  1758. var api = this.api(true);
  1759. return iRow !== undefined ? api.row(iRow).node() : api.rows().nodes().flatten().toArray();
  1760. };
  1761. /**
  1762. * Get the array indexes of a particular cell from it's DOM element
  1763. * and column index including hidden columns
  1764. * @param {node} node this can either be a TR, TD or TH in the table's body
  1765. * @returns {int} If nNode is given as a TR, then a single index is returned, or
  1766. * if given as a cell, an array of [row index, column index (visible),
  1767. * column index (all)] is given.
  1768. * @dtopt API
  1769. * @deprecated Since v1.10
  1770. *
  1771. * @example
  1772. * $(document).ready(function() {
  1773. * $('#example tbody td').click( function () {
  1774. * // Get the position of the current data from the node
  1775. * var aPos = oTable.fnGetPosition( this );
  1776. *
  1777. * // Get the data array for this row
  1778. * var aData = oTable.fnGetData( aPos[0] );
  1779. *
  1780. * // Update the data array and return the value
  1781. * aData[ aPos[1] ] = 'clicked';
  1782. * this.innerHTML = 'clicked';
  1783. * } );
  1784. *
  1785. * // Init DataTables
  1786. * oTable = $('#example').dataTable();
  1787. * } );
  1788. */
  1789. this.fnGetPosition = function (node) {
  1790. var api = this.api(true);
  1791. var nodeName = node.nodeName.toUpperCase();
  1792. if (nodeName == 'TR') {
  1793. return api.row(node).index();
  1794. } else if (nodeName == 'TD' || nodeName == 'TH') {
  1795. var cell = api.cell(node).index();
  1796. return [cell.row, cell.columnVisible, cell.column];
  1797. }
  1798. return null;
  1799. };
  1800. /**
  1801. * Check to see if a row is 'open' or not.
  1802. * @param {node} nTr the table row to check
  1803. * @returns {boolean} true if the row is currently open, false otherwise
  1804. * @dtopt API
  1805. * @deprecated Since v1.10
  1806. *
  1807. * @example
  1808. * $(document).ready(function() {
  1809. * var oTable;
  1810. *
  1811. * // 'open' an information row when a row is clicked on
  1812. * $('#example tbody tr').click( function () {
  1813. * if ( oTable.fnIsOpen(this) ) {
  1814. * oTable.fnClose( this );
  1815. * } else {
  1816. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  1817. * }
  1818. * } );
  1819. *
  1820. * oTable = $('#example').dataTable();
  1821. * } );
  1822. */
  1823. this.fnIsOpen = function (nTr) {
  1824. return this.api(true).row(nTr).child.isShown();
  1825. };
  1826. /**
  1827. * This function will place a new row directly after a row which is currently
  1828. * on display on the page, with the HTML contents that is passed into the
  1829. * function. This can be used, for example, to ask for confirmation that a
  1830. * particular record should be deleted.
  1831. * @param {node} nTr The table row to 'open'
  1832. * @param {string|node|jQuery} mHtml The HTML to put into the row
  1833. * @param {string} sClass Class to give the new TD cell
  1834. * @returns {node} The row opened. Note that if the table row passed in as the
  1835. * first parameter, is not found in the table, this method will silently
  1836. * return.
  1837. * @dtopt API
  1838. * @deprecated Since v1.10
  1839. *
  1840. * @example
  1841. * $(document).ready(function() {
  1842. * var oTable;
  1843. *
  1844. * // 'open' an information row when a row is clicked on
  1845. * $('#example tbody tr').click( function () {
  1846. * if ( oTable.fnIsOpen(this) ) {
  1847. * oTable.fnClose( this );
  1848. * } else {
  1849. * oTable.fnOpen( this, "Temporary row opened", "info_row" );
  1850. * }
  1851. * } );
  1852. *
  1853. * oTable = $('#example').dataTable();
  1854. * } );
  1855. */
  1856. this.fnOpen = function (nTr, mHtml, sClass) {
  1857. return this.api(true).row(nTr).child(mHtml, sClass).show().child()[0];
  1858. };
  1859. /**
  1860. * Change the pagination - provides the internal logic for pagination in a simple API
  1861. * function. With this function you can have a DataTables table go to the next,
  1862. * previous, first or last pages.
  1863. * @param {string|int} mAction Paging action to take: "first", "previous", "next" or "last"
  1864. * or page number to jump to (integer), note that page 0 is the first page.
  1865. * @param {bool} [bRedraw=true] Redraw the table or not
  1866. * @dtopt API
  1867. * @deprecated Since v1.10
  1868. *
  1869. * @example
  1870. * $(document).ready(function() {
  1871. * var oTable = $('#example').dataTable();
  1872. * oTable.fnPageChange( 'next' );
  1873. * } );
  1874. */
  1875. this.fnPageChange = function (mAction, bRedraw) {
  1876. var api = this.api(true).page(mAction);
  1877. if (bRedraw === undefined || bRedraw) {
  1878. api.draw(false);
  1879. }
  1880. };
  1881. /**
  1882. * Show a particular column
  1883. * @param {int} iCol The column whose display should be changed
  1884. * @param {bool} bShow Show (true) or hide (false) the column
  1885. * @param {bool} [bRedraw=true] Redraw the table or not
  1886. * @dtopt API
  1887. * @deprecated Since v1.10
  1888. *
  1889. * @example
  1890. * $(document).ready(function() {
  1891. * var oTable = $('#example').dataTable();
  1892. *
  1893. * // Hide the second column after initialisation
  1894. * oTable.fnSetColumnVis( 1, false );
  1895. * } );
  1896. */
  1897. this.fnSetColumnVis = function (iCol, bShow, bRedraw) {
  1898. var api = this.api(true).column(iCol).visible(bShow);
  1899. if (bRedraw === undefined || bRedraw) {
  1900. api.columns.adjust().draw();
  1901. }
  1902. };
  1903. /**
  1904. * Get the settings for a particular table for external manipulation
  1905. * @returns {object} DataTables settings object. See
  1906. * {@link DataTable.models.oSettings}
  1907. * @dtopt API
  1908. * @deprecated Since v1.10
  1909. *
  1910. * @example
  1911. * $(document).ready(function() {
  1912. * var oTable = $('#example').dataTable();
  1913. * var oSettings = oTable.fnSettings();
  1914. *
  1915. * // Show an example parameter from the settings
  1916. * alert( oSettings._iDisplayStart );
  1917. * } );
  1918. */
  1919. this.fnSettings = function () {
  1920. return _fnSettingsFromNode(this[_ext.iApiIndex]);
  1921. };
  1922. /**
  1923. * Sort the table by a particular column
  1924. * @param {int} iCol the data index to sort on. Note that this will not match the
  1925. * 'display index' if you have hidden data entries
  1926. * @dtopt API
  1927. * @deprecated Since v1.10
  1928. *
  1929. * @example
  1930. * $(document).ready(function() {
  1931. * var oTable = $('#example').dataTable();
  1932. *
  1933. * // Sort immediately with columns 0 and 1
  1934. * oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );
  1935. * } );
  1936. */
  1937. this.fnSort = function (aaSort) {
  1938. this.api(true).order(aaSort).draw();
  1939. };
  1940. /**
  1941. * Attach a sort listener to an element for a given column
  1942. * @param {node} nNode the element to attach the sort listener to
  1943. * @param {int} iColumn the column that a click on this node will sort on
  1944. * @param {function} [fnCallback] callback function when sort is run
  1945. * @dtopt API
  1946. * @deprecated Since v1.10
  1947. *
  1948. * @example
  1949. * $(document).ready(function() {
  1950. * var oTable = $('#example').dataTable();
  1951. *
  1952. * // Sort on column 1, when 'sorter' is clicked on
  1953. * oTable.fnSortListener( document.getElementById('sorter'), 1 );
  1954. * } );
  1955. */
  1956. this.fnSortListener = function (nNode, iColumn, fnCallback) {
  1957. this.api(true).order.listener(nNode, iColumn, fnCallback);
  1958. };
  1959. /**
  1960. * Update a table cell or row - this method will accept either a single value to
  1961. * update the cell with, an array of values with one element for each column or
  1962. * an object in the same format as the original data source. The function is
  1963. * self-referencing in order to make the multi column updates easier.
  1964. * @param {object|array|string} mData Data to update the cell/row with
  1965. * @param {node|int} mRow TR element you want to update or the aoData index
  1966. * @param {int} [iColumn] The column to update, give as null or undefined to
  1967. * update a whole row.
  1968. * @param {bool} [bRedraw=true] Redraw the table or not
  1969. * @param {bool} [bAction=true] Perform pre-draw actions or not
  1970. * @returns {int} 0 on success, 1 on error
  1971. * @dtopt API
  1972. * @deprecated Since v1.10
  1973. *
  1974. * @example
  1975. * $(document).ready(function() {
  1976. * var oTable = $('#example').dataTable();
  1977. * oTable.fnUpdate( 'Example update', 0, 0 ); // Single cell
  1978. * oTable.fnUpdate( ['a', 'b', 'c', 'd', 'e'], $('tbody tr')[0] ); // Row
  1979. * } );
  1980. */
  1981. this.fnUpdate = function (mData, mRow, iColumn, bRedraw, bAction) {
  1982. var api = this.api(true);
  1983. if (iColumn === undefined || iColumn === null) {
  1984. api.row(mRow).data(mData);
  1985. } else {
  1986. api.cell(mRow, iColumn).data(mData);
  1987. }
  1988. if (bAction === undefined || bAction) {
  1989. api.columns.adjust();
  1990. }
  1991. if (bRedraw === undefined || bRedraw) {
  1992. api.draw();
  1993. }
  1994. return 0;
  1995. };
  1996. /**
  1997. * Provide a common method for plug-ins to check the version of DataTables being used, in order
  1998. * to ensure compatibility.
  1999. * @param {string} sVersion Version string to check for, in the format "X.Y.Z". Note that the
  2000. * formats "X" and "X.Y" are also acceptable.
  2001. * @returns {boolean} true if this version of DataTables is greater or equal to the required
  2002. * version, or false if this version of DataTales is not suitable
  2003. * @method
  2004. * @dtopt API
  2005. * @deprecated Since v1.10
  2006. *
  2007. * @example
  2008. * $(document).ready(function() {
  2009. * var oTable = $('#example').dataTable();
  2010. * alert( oTable.fnVersionCheck( '1.9.0' ) );
  2011. * } );
  2012. */
  2013. this.fnVersionCheck = _ext.fnVersionCheck;
  2014. var _that = this;
  2015. var emptyInit = options === undefined;
  2016. var len = this.length;
  2017. if (emptyInit) {
  2018. options = {};
  2019. }
  2020. this.oApi = this.internal = _ext.internal;
  2021. // Extend with old style plug-in API methods
  2022. for (var fn in DataTable.ext.internal) {
  2023. if (fn) {
  2024. this[fn] = _fnExternApiFunc(fn);
  2025. }
  2026. }
  2027. this.each(function () {
  2028. // For each initialisation we want to give it a clean initialisation
  2029. // object that can be bashed around
  2030. var o = {};
  2031. var oInit = len > 1 ? // optimisation for single table case
  2032. _fnExtend(o, options, true) : options;
  2033. /*global oInit,_that,emptyInit*/
  2034. var i = 0,
  2035. iLen,
  2036. j,
  2037. jLen,
  2038. k,
  2039. kLen;
  2040. var sId = this.getAttribute('id');
  2041. var bInitHandedOff = false;
  2042. var defaults = DataTable.defaults;
  2043. var $this = $(this);
  2044. /* Sanity check */
  2045. if (this.nodeName.toLowerCase() != 'table') {
  2046. _fnLog(null, 0, 'Non-table node initialisation (' + this.nodeName + ')', 2);
  2047. return;
  2048. }
  2049. /* Backwards compatibility for the defaults */
  2050. _fnCompatOpts(defaults);
  2051. _fnCompatCols(defaults.column);
  2052. /* Convert the camel-case defaults to Hungarian */
  2053. _fnCamelToHungarian(defaults, defaults, true);
  2054. _fnCamelToHungarian(defaults.column, defaults.column, true);
  2055. /* Setting up the initialisation object */
  2056. _fnCamelToHungarian(defaults, $.extend(oInit, $this.data()));
  2057. /* Check to see if we are re-initialising a table */
  2058. var allSettings = DataTable.settings;
  2059. for (i = 0, iLen = allSettings.length; i < iLen; i++) {
  2060. var s = allSettings[i];
  2061. /* Base check on table node */
  2062. if (s.nTable == this || s.nTHead.parentNode == this || s.nTFoot && s.nTFoot.parentNode == this) {
  2063. var bRetrieve = oInit.bRetrieve !== undefined ? oInit.bRetrieve : defaults.bRetrieve;
  2064. var bDestroy = oInit.bDestroy !== undefined ? oInit.bDestroy : defaults.bDestroy;
  2065. if (emptyInit || bRetrieve) {
  2066. return s.oInstance;
  2067. } else if (bDestroy) {
  2068. s.oInstance.fnDestroy();
  2069. break;
  2070. } else {
  2071. _fnLog(s, 0, 'Cannot reinitialise DataTable', 3);
  2072. return;
  2073. }
  2074. }
  2075. /* If the element we are initialising has the same ID as a table which was previously
  2076. * initialised, but the table nodes don't match (from before) then we destroy the old
  2077. * instance by simply deleting it. This is under the assumption that the table has been
  2078. * destroyed by other methods. Anyone using non-id selectors will need to do this manually
  2079. */
  2080. if (s.sTableId == this.id) {
  2081. allSettings.splice(i, 1);
  2082. break;
  2083. }
  2084. }
  2085. /* Ensure the table has an ID - required for accessibility */
  2086. if (sId === null || sId === "") {
  2087. sId = "DataTables_Table_" + DataTable.ext._unique++;
  2088. this.id = sId;
  2089. }
  2090. /* Create the settings object for this table and set some of the default parameters */
  2091. var oSettings = $.extend(true, {}, DataTable.models.oSettings, {
  2092. "sDestroyWidth": $this[0].style.width,
  2093. "sInstance": sId,
  2094. "sTableId": sId
  2095. });
  2096. oSettings.nTable = this;
  2097. oSettings.oApi = _that.internal;
  2098. oSettings.oInit = oInit;
  2099. allSettings.push(oSettings);
  2100. // Need to add the instance after the instance after the settings object has been added
  2101. // to the settings array, so we can self reference the table instance if more than one
  2102. oSettings.oInstance = _that.length === 1 ? _that : $this.dataTable();
  2103. // Backwards compatibility, before we apply all the defaults
  2104. _fnCompatOpts(oInit);
  2105. if (oInit.oLanguage) {
  2106. _fnLanguageCompat(oInit.oLanguage);
  2107. }
  2108. // If the length menu is given, but the init display length is not, use the length menu
  2109. if (oInit.aLengthMenu && !oInit.iDisplayLength) {
  2110. oInit.iDisplayLength = $.isArray(oInit.aLengthMenu[0]) ? oInit.aLengthMenu[0][0] : oInit.aLengthMenu[0];
  2111. }
  2112. // Apply the defaults and init options to make a single init object will all
  2113. // options defined from defaults and instance options.
  2114. oInit = _fnExtend($.extend(true, {}, defaults), oInit);
  2115. // Map the initialisation options onto the settings object
  2116. _fnMap(oSettings.oFeatures, oInit, ["bPaginate", "bLengthChange", "bFilter", "bSort", "bSortMulti", "bInfo", "bProcessing", "bAutoWidth", "bSortClasses", "bServerSide", "bDeferRender"]);
  2117. _fnMap(oSettings, oInit, ["asStripeClasses", "ajax", "fnServerData", "fnFormatNumber", "sServerMethod", "aaSorting", "aaSortingFixed", "aLengthMenu", "sPaginationType", "sAjaxSource", "sAjaxDataProp", "iStateDuration", "sDom", "bSortCellsTop", "iTabIndex", "fnStateLoadCallback", "fnStateSaveCallback", "renderer", "searchDelay", "rowId", ["iCookieDuration", "iStateDuration"], // backwards compat
  2118. ["oSearch", "oPreviousSearch"], ["aoSearchCols", "aoPreSearchCols"], ["iDisplayLength", "_iDisplayLength"]]);
  2119. _fnMap(oSettings.oScroll, oInit, [["sScrollX", "sX"], ["sScrollXInner", "sXInner"], ["sScrollY", "sY"], ["bScrollCollapse", "bCollapse"]]);
  2120. _fnMap(oSettings.oLanguage, oInit, "fnInfoCallback");
  2121. /* Callback functions which are array driven */
  2122. _fnCallbackReg(oSettings, 'aoDrawCallback', oInit.fnDrawCallback, 'user');
  2123. _fnCallbackReg(oSettings, 'aoServerParams', oInit.fnServerParams, 'user');
  2124. _fnCallbackReg(oSettings, 'aoStateSaveParams', oInit.fnStateSaveParams, 'user');
  2125. _fnCallbackReg(oSettings, 'aoStateLoadParams', oInit.fnStateLoadParams, 'user');
  2126. _fnCallbackReg(oSettings, 'aoStateLoaded', oInit.fnStateLoaded, 'user');
  2127. _fnCallbackReg(oSettings, 'aoRowCallback', oInit.fnRowCallback, 'user');
  2128. _fnCallbackReg(oSettings, 'aoRowCreatedCallback', oInit.fnCreatedRow, 'user');
  2129. _fnCallbackReg(oSettings, 'aoHeaderCallback', oInit.fnHeaderCallback, 'user');
  2130. _fnCallbackReg(oSettings, 'aoFooterCallback', oInit.fnFooterCallback, 'user');
  2131. _fnCallbackReg(oSettings, 'aoInitComplete', oInit.fnInitComplete, 'user');
  2132. _fnCallbackReg(oSettings, 'aoPreDrawCallback', oInit.fnPreDrawCallback, 'user');
  2133. oSettings.rowIdFn = _fnGetObjectDataFn(oInit.rowId);
  2134. /* Browser support detection */
  2135. _fnBrowserDetect(oSettings);
  2136. var oClasses = oSettings.oClasses;
  2137. $.extend(oClasses, DataTable.ext.classes, oInit.oClasses);
  2138. $this.addClass(oClasses.sTable);
  2139. if (oSettings.iInitDisplayStart === undefined) {
  2140. /* Display start point, taking into account the save saving */
  2141. oSettings.iInitDisplayStart = oInit.iDisplayStart;
  2142. oSettings._iDisplayStart = oInit.iDisplayStart;
  2143. }
  2144. if (oInit.iDeferLoading !== null) {
  2145. oSettings.bDeferLoading = true;
  2146. var tmp = $.isArray(oInit.iDeferLoading);
  2147. oSettings._iRecordsDisplay = tmp ? oInit.iDeferLoading[0] : oInit.iDeferLoading;
  2148. oSettings._iRecordsTotal = tmp ? oInit.iDeferLoading[1] : oInit.iDeferLoading;
  2149. }
  2150. /* Language definitions */
  2151. var oLanguage = oSettings.oLanguage;
  2152. $.extend(true, oLanguage, oInit.oLanguage);
  2153. if (oLanguage.sUrl) {
  2154. /* Get the language definitions from a file - because this Ajax call makes the language
  2155. * get async to the remainder of this function we use bInitHandedOff to indicate that
  2156. * _fnInitialise will be fired by the returned Ajax handler, rather than the constructor
  2157. */
  2158. $.ajax({
  2159. dataType: 'json',
  2160. url: oLanguage.sUrl,
  2161. success: function success(json) {
  2162. _fnLanguageCompat(json);
  2163. _fnCamelToHungarian(defaults.oLanguage, json);
  2164. $.extend(true, oLanguage, json);
  2165. _fnInitialise(oSettings);
  2166. },
  2167. error: function error() {
  2168. // Error occurred loading language file, continue on as best we can
  2169. _fnInitialise(oSettings);
  2170. }
  2171. });
  2172. bInitHandedOff = true;
  2173. }
  2174. /*
  2175. * Stripes
  2176. */
  2177. if (oInit.asStripeClasses === null) {
  2178. oSettings.asStripeClasses = [oClasses.sStripeOdd, oClasses.sStripeEven];
  2179. }
  2180. /* Remove row stripe classes if they are already on the table row */
  2181. var stripeClasses = oSettings.asStripeClasses;
  2182. var rowOne = $this.children('tbody').find('tr').eq(0);
  2183. if ($.inArray(true, $.map(stripeClasses, function (el, i) {
  2184. return rowOne.hasClass(el);
  2185. })) !== -1) {
  2186. $('tbody tr', this).removeClass(stripeClasses.join(' '));
  2187. oSettings.asDestroyStripes = stripeClasses.slice();
  2188. }
  2189. /*
  2190. * Columns
  2191. * See if we should load columns automatically or use defined ones
  2192. */
  2193. var anThs = [];
  2194. var aoColumnsInit;
  2195. var nThead = this.getElementsByTagName('thead');
  2196. if (nThead.length !== 0) {
  2197. _fnDetectHeader(oSettings.aoHeader, nThead[0]);
  2198. anThs = _fnGetUniqueThs(oSettings);
  2199. }
  2200. /* If not given a column array, generate one with nulls */
  2201. if (oInit.aoColumns === null) {
  2202. aoColumnsInit = [];
  2203. for (i = 0, iLen = anThs.length; i < iLen; i++) {
  2204. aoColumnsInit.push(null);
  2205. }
  2206. } else {
  2207. aoColumnsInit = oInit.aoColumns;
  2208. }
  2209. /* Add the columns */
  2210. for (i = 0, iLen = aoColumnsInit.length; i < iLen; i++) {
  2211. _fnAddColumn(oSettings, anThs ? anThs[i] : null);
  2212. }
  2213. /* Apply the column definitions */
  2214. _fnApplyColumnDefs(oSettings, oInit.aoColumnDefs, aoColumnsInit, function (iCol, oDef) {
  2215. _fnColumnOptions(oSettings, iCol, oDef);
  2216. });
  2217. /* HTML5 attribute detection - build an mData object automatically if the
  2218. * attributes are found
  2219. */
  2220. if (rowOne.length) {
  2221. var a = function a(cell, name) {
  2222. return cell.getAttribute('data-' + name) !== null ? name : null;
  2223. };
  2224. $(rowOne[0]).children('th, td').each(function (i, cell) {
  2225. var col = oSettings.aoColumns[i];
  2226. if (col.mData === i) {
  2227. var sort = a(cell, 'sort') || a(cell, 'order');
  2228. var filter = a(cell, 'filter') || a(cell, 'search');
  2229. if (sort !== null || filter !== null) {
  2230. col.mData = {
  2231. _: i + '.display',
  2232. sort: sort !== null ? i + '.@data-' + sort : undefined,
  2233. type: sort !== null ? i + '.@data-' + sort : undefined,
  2234. filter: filter !== null ? i + '.@data-' + filter : undefined
  2235. };
  2236. _fnColumnOptions(oSettings, i);
  2237. }
  2238. }
  2239. });
  2240. }
  2241. var features = oSettings.oFeatures;
  2242. var loadedInit = function loadedInit() {
  2243. /*
  2244. * Sorting
  2245. * @todo For modularisation (1.11) this needs to do into a sort start up handler
  2246. */
  2247. // If aaSorting is not defined, then we use the first indicator in asSorting
  2248. // in case that has been altered, so the default sort reflects that option
  2249. if (oInit.aaSorting === undefined) {
  2250. var sorting = oSettings.aaSorting;
  2251. for (i = 0, iLen = sorting.length; i < iLen; i++) {
  2252. sorting[i][1] = oSettings.aoColumns[i].asSorting[0];
  2253. }
  2254. }
  2255. /* Do a first pass on the sorting classes (allows any size changes to be taken into
  2256. * account, and also will apply sorting disabled classes if disabled
  2257. */
  2258. _fnSortingClasses(oSettings);
  2259. if (features.bSort) {
  2260. _fnCallbackReg(oSettings, 'aoDrawCallback', function () {
  2261. if (oSettings.bSorted) {
  2262. var aSort = _fnSortFlatten(oSettings);
  2263. var sortedColumns = {};
  2264. $.each(aSort, function (i, val) {
  2265. sortedColumns[val.src] = val.dir;
  2266. });
  2267. _fnCallbackFire(oSettings, null, 'order', [oSettings, aSort, sortedColumns]);
  2268. _fnSortAria(oSettings);
  2269. }
  2270. });
  2271. }
  2272. _fnCallbackReg(oSettings, 'aoDrawCallback', function () {
  2273. if (oSettings.bSorted || _fnDataSource(oSettings) === 'ssp' || features.bDeferRender) {
  2274. _fnSortingClasses(oSettings);
  2275. }
  2276. }, 'sc');
  2277. /*
  2278. * Final init
  2279. * Cache the header, body and footer as required, creating them if needed
  2280. */
  2281. // Work around for Webkit bug 83867 - store the caption-side before removing from doc
  2282. var captions = $this.children('caption').each(function () {
  2283. this._captionSide = $(this).css('caption-side');
  2284. });
  2285. var thead = $this.children('thead');
  2286. if (thead.length === 0) {
  2287. thead = $('<thead/>').appendTo($this);
  2288. }
  2289. oSettings.nTHead = thead[0];
  2290. var tbody = $this.children('tbody');
  2291. if (tbody.length === 0) {
  2292. tbody = $('<tbody/>').appendTo($this);
  2293. }
  2294. oSettings.nTBody = tbody[0];
  2295. var tfoot = $this.children('tfoot');
  2296. if (tfoot.length === 0 && captions.length > 0 && (oSettings.oScroll.sX !== "" || oSettings.oScroll.sY !== "")) {
  2297. // If we are a scrolling table, and no footer has been given, then we need to create
  2298. // a tfoot element for the caption element to be appended to
  2299. tfoot = $('<tfoot/>').appendTo($this);
  2300. }
  2301. if (tfoot.length === 0 || tfoot.children().length === 0) {
  2302. $this.addClass(oClasses.sNoFooter);
  2303. } else if (tfoot.length > 0) {
  2304. oSettings.nTFoot = tfoot[0];
  2305. _fnDetectHeader(oSettings.aoFooter, oSettings.nTFoot);
  2306. }
  2307. /* Check if there is data passing into the constructor */
  2308. if (oInit.aaData) {
  2309. for (i = 0; i < oInit.aaData.length; i++) {
  2310. _fnAddData(oSettings, oInit.aaData[i]);
  2311. }
  2312. } else if (oSettings.bDeferLoading || _fnDataSource(oSettings) == 'dom') {
  2313. /* Grab the data from the page - only do this when deferred loading or no Ajax
  2314. * source since there is no point in reading the DOM data if we are then going
  2315. * to replace it with Ajax data
  2316. */
  2317. _fnAddTr(oSettings, $(oSettings.nTBody).children('tr'));
  2318. }
  2319. /* Copy the data index array */
  2320. oSettings.aiDisplay = oSettings.aiDisplayMaster.slice();
  2321. /* Initialisation complete - table can be drawn */
  2322. oSettings.bInitialised = true;
  2323. /* Check if we need to initialise the table (it might not have been handed off to the
  2324. * language processor)
  2325. */
  2326. if (bInitHandedOff === false) {
  2327. _fnInitialise(oSettings);
  2328. }
  2329. };
  2330. /* Must be done after everything which can be overridden by the state saving! */
  2331. if (oInit.bStateSave) {
  2332. features.bStateSave = true;
  2333. _fnCallbackReg(oSettings, 'aoDrawCallback', _fnSaveState, 'state_save');
  2334. _fnLoadState(oSettings, oInit, loadedInit);
  2335. } else {
  2336. loadedInit();
  2337. }
  2338. });
  2339. _that = null;
  2340. return this;
  2341. };
  2342. /*
  2343. * It is useful to have variables which are scoped locally so only the
  2344. * DataTables functions can access them and they don't leak into global space.
  2345. * At the same time these functions are often useful over multiple files in the
  2346. * core and API, so we list, or at least document, all variables which are used
  2347. * by DataTables as private variables here. This also ensures that there is no
  2348. * clashing of variable names and that they can easily referenced for reuse.
  2349. */
  2350. // Defined else where
  2351. // _selector_run
  2352. // _selector_opts
  2353. // _selector_first
  2354. // _selector_row_indexes
  2355. var _ext; // DataTable.ext
  2356. var _Api2; // DataTable.Api
  2357. var _api_register; // DataTable.Api.register
  2358. var _api_registerPlural; // DataTable.Api.registerPlural
  2359. var _re_dic = {};
  2360. var _re_new_lines = /[\r\n]/g;
  2361. var _re_html = /<.*?>/g;
  2362. // This is not strict ISO8601 - Date.parse() is quite lax, although
  2363. // implementations differ between browsers.
  2364. var _re_date = /^\d{2,4}[\.\/\-]\d{1,2}[\.\/\-]\d{1,2}([T ]{1}\d{1,2}[:\.]\d{2}([\.:]\d{2})?)?$/;
  2365. // Escape regular expression special characters
  2366. var _re_escape_regex = new RegExp('(\\' + ['/', '.', '*', '+', '?', '|', '(', ')', '[', ']', '{', '}', '\\', '$', '^', '-'].join('|\\') + ')', 'g');
  2367. // http://en.wikipedia.org/wiki/Foreign_exchange_market
  2368. // - \u20BD - Russian ruble.
  2369. // - \u20a9 - South Korean Won
  2370. // - \u20BA - Turkish Lira
  2371. // - \u20B9 - Indian Rupee
  2372. // - R - Brazil (R$) and South Africa
  2373. // - fr - Swiss Franc
  2374. // - kr - Swedish krona, Norwegian krone and Danish krone
  2375. // - \u2009 is thin space and \u202F is narrow no-break space, both used in many
  2376. // standards as thousands separators.
  2377. var _re_formatted_numeric = /[',$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfk]/gi;
  2378. var _empty = function _empty(d) {
  2379. return !d || d === true || d === '-' ? true : false;
  2380. };
  2381. var _intVal = function _intVal(s) {
  2382. var integer = parseInt(s, 10);
  2383. return !isNaN(integer) && isFinite(s) ? integer : null;
  2384. };
  2385. // Convert from a formatted number with characters other than `.` as the
  2386. // decimal place, to a Javascript number
  2387. var _numToDecimal = function _numToDecimal(num, decimalPoint) {
  2388. // Cache created regular expressions for speed as this function is called often
  2389. if (!_re_dic[decimalPoint]) {
  2390. _re_dic[decimalPoint] = new RegExp(_fnEscapeRegex(decimalPoint), 'g');
  2391. }
  2392. return typeof num === 'string' && decimalPoint !== '.' ? num.replace(/\./g, '').replace(_re_dic[decimalPoint], '.') : num;
  2393. };
  2394. var _isNumber = function _isNumber(d, decimalPoint, formatted) {
  2395. var strType = typeof d === 'string';
  2396. // If empty return immediately so there must be a number if it is a
  2397. // formatted string (this stops the string "k", or "kr", etc being detected
  2398. // as a formatted number for currency
  2399. if (_empty(d)) {
  2400. return true;
  2401. }
  2402. if (decimalPoint && strType) {
  2403. d = _numToDecimal(d, decimalPoint);
  2404. }
  2405. if (formatted && strType) {
  2406. d = d.replace(_re_formatted_numeric, '');
  2407. }
  2408. return !isNaN(parseFloat(d)) && isFinite(d);
  2409. };
  2410. // A string without HTML in it can be considered to be HTML still
  2411. var _isHtml = function _isHtml(d) {
  2412. return _empty(d) || typeof d === 'string';
  2413. };
  2414. var _htmlNumeric = function _htmlNumeric(d, decimalPoint, formatted) {
  2415. if (_empty(d)) {
  2416. return true;
  2417. }
  2418. var html = _isHtml(d);
  2419. return !html ? null : _isNumber(_stripHtml(d), decimalPoint, formatted) ? true : null;
  2420. };
  2421. var _pluck = function _pluck(a, prop, prop2) {
  2422. var out = [];
  2423. var i = 0,
  2424. ien = a.length;
  2425. // Could have the test in the loop for slightly smaller code, but speed
  2426. // is essential here
  2427. if (prop2 !== undefined) {
  2428. for (; i < ien; i++) {
  2429. if (a[i] && a[i][prop]) {
  2430. out.push(a[i][prop][prop2]);
  2431. }
  2432. }
  2433. } else {
  2434. for (; i < ien; i++) {
  2435. if (a[i]) {
  2436. out.push(a[i][prop]);
  2437. }
  2438. }
  2439. }
  2440. return out;
  2441. };
  2442. // Basically the same as _pluck, but rather than looping over `a` we use `order`
  2443. // as the indexes to pick from `a`
  2444. var _pluck_order = function _pluck_order(a, order, prop, prop2) {
  2445. var out = [];
  2446. var i = 0,
  2447. ien = order.length;
  2448. // Could have the test in the loop for slightly smaller code, but speed
  2449. // is essential here
  2450. if (prop2 !== undefined) {
  2451. for (; i < ien; i++) {
  2452. if (a[order[i]][prop]) {
  2453. out.push(a[order[i]][prop][prop2]);
  2454. }
  2455. }
  2456. } else {
  2457. for (; i < ien; i++) {
  2458. out.push(a[order[i]][prop]);
  2459. }
  2460. }
  2461. return out;
  2462. };
  2463. var _range = function _range(len, start) {
  2464. var out = [];
  2465. var end;
  2466. if (start === undefined) {
  2467. start = 0;
  2468. end = len;
  2469. } else {
  2470. end = start;
  2471. start = len;
  2472. }
  2473. for (var i = start; i < end; i++) {
  2474. out.push(i);
  2475. }
  2476. return out;
  2477. };
  2478. var _removeEmpty = function _removeEmpty(a) {
  2479. var out = [];
  2480. for (var i = 0, ien = a.length; i < ien; i++) {
  2481. if (a[i]) {
  2482. // careful - will remove all falsy values!
  2483. out.push(a[i]);
  2484. }
  2485. }
  2486. return out;
  2487. };
  2488. var _stripHtml = function _stripHtml(d) {
  2489. return d.replace(_re_html, '');
  2490. };
  2491. /**
  2492. * Determine if all values in the array are unique. This means we can short
  2493. * cut the _unique method at the cost of a single loop. A sorted array is used
  2494. * to easily check the values.
  2495. *
  2496. * @param {array} src Source array
  2497. * @return {boolean} true if all unique, false otherwise
  2498. * @ignore
  2499. */
  2500. var _areAllUnique = function _areAllUnique(src) {
  2501. if (src.length < 2) {
  2502. return true;
  2503. }
  2504. var sorted = src.slice().sort();
  2505. var last = sorted[0];
  2506. for (var i = 1, ien = sorted.length; i < ien; i++) {
  2507. if (sorted[i] === last) {
  2508. return false;
  2509. }
  2510. last = sorted[i];
  2511. }
  2512. return true;
  2513. };
  2514. /**
  2515. * Find the unique elements in a source array.
  2516. *
  2517. * @param {array} src Source array
  2518. * @return {array} Array of unique items
  2519. * @ignore
  2520. */
  2521. var _unique = function _unique(src) {
  2522. if (_areAllUnique(src)) {
  2523. return src.slice();
  2524. }
  2525. // A faster unique method is to use object keys to identify used values,
  2526. // but this doesn't work with arrays or objects, which we must also
  2527. // consider. See jsperf.com/compare-array-unique-versions/4 for more
  2528. // information.
  2529. var out = [],
  2530. val,
  2531. i,
  2532. ien = src.length,
  2533. j,
  2534. k = 0;
  2535. again: for (i = 0; i < ien; i++) {
  2536. val = src[i];
  2537. for (j = 0; j < k; j++) {
  2538. if (out[j] === val) {
  2539. continue again;
  2540. }
  2541. }
  2542. out.push(val);
  2543. k++;
  2544. }
  2545. return out;
  2546. };
  2547. /**
  2548. * DataTables utility methods
  2549. *
  2550. * This namespace provides helper methods that DataTables uses internally to
  2551. * create a DataTable, but which are not exclusively used only for DataTables.
  2552. * These methods can be used by extension authors to save the duplication of
  2553. * code.
  2554. *
  2555. * @namespace
  2556. */
  2557. DataTable.util = {
  2558. /**
  2559. * Throttle the calls to a function. Arguments and context are maintained
  2560. * for the throttled function.
  2561. *
  2562. * @param {function} fn Function to be called
  2563. * @param {integer} freq Call frequency in mS
  2564. * @return {function} Wrapped function
  2565. */
  2566. throttle: function throttle(fn, freq) {
  2567. var frequency = freq !== undefined ? freq : 200,
  2568. last,
  2569. timer;
  2570. return function () {
  2571. var that = this,
  2572. now = +new Date(),
  2573. args = arguments;
  2574. if (last && now < last + frequency) {
  2575. clearTimeout(timer);
  2576. timer = setTimeout(function () {
  2577. last = undefined;
  2578. fn.apply(that, args);
  2579. }, frequency);
  2580. } else {
  2581. last = now;
  2582. fn.apply(that, args);
  2583. }
  2584. };
  2585. },
  2586. /**
  2587. * Escape a string such that it can be used in a regular expression
  2588. *
  2589. * @param {string} val string to escape
  2590. * @returns {string} escaped string
  2591. */
  2592. escapeRegex: function escapeRegex(val) {
  2593. return val.replace(_re_escape_regex, '\\$1');
  2594. }
  2595. };
  2596. /**
  2597. * Create a mapping object that allows camel case parameters to be looked up
  2598. * for their Hungarian counterparts. The mapping is stored in a private
  2599. * parameter called `_hungarianMap` which can be accessed on the source object.
  2600. * @param {object} o
  2601. * @memberof DataTable#oApi
  2602. */
  2603. function _fnHungarianMap(o) {
  2604. var hungarian = 'a aa ai ao as b fn i m o s ',
  2605. match,
  2606. newKey,
  2607. map = {};
  2608. $.each(o, function (key, val) {
  2609. match = key.match(/^([^A-Z]+?)([A-Z])/);
  2610. if (match && hungarian.indexOf(match[1] + ' ') !== -1) {
  2611. newKey = key.replace(match[0], match[2].toLowerCase());
  2612. map[newKey] = key;
  2613. if (match[1] === 'o') {
  2614. _fnHungarianMap(o[key]);
  2615. }
  2616. }
  2617. });
  2618. o._hungarianMap = map;
  2619. }
  2620. /**
  2621. * Convert from camel case parameters to Hungarian, based on a Hungarian map
  2622. * created by _fnHungarianMap.
  2623. * @param {object} src The model object which holds all parameters that can be
  2624. * mapped.
  2625. * @param {object} user The object to convert from camel case to Hungarian.
  2626. * @param {boolean} force When set to `true`, properties which already have a
  2627. * Hungarian value in the `user` object will be overwritten. Otherwise they
  2628. * won't be.
  2629. * @memberof DataTable#oApi
  2630. */
  2631. function _fnCamelToHungarian(src, user, force) {
  2632. if (!src._hungarianMap) {
  2633. _fnHungarianMap(src);
  2634. }
  2635. var hungarianKey;
  2636. $.each(user, function (key, val) {
  2637. hungarianKey = src._hungarianMap[key];
  2638. if (hungarianKey !== undefined && (force || user[hungarianKey] === undefined)) {
  2639. // For objects, we need to buzz down into the object to copy parameters
  2640. if (hungarianKey.charAt(0) === 'o') {
  2641. // Copy the camelCase options over to the hungarian
  2642. if (!user[hungarianKey]) {
  2643. user[hungarianKey] = {};
  2644. }
  2645. $.extend(true, user[hungarianKey], user[key]);
  2646. _fnCamelToHungarian(src[hungarianKey], user[hungarianKey], force);
  2647. } else {
  2648. user[hungarianKey] = user[key];
  2649. }
  2650. }
  2651. });
  2652. }
  2653. /**
  2654. * Language compatibility - when certain options are given, and others aren't, we
  2655. * need to duplicate the values over, in order to provide backwards compatibility
  2656. * with older language files.
  2657. * @param {object} oSettings dataTables settings object
  2658. * @memberof DataTable#oApi
  2659. */
  2660. function _fnLanguageCompat(lang) {
  2661. var defaults = DataTable.defaults.oLanguage;
  2662. var zeroRecords = lang.sZeroRecords;
  2663. /* Backwards compatibility - if there is no sEmptyTable given, then use the same as
  2664. * sZeroRecords - assuming that is given.
  2665. */
  2666. if (!lang.sEmptyTable && zeroRecords && defaults.sEmptyTable === "No data available in table") {
  2667. _fnMap(lang, lang, 'sZeroRecords', 'sEmptyTable');
  2668. }
  2669. /* Likewise with loading records */
  2670. if (!lang.sLoadingRecords && zeroRecords && defaults.sLoadingRecords === "Loading...") {
  2671. _fnMap(lang, lang, 'sZeroRecords', 'sLoadingRecords');
  2672. }
  2673. // Old parameter name of the thousands separator mapped onto the new
  2674. if (lang.sInfoThousands) {
  2675. lang.sThousands = lang.sInfoThousands;
  2676. }
  2677. var decimal = lang.sDecimal;
  2678. if (decimal) {
  2679. _addNumericSort(decimal);
  2680. }
  2681. }
  2682. /**
  2683. * Map one parameter onto another
  2684. * @param {object} o Object to map
  2685. * @param {*} knew The new parameter name
  2686. * @param {*} old The old parameter name
  2687. */
  2688. var _fnCompatMap = function _fnCompatMap(o, knew, old) {
  2689. if (o[knew] !== undefined) {
  2690. o[old] = o[knew];
  2691. }
  2692. };
  2693. /**
  2694. * Provide backwards compatibility for the main DT options. Note that the new
  2695. * options are mapped onto the old parameters, so this is an external interface
  2696. * change only.
  2697. * @param {object} init Object to map
  2698. */
  2699. function _fnCompatOpts(init) {
  2700. _fnCompatMap(init, 'ordering', 'bSort');
  2701. _fnCompatMap(init, 'orderMulti', 'bSortMulti');
  2702. _fnCompatMap(init, 'orderClasses', 'bSortClasses');
  2703. _fnCompatMap(init, 'orderCellsTop', 'bSortCellsTop');
  2704. _fnCompatMap(init, 'order', 'aaSorting');
  2705. _fnCompatMap(init, 'orderFixed', 'aaSortingFixed');
  2706. _fnCompatMap(init, 'paging', 'bPaginate');
  2707. _fnCompatMap(init, 'pagingType', 'sPaginationType');
  2708. _fnCompatMap(init, 'pageLength', 'iDisplayLength');
  2709. _fnCompatMap(init, 'searching', 'bFilter');
  2710. // Boolean initialisation of x-scrolling
  2711. if (typeof init.sScrollX === 'boolean') {
  2712. init.sScrollX = init.sScrollX ? '100%' : '';
  2713. }
  2714. if (typeof init.scrollX === 'boolean') {
  2715. init.scrollX = init.scrollX ? '100%' : '';
  2716. }
  2717. // Column search objects are in an array, so it needs to be converted
  2718. // element by element
  2719. var searchCols = init.aoSearchCols;
  2720. if (searchCols) {
  2721. for (var i = 0, ien = searchCols.length; i < ien; i++) {
  2722. if (searchCols[i]) {
  2723. _fnCamelToHungarian(DataTable.models.oSearch, searchCols[i]);
  2724. }
  2725. }
  2726. }
  2727. }
  2728. /**
  2729. * Provide backwards compatibility for column options. Note that the new options
  2730. * are mapped onto the old parameters, so this is an external interface change
  2731. * only.
  2732. * @param {object} init Object to map
  2733. */
  2734. function _fnCompatCols(init) {
  2735. _fnCompatMap(init, 'orderable', 'bSortable');
  2736. _fnCompatMap(init, 'orderData', 'aDataSort');
  2737. _fnCompatMap(init, 'orderSequence', 'asSorting');
  2738. _fnCompatMap(init, 'orderDataType', 'sortDataType');
  2739. // orderData can be given as an integer
  2740. var dataSort = init.aDataSort;
  2741. if (typeof dataSort === 'number' && !$.isArray(dataSort)) {
  2742. init.aDataSort = [dataSort];
  2743. }
  2744. }
  2745. /**
  2746. * Browser feature detection for capabilities, quirks
  2747. * @param {object} settings dataTables settings object
  2748. * @memberof DataTable#oApi
  2749. */
  2750. function _fnBrowserDetect(settings) {
  2751. // We don't need to do this every time DataTables is constructed, the values
  2752. // calculated are specific to the browser and OS configuration which we
  2753. // don't expect to change between initialisations
  2754. if (!DataTable.__browser) {
  2755. var browser = {};
  2756. DataTable.__browser = browser;
  2757. // Scrolling feature / quirks detection
  2758. var n = $('<div/>').css({
  2759. position: 'fixed',
  2760. top: 0,
  2761. left: $(window).scrollLeft() * -1, // allow for scrolling
  2762. height: 1,
  2763. width: 1,
  2764. overflow: 'hidden'
  2765. }).append($('<div/>').css({
  2766. position: 'absolute',
  2767. top: 1,
  2768. left: 1,
  2769. width: 100,
  2770. overflow: 'scroll'
  2771. }).append($('<div/>').css({
  2772. width: '100%',
  2773. height: 10
  2774. }))).appendTo('body');
  2775. var outer = n.children();
  2776. var inner = outer.children();
  2777. // Numbers below, in order, are:
  2778. // inner.offsetWidth, inner.clientWidth, outer.offsetWidth, outer.clientWidth
  2779. //
  2780. // IE6 XP: 100 100 100 83
  2781. // IE7 Vista: 100 100 100 83
  2782. // IE 8+ Windows: 83 83 100 83
  2783. // Evergreen Windows: 83 83 100 83
  2784. // Evergreen Mac with scrollbars: 85 85 100 85
  2785. // Evergreen Mac without scrollbars: 100 100 100 100
  2786. // Get scrollbar width
  2787. browser.barWidth = outer[0].offsetWidth - outer[0].clientWidth;
  2788. // IE6/7 will oversize a width 100% element inside a scrolling element, to
  2789. // include the width of the scrollbar, while other browsers ensure the inner
  2790. // element is contained without forcing scrolling
  2791. browser.bScrollOversize = inner[0].offsetWidth === 100 && outer[0].clientWidth !== 100;
  2792. // In rtl text layout, some browsers (most, but not all) will place the
  2793. // scrollbar on the left, rather than the right.
  2794. browser.bScrollbarLeft = Math.round(inner.offset().left) !== 1;
  2795. // IE8- don't provide height and width for getBoundingClientRect
  2796. browser.bBounding = n[0].getBoundingClientRect().width ? true : false;
  2797. n.remove();
  2798. }
  2799. $.extend(settings.oBrowser, DataTable.__browser);
  2800. settings.oScroll.iBarWidth = DataTable.__browser.barWidth;
  2801. }
  2802. /**
  2803. * Array.prototype reduce[Right] method, used for browsers which don't support
  2804. * JS 1.6. Done this way to reduce code size, since we iterate either way
  2805. * @param {object} settings dataTables settings object
  2806. * @memberof DataTable#oApi
  2807. */
  2808. function _fnReduce(that, fn, init, start, end, inc) {
  2809. var i = start,
  2810. value,
  2811. isSet = false;
  2812. if (init !== undefined) {
  2813. value = init;
  2814. isSet = true;
  2815. }
  2816. while (i !== end) {
  2817. if (!that.hasOwnProperty(i)) {
  2818. continue;
  2819. }
  2820. value = isSet ? fn(value, that[i], i, that) : that[i];
  2821. isSet = true;
  2822. i += inc;
  2823. }
  2824. return value;
  2825. }
  2826. /**
  2827. * Add a column to the list used for the table with default values
  2828. * @param {object} oSettings dataTables settings object
  2829. * @param {node} nTh The th element for this column
  2830. * @memberof DataTable#oApi
  2831. */
  2832. function _fnAddColumn(oSettings, nTh) {
  2833. // Add column to aoColumns array
  2834. var oDefaults = DataTable.defaults.column;
  2835. var iCol = oSettings.aoColumns.length;
  2836. var oCol = $.extend({}, DataTable.models.oColumn, oDefaults, {
  2837. "nTh": nTh ? nTh : document.createElement('th'),
  2838. "sTitle": oDefaults.sTitle ? oDefaults.sTitle : nTh ? nTh.innerHTML : '',
  2839. "aDataSort": oDefaults.aDataSort ? oDefaults.aDataSort : [iCol],
  2840. "mData": oDefaults.mData ? oDefaults.mData : iCol,
  2841. idx: iCol
  2842. });
  2843. oSettings.aoColumns.push(oCol);
  2844. // Add search object for column specific search. Note that the `searchCols[ iCol ]`
  2845. // passed into extend can be undefined. This allows the user to give a default
  2846. // with only some of the parameters defined, and also not give a default
  2847. var searchCols = oSettings.aoPreSearchCols;
  2848. searchCols[iCol] = $.extend({}, DataTable.models.oSearch, searchCols[iCol]);
  2849. // Use the default column options function to initialise classes etc
  2850. _fnColumnOptions(oSettings, iCol, $(nTh).data());
  2851. }
  2852. /**
  2853. * Apply options for a column
  2854. * @param {object} oSettings dataTables settings object
  2855. * @param {int} iCol column index to consider
  2856. * @param {object} oOptions object with sType, bVisible and bSearchable etc
  2857. * @memberof DataTable#oApi
  2858. */
  2859. function _fnColumnOptions(oSettings, iCol, oOptions) {
  2860. var oCol = oSettings.aoColumns[iCol];
  2861. var oClasses = oSettings.oClasses;
  2862. var th = $(oCol.nTh);
  2863. // Try to get width information from the DOM. We can't get it from CSS
  2864. // as we'd need to parse the CSS stylesheet. `width` option can override
  2865. if (!oCol.sWidthOrig) {
  2866. // Width attribute
  2867. oCol.sWidthOrig = th.attr('width') || null;
  2868. // Style attribute
  2869. var t = (th.attr('style') || '').match(/width:\s*(\d+[pxem%]+)/);
  2870. if (t) {
  2871. oCol.sWidthOrig = t[1];
  2872. }
  2873. }
  2874. /* User specified column options */
  2875. if (oOptions !== undefined && oOptions !== null) {
  2876. // Backwards compatibility
  2877. _fnCompatCols(oOptions);
  2878. // Map camel case parameters to their Hungarian counterparts
  2879. _fnCamelToHungarian(DataTable.defaults.column, oOptions);
  2880. /* Backwards compatibility for mDataProp */
  2881. if (oOptions.mDataProp !== undefined && !oOptions.mData) {
  2882. oOptions.mData = oOptions.mDataProp;
  2883. }
  2884. if (oOptions.sType) {
  2885. oCol._sManualType = oOptions.sType;
  2886. }
  2887. // `class` is a reserved word in Javascript, so we need to provide
  2888. // the ability to use a valid name for the camel case input
  2889. if (oOptions.className && !oOptions.sClass) {
  2890. oOptions.sClass = oOptions.className;
  2891. }
  2892. if (oOptions.sClass) {
  2893. th.addClass(oOptions.sClass);
  2894. }
  2895. $.extend(oCol, oOptions);
  2896. _fnMap(oCol, oOptions, "sWidth", "sWidthOrig");
  2897. /* iDataSort to be applied (backwards compatibility), but aDataSort will take
  2898. * priority if defined
  2899. */
  2900. if (oOptions.iDataSort !== undefined) {
  2901. oCol.aDataSort = [oOptions.iDataSort];
  2902. }
  2903. _fnMap(oCol, oOptions, "aDataSort");
  2904. }
  2905. /* Cache the data get and set functions for speed */
  2906. var mDataSrc = oCol.mData;
  2907. var mData = _fnGetObjectDataFn(mDataSrc);
  2908. var mRender = oCol.mRender ? _fnGetObjectDataFn(oCol.mRender) : null;
  2909. var attrTest = function attrTest(src) {
  2910. return typeof src === 'string' && src.indexOf('@') !== -1;
  2911. };
  2912. oCol._bAttrSrc = $.isPlainObject(mDataSrc) && (attrTest(mDataSrc.sort) || attrTest(mDataSrc.type) || attrTest(mDataSrc.filter));
  2913. oCol._setter = null;
  2914. oCol.fnGetData = function (rowData, type, meta) {
  2915. var innerData = mData(rowData, type, undefined, meta);
  2916. return mRender && type ? mRender(innerData, type, rowData, meta) : innerData;
  2917. };
  2918. oCol.fnSetData = function (rowData, val, meta) {
  2919. return _fnSetObjectDataFn(mDataSrc)(rowData, val, meta);
  2920. };
  2921. // Indicate if DataTables should read DOM data as an object or array
  2922. // Used in _fnGetRowElements
  2923. if (typeof mDataSrc !== 'number') {
  2924. oSettings._rowReadObject = true;
  2925. }
  2926. /* Feature sorting overrides column specific when off */
  2927. if (!oSettings.oFeatures.bSort) {
  2928. oCol.bSortable = false;
  2929. th.addClass(oClasses.sSortableNone); // Have to add class here as order event isn't called
  2930. }
  2931. /* Check that the class assignment is correct for sorting */
  2932. var bAsc = $.inArray('asc', oCol.asSorting) !== -1;
  2933. var bDesc = $.inArray('desc', oCol.asSorting) !== -1;
  2934. if (!oCol.bSortable || !bAsc && !bDesc) {
  2935. oCol.sSortingClass = oClasses.sSortableNone;
  2936. oCol.sSortingClassJUI = "";
  2937. } else if (bAsc && !bDesc) {
  2938. oCol.sSortingClass = oClasses.sSortableAsc;
  2939. oCol.sSortingClassJUI = oClasses.sSortJUIAscAllowed;
  2940. } else if (!bAsc && bDesc) {
  2941. oCol.sSortingClass = oClasses.sSortableDesc;
  2942. oCol.sSortingClassJUI = oClasses.sSortJUIDescAllowed;
  2943. } else {
  2944. oCol.sSortingClass = oClasses.sSortable;
  2945. oCol.sSortingClassJUI = oClasses.sSortJUI;
  2946. }
  2947. }
  2948. /**
  2949. * Adjust the table column widths for new data. Note: you would probably want to
  2950. * do a redraw after calling this function!
  2951. * @param {object} settings dataTables settings object
  2952. * @memberof DataTable#oApi
  2953. */
  2954. function _fnAdjustColumnSizing(settings) {
  2955. /* Not interested in doing column width calculation if auto-width is disabled */
  2956. if (settings.oFeatures.bAutoWidth !== false) {
  2957. var columns = settings.aoColumns;
  2958. _fnCalculateColumnWidths(settings);
  2959. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  2960. columns[i].nTh.style.width = columns[i].sWidth;
  2961. }
  2962. }
  2963. var scroll = settings.oScroll;
  2964. if (scroll.sY !== '' || scroll.sX !== '') {
  2965. _fnScrollDraw(settings);
  2966. }
  2967. _fnCallbackFire(settings, null, 'column-sizing', [settings]);
  2968. }
  2969. /**
  2970. * Covert the index of a visible column to the index in the data array (take account
  2971. * of hidden columns)
  2972. * @param {object} oSettings dataTables settings object
  2973. * @param {int} iMatch Visible column index to lookup
  2974. * @returns {int} i the data index
  2975. * @memberof DataTable#oApi
  2976. */
  2977. function _fnVisibleToColumnIndex(oSettings, iMatch) {
  2978. var aiVis = _fnGetColumns(oSettings, 'bVisible');
  2979. return typeof aiVis[iMatch] === 'number' ? aiVis[iMatch] : null;
  2980. }
  2981. /**
  2982. * Covert the index of an index in the data array and convert it to the visible
  2983. * column index (take account of hidden columns)
  2984. * @param {int} iMatch Column index to lookup
  2985. * @param {object} oSettings dataTables settings object
  2986. * @returns {int} i the data index
  2987. * @memberof DataTable#oApi
  2988. */
  2989. function _fnColumnIndexToVisible(oSettings, iMatch) {
  2990. var aiVis = _fnGetColumns(oSettings, 'bVisible');
  2991. var iPos = $.inArray(iMatch, aiVis);
  2992. return iPos !== -1 ? iPos : null;
  2993. }
  2994. /**
  2995. * Get the number of visible columns
  2996. * @param {object} oSettings dataTables settings object
  2997. * @returns {int} i the number of visible columns
  2998. * @memberof DataTable#oApi
  2999. */
  3000. function _fnVisbleColumns(oSettings) {
  3001. var vis = 0;
  3002. // No reduce in IE8, use a loop for now
  3003. $.each(oSettings.aoColumns, function (i, col) {
  3004. if (col.bVisible && $(col.nTh).css('display') !== 'none') {
  3005. vis++;
  3006. }
  3007. });
  3008. return vis;
  3009. }
  3010. /**
  3011. * Get an array of column indexes that match a given property
  3012. * @param {object} oSettings dataTables settings object
  3013. * @param {string} sParam Parameter in aoColumns to look for - typically
  3014. * bVisible or bSearchable
  3015. * @returns {array} Array of indexes with matched properties
  3016. * @memberof DataTable#oApi
  3017. */
  3018. function _fnGetColumns(oSettings, sParam) {
  3019. var a = [];
  3020. $.map(oSettings.aoColumns, function (val, i) {
  3021. if (val[sParam]) {
  3022. a.push(i);
  3023. }
  3024. });
  3025. return a;
  3026. }
  3027. /**
  3028. * Calculate the 'type' of a column
  3029. * @param {object} settings dataTables settings object
  3030. * @memberof DataTable#oApi
  3031. */
  3032. function _fnColumnTypes(settings) {
  3033. var columns = settings.aoColumns;
  3034. var data = settings.aoData;
  3035. var types = DataTable.ext.type.detect;
  3036. var i, ien, j, jen, k, ken;
  3037. var col, cell, detectedType, cache;
  3038. // For each column, spin over the
  3039. for (i = 0, ien = columns.length; i < ien; i++) {
  3040. col = columns[i];
  3041. cache = [];
  3042. if (!col.sType && col._sManualType) {
  3043. col.sType = col._sManualType;
  3044. } else if (!col.sType) {
  3045. for (j = 0, jen = types.length; j < jen; j++) {
  3046. for (k = 0, ken = data.length; k < ken; k++) {
  3047. // Use a cache array so we only need to get the type data
  3048. // from the formatter once (when using multiple detectors)
  3049. if (cache[k] === undefined) {
  3050. cache[k] = _fnGetCellData(settings, k, i, 'type');
  3051. }
  3052. detectedType = types[j](cache[k], settings);
  3053. // If null, then this type can't apply to this column, so
  3054. // rather than testing all cells, break out. There is an
  3055. // exception for the last type which is `html`. We need to
  3056. // scan all rows since it is possible to mix string and HTML
  3057. // types
  3058. if (!detectedType && j !== types.length - 1) {
  3059. break;
  3060. }
  3061. // Only a single match is needed for html type since it is
  3062. // bottom of the pile and very similar to string
  3063. if (detectedType === 'html') {
  3064. break;
  3065. }
  3066. }
  3067. // Type is valid for all data points in the column - use this
  3068. // type
  3069. if (detectedType) {
  3070. col.sType = detectedType;
  3071. break;
  3072. }
  3073. }
  3074. // Fall back - if no type was detected, always use string
  3075. if (!col.sType) {
  3076. col.sType = 'string';
  3077. }
  3078. }
  3079. }
  3080. }
  3081. /**
  3082. * Take the column definitions and static columns arrays and calculate how
  3083. * they relate to column indexes. The callback function will then apply the
  3084. * definition found for a column to a suitable configuration object.
  3085. * @param {object} oSettings dataTables settings object
  3086. * @param {array} aoColDefs The aoColumnDefs array that is to be applied
  3087. * @param {array} aoCols The aoColumns array that defines columns individually
  3088. * @param {function} fn Callback function - takes two parameters, the calculated
  3089. * column index and the definition for that column.
  3090. * @memberof DataTable#oApi
  3091. */
  3092. function _fnApplyColumnDefs(oSettings, aoColDefs, aoCols, fn) {
  3093. var i, iLen, j, jLen, k, kLen, def;
  3094. var columns = oSettings.aoColumns;
  3095. // Column definitions with aTargets
  3096. if (aoColDefs) {
  3097. /* Loop over the definitions array - loop in reverse so first instance has priority */
  3098. for (i = aoColDefs.length - 1; i >= 0; i--) {
  3099. def = aoColDefs[i];
  3100. /* Each definition can target multiple columns, as it is an array */
  3101. var aTargets = def.targets !== undefined ? def.targets : def.aTargets;
  3102. if (!$.isArray(aTargets)) {
  3103. aTargets = [aTargets];
  3104. }
  3105. for (j = 0, jLen = aTargets.length; j < jLen; j++) {
  3106. if (typeof aTargets[j] === 'number' && aTargets[j] >= 0) {
  3107. /* Add columns that we don't yet know about */
  3108. while (columns.length <= aTargets[j]) {
  3109. _fnAddColumn(oSettings);
  3110. }
  3111. /* Integer, basic index */
  3112. fn(aTargets[j], def);
  3113. } else if (typeof aTargets[j] === 'number' && aTargets[j] < 0) {
  3114. /* Negative integer, right to left column counting */
  3115. fn(columns.length + aTargets[j], def);
  3116. } else if (typeof aTargets[j] === 'string') {
  3117. /* Class name matching on TH element */
  3118. for (k = 0, kLen = columns.length; k < kLen; k++) {
  3119. if (aTargets[j] == "_all" || $(columns[k].nTh).hasClass(aTargets[j])) {
  3120. fn(k, def);
  3121. }
  3122. }
  3123. }
  3124. }
  3125. }
  3126. }
  3127. // Statically defined columns array
  3128. if (aoCols) {
  3129. for (i = 0, iLen = aoCols.length; i < iLen; i++) {
  3130. fn(i, aoCols[i]);
  3131. }
  3132. }
  3133. }
  3134. /**
  3135. * Add a data array to the table, creating DOM node etc. This is the parallel to
  3136. * _fnGatherData, but for adding rows from a Javascript source, rather than a
  3137. * DOM source.
  3138. * @param {object} oSettings dataTables settings object
  3139. * @param {array} aData data array to be added
  3140. * @param {node} [nTr] TR element to add to the table - optional. If not given,
  3141. * DataTables will create a row automatically
  3142. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  3143. * if nTr is.
  3144. * @returns {int} >=0 if successful (index of new aoData entry), -1 if failed
  3145. * @memberof DataTable#oApi
  3146. */
  3147. function _fnAddData(oSettings, aDataIn, nTr, anTds) {
  3148. /* Create the object for storing information about this new row */
  3149. var iRow = oSettings.aoData.length;
  3150. var oData = $.extend(true, {}, DataTable.models.oRow, {
  3151. src: nTr ? 'dom' : 'data',
  3152. idx: iRow
  3153. });
  3154. oData._aData = aDataIn;
  3155. oSettings.aoData.push(oData);
  3156. /* Create the cells */
  3157. var nTd, sThisType;
  3158. var columns = oSettings.aoColumns;
  3159. // Invalidate the column types as the new data needs to be revalidated
  3160. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  3161. columns[i].sType = null;
  3162. }
  3163. /* Add to the display array */
  3164. oSettings.aiDisplayMaster.push(iRow);
  3165. var id = oSettings.rowIdFn(aDataIn);
  3166. if (id !== undefined) {
  3167. oSettings.aIds[id] = oData;
  3168. }
  3169. /* Create the DOM information, or register it if already present */
  3170. if (nTr || !oSettings.oFeatures.bDeferRender) {
  3171. _fnCreateTr(oSettings, iRow, nTr, anTds);
  3172. }
  3173. return iRow;
  3174. }
  3175. /**
  3176. * Add one or more TR elements to the table. Generally we'd expect to
  3177. * use this for reading data from a DOM sourced table, but it could be
  3178. * used for an TR element. Note that if a TR is given, it is used (i.e.
  3179. * it is not cloned).
  3180. * @param {object} settings dataTables settings object
  3181. * @param {array|node|jQuery} trs The TR element(s) to add to the table
  3182. * @returns {array} Array of indexes for the added rows
  3183. * @memberof DataTable#oApi
  3184. */
  3185. function _fnAddTr(settings, trs) {
  3186. var row;
  3187. // Allow an individual node to be passed in
  3188. if (!(trs instanceof $)) {
  3189. trs = $(trs);
  3190. }
  3191. return trs.map(function (i, el) {
  3192. row = _fnGetRowElements(settings, el);
  3193. return _fnAddData(settings, row.data, el, row.cells);
  3194. });
  3195. }
  3196. /**
  3197. * Take a TR element and convert it to an index in aoData
  3198. * @param {object} oSettings dataTables settings object
  3199. * @param {node} n the TR element to find
  3200. * @returns {int} index if the node is found, null if not
  3201. * @memberof DataTable#oApi
  3202. */
  3203. function _fnNodeToDataIndex(oSettings, n) {
  3204. return n._DT_RowIndex !== undefined ? n._DT_RowIndex : null;
  3205. }
  3206. /**
  3207. * Take a TD element and convert it into a column data index (not the visible index)
  3208. * @param {object} oSettings dataTables settings object
  3209. * @param {int} iRow The row number the TD/TH can be found in
  3210. * @param {node} n The TD/TH element to find
  3211. * @returns {int} index if the node is found, -1 if not
  3212. * @memberof DataTable#oApi
  3213. */
  3214. function _fnNodeToColumnIndex(oSettings, iRow, n) {
  3215. return $.inArray(n, oSettings.aoData[iRow].anCells);
  3216. }
  3217. /**
  3218. * Get the data for a given cell from the internal cache, taking into account data mapping
  3219. * @param {object} settings dataTables settings object
  3220. * @param {int} rowIdx aoData row id
  3221. * @param {int} colIdx Column index
  3222. * @param {string} type data get type ('display', 'type' 'filter' 'sort')
  3223. * @returns {*} Cell data
  3224. * @memberof DataTable#oApi
  3225. */
  3226. function _fnGetCellData(settings, rowIdx, colIdx, type) {
  3227. var draw = settings.iDraw;
  3228. var col = settings.aoColumns[colIdx];
  3229. var rowData = settings.aoData[rowIdx]._aData;
  3230. var defaultContent = col.sDefaultContent;
  3231. var cellData = col.fnGetData(rowData, type, {
  3232. settings: settings,
  3233. row: rowIdx,
  3234. col: colIdx
  3235. });
  3236. if (cellData === undefined) {
  3237. if (settings.iDrawError != draw && defaultContent === null) {
  3238. _fnLog(settings, 0, "Requested unknown parameter " + (typeof col.mData == 'function' ? '{function}' : "'" + col.mData + "'") + " for row " + rowIdx + ", column " + colIdx, 4);
  3239. settings.iDrawError = draw;
  3240. }
  3241. return defaultContent;
  3242. }
  3243. // When the data source is null and a specific data type is requested (i.e.
  3244. // not the original data), we can use default column data
  3245. if ((cellData === rowData || cellData === null) && defaultContent !== null && type !== undefined) {
  3246. cellData = defaultContent;
  3247. } else if (typeof cellData === 'function') {
  3248. // If the data source is a function, then we run it and use the return,
  3249. // executing in the scope of the data object (for instances)
  3250. return cellData.call(rowData);
  3251. }
  3252. if (cellData === null && type == 'display') {
  3253. return '';
  3254. }
  3255. return cellData;
  3256. }
  3257. /**
  3258. * Set the value for a specific cell, into the internal data cache
  3259. * @param {object} settings dataTables settings object
  3260. * @param {int} rowIdx aoData row id
  3261. * @param {int} colIdx Column index
  3262. * @param {*} val Value to set
  3263. * @memberof DataTable#oApi
  3264. */
  3265. function _fnSetCellData(settings, rowIdx, colIdx, val) {
  3266. var col = settings.aoColumns[colIdx];
  3267. var rowData = settings.aoData[rowIdx]._aData;
  3268. col.fnSetData(rowData, val, {
  3269. settings: settings,
  3270. row: rowIdx,
  3271. col: colIdx
  3272. });
  3273. }
  3274. // Private variable that is used to match action syntax in the data property object
  3275. var __reArray = /\[.*?\]$/;
  3276. var __reFn = /\(\)$/;
  3277. /**
  3278. * Split string on periods, taking into account escaped periods
  3279. * @param {string} str String to split
  3280. * @return {array} Split string
  3281. */
  3282. function _fnSplitObjNotation(str) {
  3283. return $.map(str.match(/(\\.|[^\.])+/g) || [''], function (s) {
  3284. return s.replace(/\\\./g, '.');
  3285. });
  3286. }
  3287. /**
  3288. * Return a function that can be used to get data from a source object, taking
  3289. * into account the ability to use nested objects as a source
  3290. * @param {string|int|function} mSource The data source for the object
  3291. * @returns {function} Data get function
  3292. * @memberof DataTable#oApi
  3293. */
  3294. function _fnGetObjectDataFn(mSource) {
  3295. if ($.isPlainObject(mSource)) {
  3296. /* Build an object of get functions, and wrap them in a single call */
  3297. var o = {};
  3298. $.each(mSource, function (key, val) {
  3299. if (val) {
  3300. o[key] = _fnGetObjectDataFn(val);
  3301. }
  3302. });
  3303. return function (data, type, row, meta) {
  3304. var t = o[type] || o._;
  3305. return t !== undefined ? t(data, type, row, meta) : data;
  3306. };
  3307. } else if (mSource === null) {
  3308. /* Give an empty string for rendering / sorting etc */
  3309. return function (data) {
  3310. // type, row and meta also passed, but not used
  3311. return data;
  3312. };
  3313. } else if (typeof mSource === 'function') {
  3314. return function (data, type, row, meta) {
  3315. return mSource(data, type, row, meta);
  3316. };
  3317. } else if (typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1)) {
  3318. /* If there is a . in the source string then the data source is in a
  3319. * nested object so we loop over the data for each level to get the next
  3320. * level down. On each loop we test for undefined, and if found immediately
  3321. * return. This allows entire objects to be missing and sDefaultContent to
  3322. * be used if defined, rather than throwing an error
  3323. */
  3324. var fetchData = function fetchData(data, type, src) {
  3325. var arrayNotation, funcNotation, out, innerSrc;
  3326. if (src !== "") {
  3327. var a = _fnSplitObjNotation(src);
  3328. for (var i = 0, iLen = a.length; i < iLen; i++) {
  3329. // Check if we are dealing with special notation
  3330. arrayNotation = a[i].match(__reArray);
  3331. funcNotation = a[i].match(__reFn);
  3332. if (arrayNotation) {
  3333. // Array notation
  3334. a[i] = a[i].replace(__reArray, '');
  3335. // Condition allows simply [] to be passed in
  3336. if (a[i] !== "") {
  3337. data = data[a[i]];
  3338. }
  3339. out = [];
  3340. // Get the remainder of the nested object to get
  3341. a.splice(0, i + 1);
  3342. innerSrc = a.join('.');
  3343. // Traverse each entry in the array getting the properties requested
  3344. if ($.isArray(data)) {
  3345. for (var j = 0, jLen = data.length; j < jLen; j++) {
  3346. out.push(fetchData(data[j], type, innerSrc));
  3347. }
  3348. }
  3349. // If a string is given in between the array notation indicators, that
  3350. // is used to join the strings together, otherwise an array is returned
  3351. var join = arrayNotation[0].substring(1, arrayNotation[0].length - 1);
  3352. data = join === "" ? out : out.join(join);
  3353. // The inner call to fetchData has already traversed through the remainder
  3354. // of the source requested, so we exit from the loop
  3355. break;
  3356. } else if (funcNotation) {
  3357. // Function call
  3358. a[i] = a[i].replace(__reFn, '');
  3359. data = data[a[i]]();
  3360. continue;
  3361. }
  3362. if (data === null || data[a[i]] === undefined) {
  3363. return undefined;
  3364. }
  3365. data = data[a[i]];
  3366. }
  3367. }
  3368. return data;
  3369. };
  3370. return function (data, type) {
  3371. // row and meta also passed, but not used
  3372. return fetchData(data, type, mSource);
  3373. };
  3374. } else {
  3375. /* Array or flat object mapping */
  3376. return function (data, type) {
  3377. // row and meta also passed, but not used
  3378. return data[mSource];
  3379. };
  3380. }
  3381. }
  3382. /**
  3383. * Return a function that can be used to set data from a source object, taking
  3384. * into account the ability to use nested objects as a source
  3385. * @param {string|int|function} mSource The data source for the object
  3386. * @returns {function} Data set function
  3387. * @memberof DataTable#oApi
  3388. */
  3389. function _fnSetObjectDataFn(mSource) {
  3390. if ($.isPlainObject(mSource)) {
  3391. /* Unlike get, only the underscore (global) option is used for for
  3392. * setting data since we don't know the type here. This is why an object
  3393. * option is not documented for `mData` (which is read/write), but it is
  3394. * for `mRender` which is read only.
  3395. */
  3396. return _fnSetObjectDataFn(mSource._);
  3397. } else if (mSource === null) {
  3398. /* Nothing to do when the data source is null */
  3399. return function () {};
  3400. } else if (typeof mSource === 'function') {
  3401. return function (data, val, meta) {
  3402. mSource(data, 'set', val, meta);
  3403. };
  3404. } else if (typeof mSource === 'string' && (mSource.indexOf('.') !== -1 || mSource.indexOf('[') !== -1 || mSource.indexOf('(') !== -1)) {
  3405. /* Like the get, we need to get data from a nested object */
  3406. var setData = function setData(data, val, src) {
  3407. var a = _fnSplitObjNotation(src),
  3408. b;
  3409. var aLast = a[a.length - 1];
  3410. var arrayNotation, funcNotation, o, innerSrc;
  3411. for (var i = 0, iLen = a.length - 1; i < iLen; i++) {
  3412. // Check if we are dealing with an array notation request
  3413. arrayNotation = a[i].match(__reArray);
  3414. funcNotation = a[i].match(__reFn);
  3415. if (arrayNotation) {
  3416. a[i] = a[i].replace(__reArray, '');
  3417. data[a[i]] = [];
  3418. // Get the remainder of the nested object to set so we can recurse
  3419. b = a.slice();
  3420. b.splice(0, i + 1);
  3421. innerSrc = b.join('.');
  3422. // Traverse each entry in the array setting the properties requested
  3423. if ($.isArray(val)) {
  3424. for (var j = 0, jLen = val.length; j < jLen; j++) {
  3425. o = {};
  3426. setData(o, val[j], innerSrc);
  3427. data[a[i]].push(o);
  3428. }
  3429. } else {
  3430. // We've been asked to save data to an array, but it
  3431. // isn't array data to be saved. Best that can be done
  3432. // is to just save the value.
  3433. data[a[i]] = val;
  3434. }
  3435. // The inner call to setData has already traversed through the remainder
  3436. // of the source and has set the data, thus we can exit here
  3437. return;
  3438. } else if (funcNotation) {
  3439. // Function call
  3440. a[i] = a[i].replace(__reFn, '');
  3441. data = data[a[i]](val);
  3442. }
  3443. // If the nested object doesn't currently exist - since we are
  3444. // trying to set the value - create it
  3445. if (data[a[i]] === null || data[a[i]] === undefined) {
  3446. data[a[i]] = {};
  3447. }
  3448. data = data[a[i]];
  3449. }
  3450. // Last item in the input - i.e, the actual set
  3451. if (aLast.match(__reFn)) {
  3452. // Function call
  3453. data = data[aLast.replace(__reFn, '')](val);
  3454. } else {
  3455. // If array notation is used, we just want to strip it and use the property name
  3456. // and assign the value. If it isn't used, then we get the result we want anyway
  3457. data[aLast.replace(__reArray, '')] = val;
  3458. }
  3459. };
  3460. return function (data, val) {
  3461. // meta is also passed in, but not used
  3462. return setData(data, val, mSource);
  3463. };
  3464. } else {
  3465. /* Array or flat object mapping */
  3466. return function (data, val) {
  3467. // meta is also passed in, but not used
  3468. data[mSource] = val;
  3469. };
  3470. }
  3471. }
  3472. /**
  3473. * Return an array with the full table data
  3474. * @param {object} oSettings dataTables settings object
  3475. * @returns array {array} aData Master data array
  3476. * @memberof DataTable#oApi
  3477. */
  3478. function _fnGetDataMaster(settings) {
  3479. return _pluck(settings.aoData, '_aData');
  3480. }
  3481. /**
  3482. * Nuke the table
  3483. * @param {object} oSettings dataTables settings object
  3484. * @memberof DataTable#oApi
  3485. */
  3486. function _fnClearTable(settings) {
  3487. settings.aoData.length = 0;
  3488. settings.aiDisplayMaster.length = 0;
  3489. settings.aiDisplay.length = 0;
  3490. settings.aIds = {};
  3491. }
  3492. /**
  3493. * Take an array of integers (index array) and remove a target integer (value - not
  3494. * the key!)
  3495. * @param {array} a Index array to target
  3496. * @param {int} iTarget value to find
  3497. * @memberof DataTable#oApi
  3498. */
  3499. function _fnDeleteIndex(a, iTarget, splice) {
  3500. var iTargetIndex = -1;
  3501. for (var i = 0, iLen = a.length; i < iLen; i++) {
  3502. if (a[i] == iTarget) {
  3503. iTargetIndex = i;
  3504. } else if (a[i] > iTarget) {
  3505. a[i]--;
  3506. }
  3507. }
  3508. if (iTargetIndex != -1 && splice === undefined) {
  3509. a.splice(iTargetIndex, 1);
  3510. }
  3511. }
  3512. /**
  3513. * Mark cached data as invalid such that a re-read of the data will occur when
  3514. * the cached data is next requested. Also update from the data source object.
  3515. *
  3516. * @param {object} settings DataTables settings object
  3517. * @param {int} rowIdx Row index to invalidate
  3518. * @param {string} [src] Source to invalidate from: undefined, 'auto', 'dom'
  3519. * or 'data'
  3520. * @param {int} [colIdx] Column index to invalidate. If undefined the whole
  3521. * row will be invalidated
  3522. * @memberof DataTable#oApi
  3523. *
  3524. * @todo For the modularisation of v1.11 this will need to become a callback, so
  3525. * the sort and filter methods can subscribe to it. That will required
  3526. * initialisation options for sorting, which is why it is not already baked in
  3527. */
  3528. function _fnInvalidate(settings, rowIdx, src, colIdx) {
  3529. var row = settings.aoData[rowIdx];
  3530. var i, ien;
  3531. var cellWrite = function cellWrite(cell, col) {
  3532. // This is very frustrating, but in IE if you just write directly
  3533. // to innerHTML, and elements that are overwritten are GC'ed,
  3534. // even if there is a reference to them elsewhere
  3535. while (cell.childNodes.length) {
  3536. cell.removeChild(cell.firstChild);
  3537. }
  3538. cell.innerHTML = _fnGetCellData(settings, rowIdx, col, 'display');
  3539. };
  3540. // Are we reading last data from DOM or the data object?
  3541. if (src === 'dom' || (!src || src === 'auto') && row.src === 'dom') {
  3542. // Read the data from the DOM
  3543. row._aData = _fnGetRowElements(settings, row, colIdx, colIdx === undefined ? undefined : row._aData).data;
  3544. } else {
  3545. // Reading from data object, update the DOM
  3546. var cells = row.anCells;
  3547. if (cells) {
  3548. if (colIdx !== undefined) {
  3549. cellWrite(cells[colIdx], colIdx);
  3550. } else {
  3551. for (i = 0, ien = cells.length; i < ien; i++) {
  3552. cellWrite(cells[i], i);
  3553. }
  3554. }
  3555. }
  3556. }
  3557. // For both row and cell invalidation, the cached data for sorting and
  3558. // filtering is nulled out
  3559. row._aSortData = null;
  3560. row._aFilterData = null;
  3561. // Invalidate the type for a specific column (if given) or all columns since
  3562. // the data might have changed
  3563. var cols = settings.aoColumns;
  3564. if (colIdx !== undefined) {
  3565. cols[colIdx].sType = null;
  3566. } else {
  3567. for (i = 0, ien = cols.length; i < ien; i++) {
  3568. cols[i].sType = null;
  3569. }
  3570. // Update DataTables special `DT_*` attributes for the row
  3571. _fnRowAttributes(settings, row);
  3572. }
  3573. }
  3574. /**
  3575. * Build a data source object from an HTML row, reading the contents of the
  3576. * cells that are in the row.
  3577. *
  3578. * @param {object} settings DataTables settings object
  3579. * @param {node|object} TR element from which to read data or existing row
  3580. * object from which to re-read the data from the cells
  3581. * @param {int} [colIdx] Optional column index
  3582. * @param {array|object} [d] Data source object. If `colIdx` is given then this
  3583. * parameter should also be given and will be used to write the data into.
  3584. * Only the column in question will be written
  3585. * @returns {object} Object with two parameters: `data` the data read, in
  3586. * document order, and `cells` and array of nodes (they can be useful to the
  3587. * caller, so rather than needing a second traversal to get them, just return
  3588. * them from here).
  3589. * @memberof DataTable#oApi
  3590. */
  3591. function _fnGetRowElements(settings, row, colIdx, d) {
  3592. var tds = [],
  3593. td = row.firstChild,
  3594. name,
  3595. col,
  3596. o,
  3597. i = 0,
  3598. contents,
  3599. columns = settings.aoColumns,
  3600. objectRead = settings._rowReadObject;
  3601. // Allow the data object to be passed in, or construct
  3602. d = d !== undefined ? d : objectRead ? {} : [];
  3603. var attr = function attr(str, td) {
  3604. if (typeof str === 'string') {
  3605. var idx = str.indexOf('@');
  3606. if (idx !== -1) {
  3607. var attr = str.substring(idx + 1);
  3608. var setter = _fnSetObjectDataFn(str);
  3609. setter(d, td.getAttribute(attr));
  3610. }
  3611. }
  3612. };
  3613. // Read data from a cell and store into the data object
  3614. var cellProcess = function cellProcess(cell) {
  3615. if (colIdx === undefined || colIdx === i) {
  3616. col = columns[i];
  3617. contents = $.trim(cell.innerHTML);
  3618. if (col && col._bAttrSrc) {
  3619. var setter = _fnSetObjectDataFn(col.mData._);
  3620. setter(d, contents);
  3621. attr(col.mData.sort, cell);
  3622. attr(col.mData.type, cell);
  3623. attr(col.mData.filter, cell);
  3624. } else {
  3625. // Depending on the `data` option for the columns the data can
  3626. // be read to either an object or an array.
  3627. if (objectRead) {
  3628. if (!col._setter) {
  3629. // Cache the setter function
  3630. col._setter = _fnSetObjectDataFn(col.mData);
  3631. }
  3632. col._setter(d, contents);
  3633. } else {
  3634. d[i] = contents;
  3635. }
  3636. }
  3637. }
  3638. i++;
  3639. };
  3640. if (td) {
  3641. // `tr` element was passed in
  3642. while (td) {
  3643. name = td.nodeName.toUpperCase();
  3644. if (name == "TD" || name == "TH") {
  3645. cellProcess(td);
  3646. tds.push(td);
  3647. }
  3648. td = td.nextSibling;
  3649. }
  3650. } else {
  3651. // Existing row object passed in
  3652. tds = row.anCells;
  3653. for (var j = 0, jen = tds.length; j < jen; j++) {
  3654. cellProcess(tds[j]);
  3655. }
  3656. }
  3657. // Read the ID from the DOM if present
  3658. var rowNode = row.firstChild ? row : row.nTr;
  3659. if (rowNode) {
  3660. var id = rowNode.getAttribute('id');
  3661. if (id) {
  3662. _fnSetObjectDataFn(settings.rowId)(d, id);
  3663. }
  3664. }
  3665. return {
  3666. data: d,
  3667. cells: tds
  3668. };
  3669. }
  3670. /**
  3671. * Create a new TR element (and it's TD children) for a row
  3672. * @param {object} oSettings dataTables settings object
  3673. * @param {int} iRow Row to consider
  3674. * @param {node} [nTrIn] TR element to add to the table - optional. If not given,
  3675. * DataTables will create a row automatically
  3676. * @param {array} [anTds] Array of TD|TH elements for the row - must be given
  3677. * if nTr is.
  3678. * @memberof DataTable#oApi
  3679. */
  3680. function _fnCreateTr(oSettings, iRow, nTrIn, anTds) {
  3681. var row = oSettings.aoData[iRow],
  3682. rowData = row._aData,
  3683. cells = [],
  3684. nTr,
  3685. nTd,
  3686. oCol,
  3687. i,
  3688. iLen;
  3689. if (row.nTr === null) {
  3690. nTr = nTrIn || document.createElement('tr');
  3691. row.nTr = nTr;
  3692. row.anCells = cells;
  3693. /* Use a private property on the node to allow reserve mapping from the node
  3694. * to the aoData array for fast look up
  3695. */
  3696. nTr._DT_RowIndex = iRow;
  3697. /* Special parameters can be given by the data source to be used on the row */
  3698. _fnRowAttributes(oSettings, row);
  3699. /* Process each column */
  3700. for (i = 0, iLen = oSettings.aoColumns.length; i < iLen; i++) {
  3701. oCol = oSettings.aoColumns[i];
  3702. nTd = nTrIn ? anTds[i] : document.createElement(oCol.sCellType);
  3703. nTd._DT_CellIndex = {
  3704. row: iRow,
  3705. column: i
  3706. };
  3707. cells.push(nTd);
  3708. // Need to create the HTML if new, or if a rendering function is defined
  3709. if ((!nTrIn || oCol.mRender || oCol.mData !== i) && (!$.isPlainObject(oCol.mData) || oCol.mData._ !== i + '.display')) {
  3710. nTd.innerHTML = _fnGetCellData(oSettings, iRow, i, 'display');
  3711. }
  3712. /* Add user defined class */
  3713. if (oCol.sClass) {
  3714. nTd.className += ' ' + oCol.sClass;
  3715. }
  3716. // Visibility - add or remove as required
  3717. if (oCol.bVisible && !nTrIn) {
  3718. nTr.appendChild(nTd);
  3719. } else if (!oCol.bVisible && nTrIn) {
  3720. nTd.parentNode.removeChild(nTd);
  3721. }
  3722. if (oCol.fnCreatedCell) {
  3723. oCol.fnCreatedCell.call(oSettings.oInstance, nTd, _fnGetCellData(oSettings, iRow, i), rowData, iRow, i);
  3724. }
  3725. }
  3726. _fnCallbackFire(oSettings, 'aoRowCreatedCallback', null, [nTr, rowData, iRow]);
  3727. }
  3728. // Remove once webkit bug 131819 and Chromium bug 365619 have been resolved
  3729. // and deployed
  3730. row.nTr.setAttribute('role', 'row');
  3731. }
  3732. /**
  3733. * Add attributes to a row based on the special `DT_*` parameters in a data
  3734. * source object.
  3735. * @param {object} settings DataTables settings object
  3736. * @param {object} DataTables row object for the row to be modified
  3737. * @memberof DataTable#oApi
  3738. */
  3739. function _fnRowAttributes(settings, row) {
  3740. var tr = row.nTr;
  3741. var data = row._aData;
  3742. if (tr) {
  3743. var id = settings.rowIdFn(data);
  3744. if (id) {
  3745. tr.id = id;
  3746. }
  3747. if (data.DT_RowClass) {
  3748. // Remove any classes added by DT_RowClass before
  3749. var a = data.DT_RowClass.split(' ');
  3750. row.__rowc = row.__rowc ? _unique(row.__rowc.concat(a)) : a;
  3751. $(tr).removeClass(row.__rowc.join(' ')).addClass(data.DT_RowClass);
  3752. }
  3753. if (data.DT_RowAttr) {
  3754. $(tr).attr(data.DT_RowAttr);
  3755. }
  3756. if (data.DT_RowData) {
  3757. $(tr).data(data.DT_RowData);
  3758. }
  3759. }
  3760. }
  3761. /**
  3762. * Create the HTML header for the table
  3763. * @param {object} oSettings dataTables settings object
  3764. * @memberof DataTable#oApi
  3765. */
  3766. function _fnBuildHead(oSettings) {
  3767. var i, ien, cell, row, column;
  3768. var thead = oSettings.nTHead;
  3769. var tfoot = oSettings.nTFoot;
  3770. var createHeader = $('th, td', thead).length === 0;
  3771. var classes = oSettings.oClasses;
  3772. var columns = oSettings.aoColumns;
  3773. if (createHeader) {
  3774. row = $('<tr/>').appendTo(thead);
  3775. }
  3776. for (i = 0, ien = columns.length; i < ien; i++) {
  3777. column = columns[i];
  3778. cell = $(column.nTh).addClass(column.sClass);
  3779. if (createHeader) {
  3780. cell.appendTo(row);
  3781. }
  3782. // 1.11 move into sorting
  3783. if (oSettings.oFeatures.bSort) {
  3784. cell.addClass(column.sSortingClass);
  3785. if (column.bSortable !== false) {
  3786. cell.attr('tabindex', oSettings.iTabIndex).attr('aria-controls', oSettings.sTableId);
  3787. _fnSortAttachListener(oSettings, column.nTh, i);
  3788. }
  3789. }
  3790. if (column.sTitle != cell[0].innerHTML) {
  3791. cell.html(column.sTitle);
  3792. }
  3793. _fnRenderer(oSettings, 'header')(oSettings, cell, column, classes);
  3794. }
  3795. if (createHeader) {
  3796. _fnDetectHeader(oSettings.aoHeader, thead);
  3797. }
  3798. /* ARIA role for the rows */
  3799. $(thead).find('>tr').attr('role', 'row');
  3800. /* Deal with the footer - add classes if required */
  3801. $(thead).find('>tr>th, >tr>td').addClass(classes.sHeaderTH);
  3802. $(tfoot).find('>tr>th, >tr>td').addClass(classes.sFooterTH);
  3803. // Cache the footer cells. Note that we only take the cells from the first
  3804. // row in the footer. If there is more than one row the user wants to
  3805. // interact with, they need to use the table().foot() method. Note also this
  3806. // allows cells to be used for multiple columns using colspan
  3807. if (tfoot !== null) {
  3808. var cells = oSettings.aoFooter[0];
  3809. for (i = 0, ien = cells.length; i < ien; i++) {
  3810. column = columns[i];
  3811. column.nTf = cells[i].cell;
  3812. if (column.sClass) {
  3813. $(column.nTf).addClass(column.sClass);
  3814. }
  3815. }
  3816. }
  3817. }
  3818. /**
  3819. * Draw the header (or footer) element based on the column visibility states. The
  3820. * methodology here is to use the layout array from _fnDetectHeader, modified for
  3821. * the instantaneous column visibility, to construct the new layout. The grid is
  3822. * traversed over cell at a time in a rows x columns grid fashion, although each
  3823. * cell insert can cover multiple elements in the grid - which is tracks using the
  3824. * aApplied array. Cell inserts in the grid will only occur where there isn't
  3825. * already a cell in that position.
  3826. * @param {object} oSettings dataTables settings object
  3827. * @param array {objects} aoSource Layout array from _fnDetectHeader
  3828. * @param {boolean} [bIncludeHidden=false] If true then include the hidden columns in the calc,
  3829. * @memberof DataTable#oApi
  3830. */
  3831. function _fnDrawHead(oSettings, aoSource, bIncludeHidden) {
  3832. var i, iLen, j, jLen, k, kLen, n, nLocalTr;
  3833. var aoLocal = [];
  3834. var aApplied = [];
  3835. var iColumns = oSettings.aoColumns.length;
  3836. var iRowspan, iColspan;
  3837. if (!aoSource) {
  3838. return;
  3839. }
  3840. if (bIncludeHidden === undefined) {
  3841. bIncludeHidden = false;
  3842. }
  3843. /* Make a copy of the master layout array, but without the visible columns in it */
  3844. for (i = 0, iLen = aoSource.length; i < iLen; i++) {
  3845. aoLocal[i] = aoSource[i].slice();
  3846. aoLocal[i].nTr = aoSource[i].nTr;
  3847. /* Remove any columns which are currently hidden */
  3848. for (j = iColumns - 1; j >= 0; j--) {
  3849. if (!oSettings.aoColumns[j].bVisible && !bIncludeHidden) {
  3850. aoLocal[i].splice(j, 1);
  3851. }
  3852. }
  3853. /* Prep the applied array - it needs an element for each row */
  3854. aApplied.push([]);
  3855. }
  3856. for (i = 0, iLen = aoLocal.length; i < iLen; i++) {
  3857. nLocalTr = aoLocal[i].nTr;
  3858. /* All cells are going to be replaced, so empty out the row */
  3859. if (nLocalTr) {
  3860. while (n = nLocalTr.firstChild) {
  3861. nLocalTr.removeChild(n);
  3862. }
  3863. }
  3864. for (j = 0, jLen = aoLocal[i].length; j < jLen; j++) {
  3865. iRowspan = 1;
  3866. iColspan = 1;
  3867. /* Check to see if there is already a cell (row/colspan) covering our target
  3868. * insert point. If there is, then there is nothing to do.
  3869. */
  3870. if (aApplied[i][j] === undefined) {
  3871. nLocalTr.appendChild(aoLocal[i][j].cell);
  3872. aApplied[i][j] = 1;
  3873. /* Expand the cell to cover as many rows as needed */
  3874. while (aoLocal[i + iRowspan] !== undefined && aoLocal[i][j].cell == aoLocal[i + iRowspan][j].cell) {
  3875. aApplied[i + iRowspan][j] = 1;
  3876. iRowspan++;
  3877. }
  3878. /* Expand the cell to cover as many columns as needed */
  3879. while (aoLocal[i][j + iColspan] !== undefined && aoLocal[i][j].cell == aoLocal[i][j + iColspan].cell) {
  3880. /* Must update the applied array over the rows for the columns */
  3881. for (k = 0; k < iRowspan; k++) {
  3882. aApplied[i + k][j + iColspan] = 1;
  3883. }
  3884. iColspan++;
  3885. }
  3886. /* Do the actual expansion in the DOM */
  3887. $(aoLocal[i][j].cell).attr('rowspan', iRowspan).attr('colspan', iColspan);
  3888. }
  3889. }
  3890. }
  3891. }
  3892. /**
  3893. * Insert the required TR nodes into the table for display
  3894. * @param {object} oSettings dataTables settings object
  3895. * @memberof DataTable#oApi
  3896. */
  3897. function _fnDraw(oSettings) {
  3898. /* Provide a pre-callback function which can be used to cancel the draw is false is returned */
  3899. var aPreDraw = _fnCallbackFire(oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings]);
  3900. if ($.inArray(false, aPreDraw) !== -1) {
  3901. _fnProcessingDisplay(oSettings, false);
  3902. return;
  3903. }
  3904. var i, iLen, n;
  3905. var anRows = [];
  3906. var iRowCount = 0;
  3907. var asStripeClasses = oSettings.asStripeClasses;
  3908. var iStripes = asStripeClasses.length;
  3909. var iOpenRows = oSettings.aoOpenRows.length;
  3910. var oLang = oSettings.oLanguage;
  3911. var iInitDisplayStart = oSettings.iInitDisplayStart;
  3912. var bServerSide = _fnDataSource(oSettings) == 'ssp';
  3913. var aiDisplay = oSettings.aiDisplay;
  3914. oSettings.bDrawing = true;
  3915. /* Check and see if we have an initial draw position from state saving */
  3916. if (iInitDisplayStart !== undefined && iInitDisplayStart !== -1) {
  3917. oSettings._iDisplayStart = bServerSide ? iInitDisplayStart : iInitDisplayStart >= oSettings.fnRecordsDisplay() ? 0 : iInitDisplayStart;
  3918. oSettings.iInitDisplayStart = -1;
  3919. }
  3920. var iDisplayStart = oSettings._iDisplayStart;
  3921. var iDisplayEnd = oSettings.fnDisplayEnd();
  3922. /* Server-side processing draw intercept */
  3923. if (oSettings.bDeferLoading) {
  3924. oSettings.bDeferLoading = false;
  3925. oSettings.iDraw++;
  3926. _fnProcessingDisplay(oSettings, false);
  3927. } else if (!bServerSide) {
  3928. oSettings.iDraw++;
  3929. } else if (!oSettings.bDestroying && !_fnAjaxUpdate(oSettings)) {
  3930. return;
  3931. }
  3932. if (aiDisplay.length !== 0) {
  3933. var iStart = bServerSide ? 0 : iDisplayStart;
  3934. var iEnd = bServerSide ? oSettings.aoData.length : iDisplayEnd;
  3935. for (var j = iStart; j < iEnd; j++) {
  3936. var iDataIndex = aiDisplay[j];
  3937. var aoData = oSettings.aoData[iDataIndex];
  3938. if (aoData.nTr === null) {
  3939. _fnCreateTr(oSettings, iDataIndex);
  3940. }
  3941. var nRow = aoData.nTr;
  3942. /* Remove the old striping classes and then add the new one */
  3943. if (iStripes !== 0) {
  3944. var sStripe = asStripeClasses[iRowCount % iStripes];
  3945. if (aoData._sRowStripe != sStripe) {
  3946. $(nRow).removeClass(aoData._sRowStripe).addClass(sStripe);
  3947. aoData._sRowStripe = sStripe;
  3948. }
  3949. }
  3950. // Row callback functions - might want to manipulate the row
  3951. // iRowCount and j are not currently documented. Are they at all
  3952. // useful?
  3953. _fnCallbackFire(oSettings, 'aoRowCallback', null, [nRow, aoData._aData, iRowCount, j]);
  3954. anRows.push(nRow);
  3955. iRowCount++;
  3956. }
  3957. } else {
  3958. /* Table is empty - create a row with an empty message in it */
  3959. var sZero = oLang.sZeroRecords;
  3960. if (oSettings.iDraw == 1 && _fnDataSource(oSettings) == 'ajax') {
  3961. sZero = oLang.sLoadingRecords;
  3962. } else if (oLang.sEmptyTable && oSettings.fnRecordsTotal() === 0) {
  3963. sZero = oLang.sEmptyTable;
  3964. }
  3965. anRows[0] = $('<tr/>', { 'class': iStripes ? asStripeClasses[0] : '' }).append($('<td />', {
  3966. 'valign': 'top',
  3967. 'colSpan': _fnVisbleColumns(oSettings),
  3968. 'class': oSettings.oClasses.sRowEmpty
  3969. }).html(sZero))[0];
  3970. }
  3971. /* Header and footer callbacks */
  3972. _fnCallbackFire(oSettings, 'aoHeaderCallback', 'header', [$(oSettings.nTHead).children('tr')[0], _fnGetDataMaster(oSettings), iDisplayStart, iDisplayEnd, aiDisplay]);
  3973. _fnCallbackFire(oSettings, 'aoFooterCallback', 'footer', [$(oSettings.nTFoot).children('tr')[0], _fnGetDataMaster(oSettings), iDisplayStart, iDisplayEnd, aiDisplay]);
  3974. var body = $(oSettings.nTBody);
  3975. body.children().detach();
  3976. body.append($(anRows));
  3977. /* Call all required callback functions for the end of a draw */
  3978. _fnCallbackFire(oSettings, 'aoDrawCallback', 'draw', [oSettings]);
  3979. /* Draw is complete, sorting and filtering must be as well */
  3980. oSettings.bSorted = false;
  3981. oSettings.bFiltered = false;
  3982. oSettings.bDrawing = false;
  3983. }
  3984. /**
  3985. * Redraw the table - taking account of the various features which are enabled
  3986. * @param {object} oSettings dataTables settings object
  3987. * @param {boolean} [holdPosition] Keep the current paging position. By default
  3988. * the paging is reset to the first page
  3989. * @memberof DataTable#oApi
  3990. */
  3991. function _fnReDraw(settings, holdPosition) {
  3992. var features = settings.oFeatures,
  3993. sort = features.bSort,
  3994. filter = features.bFilter;
  3995. if (sort) {
  3996. _fnSort(settings);
  3997. }
  3998. if (filter) {
  3999. _fnFilterComplete(settings, settings.oPreviousSearch);
  4000. } else {
  4001. // No filtering, so we want to just use the display master
  4002. settings.aiDisplay = settings.aiDisplayMaster.slice();
  4003. }
  4004. if (holdPosition !== true) {
  4005. settings._iDisplayStart = 0;
  4006. }
  4007. // Let any modules know about the draw hold position state (used by
  4008. // scrolling internally)
  4009. settings._drawHold = holdPosition;
  4010. _fnDraw(settings);
  4011. settings._drawHold = false;
  4012. }
  4013. /**
  4014. * Add the options to the page HTML for the table
  4015. * @param {object} oSettings dataTables settings object
  4016. * @memberof DataTable#oApi
  4017. */
  4018. function _fnAddOptionsHtml(oSettings) {
  4019. var classes = oSettings.oClasses;
  4020. var table = $(oSettings.nTable);
  4021. var holding = $('<div/>').insertBefore(table); // Holding element for speed
  4022. var features = oSettings.oFeatures;
  4023. // All DataTables are wrapped in a div
  4024. var insert = $('<div/>', {
  4025. id: oSettings.sTableId + '_wrapper',
  4026. 'class': classes.sWrapper + (oSettings.nTFoot ? '' : ' ' + classes.sNoFooter)
  4027. });
  4028. oSettings.nHolding = holding[0];
  4029. oSettings.nTableWrapper = insert[0];
  4030. oSettings.nTableReinsertBefore = oSettings.nTable.nextSibling;
  4031. /* Loop over the user set positioning and place the elements as needed */
  4032. var aDom = oSettings.sDom.split('');
  4033. var featureNode, cOption, nNewNode, cNext, sAttr, j;
  4034. for (var i = 0; i < aDom.length; i++) {
  4035. featureNode = null;
  4036. cOption = aDom[i];
  4037. if (cOption == '<') {
  4038. /* New container div */
  4039. nNewNode = $('<div/>')[0];
  4040. /* Check to see if we should append an id and/or a class name to the container */
  4041. cNext = aDom[i + 1];
  4042. if (cNext == "'" || cNext == '"') {
  4043. sAttr = "";
  4044. j = 2;
  4045. while (aDom[i + j] != cNext) {
  4046. sAttr += aDom[i + j];
  4047. j++;
  4048. }
  4049. /* Replace jQuery UI constants @todo depreciated */
  4050. if (sAttr == "H") {
  4051. sAttr = classes.sJUIHeader;
  4052. } else if (sAttr == "F") {
  4053. sAttr = classes.sJUIFooter;
  4054. }
  4055. /* The attribute can be in the format of "#id.class", "#id" or "class" This logic
  4056. * breaks the string into parts and applies them as needed
  4057. */
  4058. if (sAttr.indexOf('.') != -1) {
  4059. var aSplit = sAttr.split('.');
  4060. nNewNode.id = aSplit[0].substr(1, aSplit[0].length - 1);
  4061. nNewNode.className = aSplit[1];
  4062. } else if (sAttr.charAt(0) == "#") {
  4063. nNewNode.id = sAttr.substr(1, sAttr.length - 1);
  4064. } else {
  4065. nNewNode.className = sAttr;
  4066. }
  4067. i += j; /* Move along the position array */
  4068. }
  4069. insert.append(nNewNode);
  4070. insert = $(nNewNode);
  4071. } else if (cOption == '>') {
  4072. /* End container div */
  4073. insert = insert.parent();
  4074. }
  4075. // @todo Move options into their own plugins?
  4076. else if (cOption == 'l' && features.bPaginate && features.bLengthChange) {
  4077. /* Length */
  4078. featureNode = _fnFeatureHtmlLength(oSettings);
  4079. } else if (cOption == 'f' && features.bFilter) {
  4080. /* Filter */
  4081. featureNode = _fnFeatureHtmlFilter(oSettings);
  4082. } else if (cOption == 'r' && features.bProcessing) {
  4083. /* pRocessing */
  4084. featureNode = _fnFeatureHtmlProcessing(oSettings);
  4085. } else if (cOption == 't') {
  4086. /* Table */
  4087. featureNode = _fnFeatureHtmlTable(oSettings);
  4088. } else if (cOption == 'i' && features.bInfo) {
  4089. /* Info */
  4090. featureNode = _fnFeatureHtmlInfo(oSettings);
  4091. } else if (cOption == 'p' && features.bPaginate) {
  4092. /* Pagination */
  4093. featureNode = _fnFeatureHtmlPaginate(oSettings);
  4094. } else if (DataTable.ext.feature.length !== 0) {
  4095. /* Plug-in features */
  4096. var aoFeatures = DataTable.ext.feature;
  4097. for (var k = 0, kLen = aoFeatures.length; k < kLen; k++) {
  4098. if (cOption == aoFeatures[k].cFeature) {
  4099. featureNode = aoFeatures[k].fnInit(oSettings);
  4100. break;
  4101. }
  4102. }
  4103. }
  4104. /* Add to the 2D features array */
  4105. if (featureNode) {
  4106. var aanFeatures = oSettings.aanFeatures;
  4107. if (!aanFeatures[cOption]) {
  4108. aanFeatures[cOption] = [];
  4109. }
  4110. aanFeatures[cOption].push(featureNode);
  4111. insert.append(featureNode);
  4112. }
  4113. }
  4114. /* Built our DOM structure - replace the holding div with what we want */
  4115. holding.replaceWith(insert);
  4116. oSettings.nHolding = null;
  4117. }
  4118. /**
  4119. * Use the DOM source to create up an array of header cells. The idea here is to
  4120. * create a layout grid (array) of rows x columns, which contains a reference
  4121. * to the cell that that point in the grid (regardless of col/rowspan), such that
  4122. * any column / row could be removed and the new grid constructed
  4123. * @param array {object} aLayout Array to store the calculated layout in
  4124. * @param {node} nThead The header/footer element for the table
  4125. * @memberof DataTable#oApi
  4126. */
  4127. function _fnDetectHeader(aLayout, nThead) {
  4128. var nTrs = $(nThead).children('tr');
  4129. var nTr, nCell;
  4130. var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
  4131. var bUnique;
  4132. var fnShiftCol = function fnShiftCol(a, i, j) {
  4133. var k = a[i];
  4134. while (k[j]) {
  4135. j++;
  4136. }
  4137. return j;
  4138. };
  4139. aLayout.splice(0, aLayout.length);
  4140. /* We know how many rows there are in the layout - so prep it */
  4141. for (i = 0, iLen = nTrs.length; i < iLen; i++) {
  4142. aLayout.push([]);
  4143. }
  4144. /* Calculate a layout array */
  4145. for (i = 0, iLen = nTrs.length; i < iLen; i++) {
  4146. nTr = nTrs[i];
  4147. iColumn = 0;
  4148. /* For every cell in the row... */
  4149. nCell = nTr.firstChild;
  4150. while (nCell) {
  4151. if (nCell.nodeName.toUpperCase() == "TD" || nCell.nodeName.toUpperCase() == "TH") {
  4152. /* Get the col and rowspan attributes from the DOM and sanitise them */
  4153. iColspan = nCell.getAttribute('colspan') * 1;
  4154. iRowspan = nCell.getAttribute('rowspan') * 1;
  4155. iColspan = !iColspan || iColspan === 0 || iColspan === 1 ? 1 : iColspan;
  4156. iRowspan = !iRowspan || iRowspan === 0 || iRowspan === 1 ? 1 : iRowspan;
  4157. /* There might be colspan cells already in this row, so shift our target
  4158. * accordingly
  4159. */
  4160. iColShifted = fnShiftCol(aLayout, i, iColumn);
  4161. /* Cache calculation for unique columns */
  4162. bUnique = iColspan === 1 ? true : false;
  4163. /* If there is col / rowspan, copy the information into the layout grid */
  4164. for (l = 0; l < iColspan; l++) {
  4165. for (k = 0; k < iRowspan; k++) {
  4166. aLayout[i + k][iColShifted + l] = {
  4167. "cell": nCell,
  4168. "unique": bUnique
  4169. };
  4170. aLayout[i + k].nTr = nTr;
  4171. }
  4172. }
  4173. }
  4174. nCell = nCell.nextSibling;
  4175. }
  4176. }
  4177. }
  4178. /**
  4179. * Get an array of unique th elements, one for each column
  4180. * @param {object} oSettings dataTables settings object
  4181. * @param {node} nHeader automatically detect the layout from this node - optional
  4182. * @param {array} aLayout thead/tfoot layout from _fnDetectHeader - optional
  4183. * @returns array {node} aReturn list of unique th's
  4184. * @memberof DataTable#oApi
  4185. */
  4186. function _fnGetUniqueThs(oSettings, nHeader, aLayout) {
  4187. var aReturn = [];
  4188. if (!aLayout) {
  4189. aLayout = oSettings.aoHeader;
  4190. if (nHeader) {
  4191. aLayout = [];
  4192. _fnDetectHeader(aLayout, nHeader);
  4193. }
  4194. }
  4195. for (var i = 0, iLen = aLayout.length; i < iLen; i++) {
  4196. for (var j = 0, jLen = aLayout[i].length; j < jLen; j++) {
  4197. if (aLayout[i][j].unique && (!aReturn[j] || !oSettings.bSortCellsTop)) {
  4198. aReturn[j] = aLayout[i][j].cell;
  4199. }
  4200. }
  4201. }
  4202. return aReturn;
  4203. }
  4204. /**
  4205. * Create an Ajax call based on the table's settings, taking into account that
  4206. * parameters can have multiple forms, and backwards compatibility.
  4207. *
  4208. * @param {object} oSettings dataTables settings object
  4209. * @param {array} data Data to send to the server, required by
  4210. * DataTables - may be augmented by developer callbacks
  4211. * @param {function} fn Callback function to run when data is obtained
  4212. */
  4213. function _fnBuildAjax(oSettings, data, fn) {
  4214. // Compatibility with 1.9-, allow fnServerData and event to manipulate
  4215. _fnCallbackFire(oSettings, 'aoServerParams', 'serverParams', [data]);
  4216. // Convert to object based for 1.10+ if using the old array scheme which can
  4217. // come from server-side processing or serverParams
  4218. if (data && $.isArray(data)) {
  4219. var tmp = {};
  4220. var rbracket = /(.*?)\[\]$/;
  4221. $.each(data, function (key, val) {
  4222. var match = val.name.match(rbracket);
  4223. if (match) {
  4224. // Support for arrays
  4225. var name = match[0];
  4226. if (!tmp[name]) {
  4227. tmp[name] = [];
  4228. }
  4229. tmp[name].push(val.value);
  4230. } else {
  4231. tmp[val.name] = val.value;
  4232. }
  4233. });
  4234. data = tmp;
  4235. }
  4236. var ajaxData;
  4237. var ajax = oSettings.ajax;
  4238. var instance = oSettings.oInstance;
  4239. var callback = function callback(json) {
  4240. _fnCallbackFire(oSettings, null, 'xhr', [oSettings, json, oSettings.jqXHR]);
  4241. fn(json);
  4242. };
  4243. if ($.isPlainObject(ajax) && ajax.data) {
  4244. ajaxData = ajax.data;
  4245. var newData = $.isFunction(ajaxData) ? ajaxData(data, oSettings) : // fn can manipulate data or return
  4246. ajaxData; // an object object or array to merge
  4247. // If the function returned something, use that alone
  4248. data = $.isFunction(ajaxData) && newData ? newData : $.extend(true, data, newData);
  4249. // Remove the data property as we've resolved it already and don't want
  4250. // jQuery to do it again (it is restored at the end of the function)
  4251. delete ajax.data;
  4252. }
  4253. var baseAjax = {
  4254. "data": data,
  4255. "success": function success(json) {
  4256. var error = json.error || json.sError;
  4257. if (error) {
  4258. _fnLog(oSettings, 0, error);
  4259. }
  4260. oSettings.json = json;
  4261. callback(json);
  4262. },
  4263. "dataType": "json",
  4264. "cache": false,
  4265. "type": oSettings.sServerMethod,
  4266. "error": function error(xhr, _error, thrown) {
  4267. var ret = _fnCallbackFire(oSettings, null, 'xhr', [oSettings, null, oSettings.jqXHR]);
  4268. if ($.inArray(true, ret) === -1) {
  4269. if (_error == "parsererror") {
  4270. _fnLog(oSettings, 0, 'Invalid JSON response', 1);
  4271. } else if (xhr.readyState === 4) {
  4272. _fnLog(oSettings, 0, 'Ajax error', 7);
  4273. }
  4274. }
  4275. _fnProcessingDisplay(oSettings, false);
  4276. }
  4277. };
  4278. // Store the data submitted for the API
  4279. oSettings.oAjaxData = data;
  4280. // Allow plug-ins and external processes to modify the data
  4281. _fnCallbackFire(oSettings, null, 'preXhr', [oSettings, data]);
  4282. if (oSettings.fnServerData) {
  4283. // DataTables 1.9- compatibility
  4284. oSettings.fnServerData.call(instance, oSettings.sAjaxSource, $.map(data, function (val, key) {
  4285. // Need to convert back to 1.9 trad format
  4286. return { name: key, value: val };
  4287. }), callback, oSettings);
  4288. } else if (oSettings.sAjaxSource || typeof ajax === 'string') {
  4289. // DataTables 1.9- compatibility
  4290. oSettings.jqXHR = $.ajax($.extend(baseAjax, {
  4291. url: ajax || oSettings.sAjaxSource
  4292. }));
  4293. } else if ($.isFunction(ajax)) {
  4294. // Is a function - let the caller define what needs to be done
  4295. oSettings.jqXHR = ajax.call(instance, data, callback, oSettings);
  4296. } else {
  4297. // Object to extend the base settings
  4298. oSettings.jqXHR = $.ajax($.extend(baseAjax, ajax));
  4299. // Restore for next time around
  4300. ajax.data = ajaxData;
  4301. }
  4302. }
  4303. /**
  4304. * Update the table using an Ajax call
  4305. * @param {object} settings dataTables settings object
  4306. * @returns {boolean} Block the table drawing or not
  4307. * @memberof DataTable#oApi
  4308. */
  4309. function _fnAjaxUpdate(settings) {
  4310. if (settings.bAjaxDataGet) {
  4311. settings.iDraw++;
  4312. _fnProcessingDisplay(settings, true);
  4313. _fnBuildAjax(settings, _fnAjaxParameters(settings), function (json) {
  4314. _fnAjaxUpdateDraw(settings, json);
  4315. });
  4316. return false;
  4317. }
  4318. return true;
  4319. }
  4320. /**
  4321. * Build up the parameters in an object needed for a server-side processing
  4322. * request. Note that this is basically done twice, is different ways - a modern
  4323. * method which is used by default in DataTables 1.10 which uses objects and
  4324. * arrays, or the 1.9- method with is name / value pairs. 1.9 method is used if
  4325. * the sAjaxSource option is used in the initialisation, or the legacyAjax
  4326. * option is set.
  4327. * @param {object} oSettings dataTables settings object
  4328. * @returns {bool} block the table drawing or not
  4329. * @memberof DataTable#oApi
  4330. */
  4331. function _fnAjaxParameters(settings) {
  4332. var columns = settings.aoColumns,
  4333. columnCount = columns.length,
  4334. features = settings.oFeatures,
  4335. preSearch = settings.oPreviousSearch,
  4336. preColSearch = settings.aoPreSearchCols,
  4337. i,
  4338. data = [],
  4339. dataProp,
  4340. column,
  4341. columnSearch,
  4342. sort = _fnSortFlatten(settings),
  4343. displayStart = settings._iDisplayStart,
  4344. displayLength = features.bPaginate !== false ? settings._iDisplayLength : -1;
  4345. var param = function param(name, value) {
  4346. data.push({ 'name': name, 'value': value });
  4347. };
  4348. // DataTables 1.9- compatible method
  4349. param('sEcho', settings.iDraw);
  4350. param('iColumns', columnCount);
  4351. param('sColumns', _pluck(columns, 'sName').join(','));
  4352. param('iDisplayStart', displayStart);
  4353. param('iDisplayLength', displayLength);
  4354. // DataTables 1.10+ method
  4355. var d = {
  4356. draw: settings.iDraw,
  4357. columns: [],
  4358. order: [],
  4359. start: displayStart,
  4360. length: displayLength,
  4361. search: {
  4362. value: preSearch.sSearch,
  4363. regex: preSearch.bRegex
  4364. }
  4365. };
  4366. for (i = 0; i < columnCount; i++) {
  4367. column = columns[i];
  4368. columnSearch = preColSearch[i];
  4369. dataProp = typeof column.mData == "function" ? 'function' : column.mData;
  4370. d.columns.push({
  4371. data: dataProp,
  4372. name: column.sName,
  4373. searchable: column.bSearchable,
  4374. orderable: column.bSortable,
  4375. search: {
  4376. value: columnSearch.sSearch,
  4377. regex: columnSearch.bRegex
  4378. }
  4379. });
  4380. param("mDataProp_" + i, dataProp);
  4381. if (features.bFilter) {
  4382. param('sSearch_' + i, columnSearch.sSearch);
  4383. param('bRegex_' + i, columnSearch.bRegex);
  4384. param('bSearchable_' + i, column.bSearchable);
  4385. }
  4386. if (features.bSort) {
  4387. param('bSortable_' + i, column.bSortable);
  4388. }
  4389. }
  4390. if (features.bFilter) {
  4391. param('sSearch', preSearch.sSearch);
  4392. param('bRegex', preSearch.bRegex);
  4393. }
  4394. if (features.bSort) {
  4395. $.each(sort, function (i, val) {
  4396. d.order.push({ column: val.col, dir: val.dir });
  4397. param('iSortCol_' + i, val.col);
  4398. param('sSortDir_' + i, val.dir);
  4399. });
  4400. param('iSortingCols', sort.length);
  4401. }
  4402. // If the legacy.ajax parameter is null, then we automatically decide which
  4403. // form to use, based on sAjaxSource
  4404. var legacy = DataTable.ext.legacy.ajax;
  4405. if (legacy === null) {
  4406. return settings.sAjaxSource ? data : d;
  4407. }
  4408. // Otherwise, if legacy has been specified then we use that to decide on the
  4409. // form
  4410. return legacy ? data : d;
  4411. }
  4412. /**
  4413. * Data the data from the server (nuking the old) and redraw the table
  4414. * @param {object} oSettings dataTables settings object
  4415. * @param {object} json json data return from the server.
  4416. * @param {string} json.sEcho Tracking flag for DataTables to match requests
  4417. * @param {int} json.iTotalRecords Number of records in the data set, not accounting for filtering
  4418. * @param {int} json.iTotalDisplayRecords Number of records in the data set, accounting for filtering
  4419. * @param {array} json.aaData The data to display on this page
  4420. * @param {string} [json.sColumns] Column ordering (sName, comma separated)
  4421. * @memberof DataTable#oApi
  4422. */
  4423. function _fnAjaxUpdateDraw(settings, json) {
  4424. // v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
  4425. // Support both
  4426. var compat = function compat(old, modern) {
  4427. return json[old] !== undefined ? json[old] : json[modern];
  4428. };
  4429. var data = _fnAjaxDataSrc(settings, json);
  4430. var draw = compat('sEcho', 'draw');
  4431. var recordsTotal = compat('iTotalRecords', 'recordsTotal');
  4432. var recordsFiltered = compat('iTotalDisplayRecords', 'recordsFiltered');
  4433. if (draw) {
  4434. // Protect against out of sequence returns
  4435. if (draw * 1 < settings.iDraw) {
  4436. return;
  4437. }
  4438. settings.iDraw = draw * 1;
  4439. }
  4440. _fnClearTable(settings);
  4441. settings._iRecordsTotal = parseInt(recordsTotal, 10);
  4442. settings._iRecordsDisplay = parseInt(recordsFiltered, 10);
  4443. for (var i = 0, ien = data.length; i < ien; i++) {
  4444. _fnAddData(settings, data[i]);
  4445. }
  4446. settings.aiDisplay = settings.aiDisplayMaster.slice();
  4447. settings.bAjaxDataGet = false;
  4448. _fnDraw(settings);
  4449. if (!settings._bInitComplete) {
  4450. _fnInitComplete(settings, json);
  4451. }
  4452. settings.bAjaxDataGet = true;
  4453. _fnProcessingDisplay(settings, false);
  4454. }
  4455. /**
  4456. * Get the data from the JSON data source to use for drawing a table. Using
  4457. * `_fnGetObjectDataFn` allows the data to be sourced from a property of the
  4458. * source object, or from a processing function.
  4459. * @param {object} oSettings dataTables settings object
  4460. * @param {object} json Data source object / array from the server
  4461. * @return {array} Array of data to use
  4462. */
  4463. function _fnAjaxDataSrc(oSettings, json) {
  4464. var dataSrc = $.isPlainObject(oSettings.ajax) && oSettings.ajax.dataSrc !== undefined ? oSettings.ajax.dataSrc : oSettings.sAjaxDataProp; // Compatibility with 1.9-.
  4465. // Compatibility with 1.9-. In order to read from aaData, check if the
  4466. // default has been changed, if not, check for aaData
  4467. if (dataSrc === 'data') {
  4468. return json.aaData || json[dataSrc];
  4469. }
  4470. return dataSrc !== "" ? _fnGetObjectDataFn(dataSrc)(json) : json;
  4471. }
  4472. /**
  4473. * Generate the node required for filtering text
  4474. * @returns {node} Filter control element
  4475. * @param {object} oSettings dataTables settings object
  4476. * @memberof DataTable#oApi
  4477. */
  4478. function _fnFeatureHtmlFilter(settings) {
  4479. var classes = settings.oClasses;
  4480. var tableId = settings.sTableId;
  4481. var language = settings.oLanguage;
  4482. var previousSearch = settings.oPreviousSearch;
  4483. var features = settings.aanFeatures;
  4484. var input = '<input type="search" class="' + classes.sFilterInput + '"/>';
  4485. var str = language.sSearch;
  4486. str = str.match(/_INPUT_/) ? str.replace('_INPUT_', input) : str + input;
  4487. var filter = $('<div/>', {
  4488. 'id': !features.f ? tableId + '_filter' : null,
  4489. 'class': classes.sFilter
  4490. }).append($('<label/>').append(str));
  4491. var searchFn = function searchFn() {
  4492. /* Update all other filter input elements for the new display */
  4493. var n = features.f;
  4494. var val = !this.value ? "" : this.value; // mental IE8 fix :-(
  4495. /* Now do the filter */
  4496. if (val != previousSearch.sSearch) {
  4497. _fnFilterComplete(settings, {
  4498. "sSearch": val,
  4499. "bRegex": previousSearch.bRegex,
  4500. "bSmart": previousSearch.bSmart,
  4501. "bCaseInsensitive": previousSearch.bCaseInsensitive
  4502. });
  4503. // Need to redraw, without resorting
  4504. settings._iDisplayStart = 0;
  4505. _fnDraw(settings);
  4506. }
  4507. };
  4508. var searchDelay = settings.searchDelay !== null ? settings.searchDelay : _fnDataSource(settings) === 'ssp' ? 400 : 0;
  4509. var jqFilter = $('input', filter).val(previousSearch.sSearch).attr('placeholder', language.sSearchPlaceholder).on('keyup.DT search.DT input.DT paste.DT cut.DT', searchDelay ? _fnThrottle(searchFn, searchDelay) : searchFn).on('keypress.DT', function (e) {
  4510. /* Prevent form submission */
  4511. if (e.keyCode == 13) {
  4512. return false;
  4513. }
  4514. }).attr('aria-controls', tableId);
  4515. // Update the input elements whenever the table is filtered
  4516. $(settings.nTable).on('search.dt.DT', function (ev, s) {
  4517. if (settings === s) {
  4518. // IE9 throws an 'unknown error' if document.activeElement is used
  4519. // inside an iframe or frame...
  4520. try {
  4521. if (jqFilter[0] !== document.activeElement) {
  4522. jqFilter.val(previousSearch.sSearch);
  4523. }
  4524. } catch (e) {}
  4525. }
  4526. });
  4527. return filter[0];
  4528. }
  4529. /**
  4530. * Filter the table using both the global filter and column based filtering
  4531. * @param {object} oSettings dataTables settings object
  4532. * @param {object} oSearch search information
  4533. * @param {int} [iForce] force a research of the master array (1) or not (undefined or 0)
  4534. * @memberof DataTable#oApi
  4535. */
  4536. function _fnFilterComplete(oSettings, oInput, iForce) {
  4537. var oPrevSearch = oSettings.oPreviousSearch;
  4538. var aoPrevSearch = oSettings.aoPreSearchCols;
  4539. var fnSaveFilter = function fnSaveFilter(oFilter) {
  4540. /* Save the filtering values */
  4541. oPrevSearch.sSearch = oFilter.sSearch;
  4542. oPrevSearch.bRegex = oFilter.bRegex;
  4543. oPrevSearch.bSmart = oFilter.bSmart;
  4544. oPrevSearch.bCaseInsensitive = oFilter.bCaseInsensitive;
  4545. };
  4546. var fnRegex = function fnRegex(o) {
  4547. // Backwards compatibility with the bEscapeRegex option
  4548. return o.bEscapeRegex !== undefined ? !o.bEscapeRegex : o.bRegex;
  4549. };
  4550. // Resolve any column types that are unknown due to addition or invalidation
  4551. // @todo As per sort - can this be moved into an event handler?
  4552. _fnColumnTypes(oSettings);
  4553. /* In server-side processing all filtering is done by the server, so no point hanging around here */
  4554. if (_fnDataSource(oSettings) != 'ssp') {
  4555. /* Global filter */
  4556. _fnFilter(oSettings, oInput.sSearch, iForce, fnRegex(oInput), oInput.bSmart, oInput.bCaseInsensitive);
  4557. fnSaveFilter(oInput);
  4558. /* Now do the individual column filter */
  4559. for (var i = 0; i < aoPrevSearch.length; i++) {
  4560. _fnFilterColumn(oSettings, aoPrevSearch[i].sSearch, i, fnRegex(aoPrevSearch[i]), aoPrevSearch[i].bSmart, aoPrevSearch[i].bCaseInsensitive);
  4561. }
  4562. /* Custom filtering */
  4563. _fnFilterCustom(oSettings);
  4564. } else {
  4565. fnSaveFilter(oInput);
  4566. }
  4567. /* Tell the draw function we have been filtering */
  4568. oSettings.bFiltered = true;
  4569. _fnCallbackFire(oSettings, null, 'search', [oSettings]);
  4570. }
  4571. /**
  4572. * Apply custom filtering functions
  4573. * @param {object} oSettings dataTables settings object
  4574. * @memberof DataTable#oApi
  4575. */
  4576. function _fnFilterCustom(settings) {
  4577. var filters = DataTable.ext.search;
  4578. var displayRows = settings.aiDisplay;
  4579. var row, rowIdx;
  4580. for (var i = 0, ien = filters.length; i < ien; i++) {
  4581. var rows = [];
  4582. // Loop over each row and see if it should be included
  4583. for (var j = 0, jen = displayRows.length; j < jen; j++) {
  4584. rowIdx = displayRows[j];
  4585. row = settings.aoData[rowIdx];
  4586. if (filters[i](settings, row._aFilterData, rowIdx, row._aData, j)) {
  4587. rows.push(rowIdx);
  4588. }
  4589. }
  4590. // So the array reference doesn't break set the results into the
  4591. // existing array
  4592. displayRows.length = 0;
  4593. $.merge(displayRows, rows);
  4594. }
  4595. }
  4596. /**
  4597. * Filter the table on a per-column basis
  4598. * @param {object} oSettings dataTables settings object
  4599. * @param {string} sInput string to filter on
  4600. * @param {int} iColumn column to filter
  4601. * @param {bool} bRegex treat search string as a regular expression or not
  4602. * @param {bool} bSmart use smart filtering or not
  4603. * @param {bool} bCaseInsensitive Do case insenstive matching or not
  4604. * @memberof DataTable#oApi
  4605. */
  4606. function _fnFilterColumn(settings, searchStr, colIdx, regex, smart, caseInsensitive) {
  4607. if (searchStr === '') {
  4608. return;
  4609. }
  4610. var data;
  4611. var out = [];
  4612. var display = settings.aiDisplay;
  4613. var rpSearch = _fnFilterCreateSearch(searchStr, regex, smart, caseInsensitive);
  4614. for (var i = 0; i < display.length; i++) {
  4615. data = settings.aoData[display[i]]._aFilterData[colIdx];
  4616. if (rpSearch.test(data)) {
  4617. out.push(display[i]);
  4618. }
  4619. }
  4620. settings.aiDisplay = out;
  4621. }
  4622. /**
  4623. * Filter the data table based on user input and draw the table
  4624. * @param {object} settings dataTables settings object
  4625. * @param {string} input string to filter on
  4626. * @param {int} force optional - force a research of the master array (1) or not (undefined or 0)
  4627. * @param {bool} regex treat as a regular expression or not
  4628. * @param {bool} smart perform smart filtering or not
  4629. * @param {bool} caseInsensitive Do case insenstive matching or not
  4630. * @memberof DataTable#oApi
  4631. */
  4632. function _fnFilter(settings, input, force, regex, smart, caseInsensitive) {
  4633. var rpSearch = _fnFilterCreateSearch(input, regex, smart, caseInsensitive);
  4634. var prevSearch = settings.oPreviousSearch.sSearch;
  4635. var displayMaster = settings.aiDisplayMaster;
  4636. var display, invalidated, i;
  4637. var filtered = [];
  4638. // Need to take account of custom filtering functions - always filter
  4639. if (DataTable.ext.search.length !== 0) {
  4640. force = true;
  4641. }
  4642. // Check if any of the rows were invalidated
  4643. invalidated = _fnFilterData(settings);
  4644. // If the input is blank - we just want the full data set
  4645. if (input.length <= 0) {
  4646. settings.aiDisplay = displayMaster.slice();
  4647. } else {
  4648. // New search - start from the master array
  4649. if (invalidated || force || prevSearch.length > input.length || input.indexOf(prevSearch) !== 0 || settings.bSorted // On resort, the display master needs to be
  4650. // re-filtered since indexes will have changed
  4651. ) {
  4652. settings.aiDisplay = displayMaster.slice();
  4653. }
  4654. // Search the display array
  4655. display = settings.aiDisplay;
  4656. for (i = 0; i < display.length; i++) {
  4657. if (rpSearch.test(settings.aoData[display[i]]._sFilterRow)) {
  4658. filtered.push(display[i]);
  4659. }
  4660. }
  4661. settings.aiDisplay = filtered;
  4662. }
  4663. }
  4664. /**
  4665. * Build a regular expression object suitable for searching a table
  4666. * @param {string} sSearch string to search for
  4667. * @param {bool} bRegex treat as a regular expression or not
  4668. * @param {bool} bSmart perform smart filtering or not
  4669. * @param {bool} bCaseInsensitive Do case insensitive matching or not
  4670. * @returns {RegExp} constructed object
  4671. * @memberof DataTable#oApi
  4672. */
  4673. function _fnFilterCreateSearch(search, regex, smart, caseInsensitive) {
  4674. search = regex ? search : _fnEscapeRegex(search);
  4675. if (smart) {
  4676. /* For smart filtering we want to allow the search to work regardless of
  4677. * word order. We also want double quoted text to be preserved, so word
  4678. * order is important - a la google. So this is what we want to
  4679. * generate:
  4680. *
  4681. * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$
  4682. */
  4683. var a = $.map(search.match(/"[^"]+"|[^ ]+/g) || [''], function (word) {
  4684. if (word.charAt(0) === '"') {
  4685. var m = word.match(/^"(.*)"$/);
  4686. word = m ? m[1] : word;
  4687. }
  4688. return word.replace('"', '');
  4689. });
  4690. search = '^(?=.*?' + a.join(')(?=.*?') + ').*$';
  4691. }
  4692. return new RegExp(search, caseInsensitive ? 'i' : '');
  4693. }
  4694. /**
  4695. * Escape a string such that it can be used in a regular expression
  4696. * @param {string} sVal string to escape
  4697. * @returns {string} escaped string
  4698. * @memberof DataTable#oApi
  4699. */
  4700. var _fnEscapeRegex = DataTable.util.escapeRegex;
  4701. var __filter_div = $('<div>')[0];
  4702. var __filter_div_textContent = __filter_div.textContent !== undefined;
  4703. // Update the filtering data for each row if needed (by invalidation or first run)
  4704. function _fnFilterData(settings) {
  4705. var columns = settings.aoColumns;
  4706. var column;
  4707. var i, j, ien, jen, filterData, cellData, row;
  4708. var fomatters = DataTable.ext.type.search;
  4709. var wasInvalidated = false;
  4710. for (i = 0, ien = settings.aoData.length; i < ien; i++) {
  4711. row = settings.aoData[i];
  4712. if (!row._aFilterData) {
  4713. filterData = [];
  4714. for (j = 0, jen = columns.length; j < jen; j++) {
  4715. column = columns[j];
  4716. if (column.bSearchable) {
  4717. cellData = _fnGetCellData(settings, i, j, 'filter');
  4718. if (fomatters[column.sType]) {
  4719. cellData = fomatters[column.sType](cellData);
  4720. }
  4721. // Search in DataTables 1.10 is string based. In 1.11 this
  4722. // should be altered to also allow strict type checking.
  4723. if (cellData === null) {
  4724. cellData = '';
  4725. }
  4726. if (typeof cellData !== 'string' && cellData.toString) {
  4727. cellData = cellData.toString();
  4728. }
  4729. } else {
  4730. cellData = '';
  4731. }
  4732. // If it looks like there is an HTML entity in the string,
  4733. // attempt to decode it so sorting works as expected. Note that
  4734. // we could use a single line of jQuery to do this, but the DOM
  4735. // method used here is much faster http://jsperf.com/html-decode
  4736. if (cellData.indexOf && cellData.indexOf('&') !== -1) {
  4737. __filter_div.innerHTML = cellData;
  4738. cellData = __filter_div_textContent ? __filter_div.textContent : __filter_div.innerText;
  4739. }
  4740. if (cellData.replace) {
  4741. cellData = cellData.replace(/[\r\n]/g, '');
  4742. }
  4743. filterData.push(cellData);
  4744. }
  4745. row._aFilterData = filterData;
  4746. row._sFilterRow = filterData.join(' ');
  4747. wasInvalidated = true;
  4748. }
  4749. }
  4750. return wasInvalidated;
  4751. }
  4752. /**
  4753. * Convert from the internal Hungarian notation to camelCase for external
  4754. * interaction
  4755. * @param {object} obj Object to convert
  4756. * @returns {object} Inverted object
  4757. * @memberof DataTable#oApi
  4758. */
  4759. function _fnSearchToCamel(obj) {
  4760. return {
  4761. search: obj.sSearch,
  4762. smart: obj.bSmart,
  4763. regex: obj.bRegex,
  4764. caseInsensitive: obj.bCaseInsensitive
  4765. };
  4766. }
  4767. /**
  4768. * Convert from camelCase notation to the internal Hungarian. We could use the
  4769. * Hungarian convert function here, but this is cleaner
  4770. * @param {object} obj Object to convert
  4771. * @returns {object} Inverted object
  4772. * @memberof DataTable#oApi
  4773. */
  4774. function _fnSearchToHung(obj) {
  4775. return {
  4776. sSearch: obj.search,
  4777. bSmart: obj.smart,
  4778. bRegex: obj.regex,
  4779. bCaseInsensitive: obj.caseInsensitive
  4780. };
  4781. }
  4782. /**
  4783. * Generate the node required for the info display
  4784. * @param {object} oSettings dataTables settings object
  4785. * @returns {node} Information element
  4786. * @memberof DataTable#oApi
  4787. */
  4788. function _fnFeatureHtmlInfo(settings) {
  4789. var tid = settings.sTableId,
  4790. nodes = settings.aanFeatures.i,
  4791. n = $('<div/>', {
  4792. 'class': settings.oClasses.sInfo,
  4793. 'id': !nodes ? tid + '_info' : null
  4794. });
  4795. if (!nodes) {
  4796. // Update display on each draw
  4797. settings.aoDrawCallback.push({
  4798. "fn": _fnUpdateInfo,
  4799. "sName": "information"
  4800. });
  4801. n.attr('role', 'status').attr('aria-live', 'polite');
  4802. // Table is described by our info div
  4803. $(settings.nTable).attr('aria-describedby', tid + '_info');
  4804. }
  4805. return n[0];
  4806. }
  4807. /**
  4808. * Update the information elements in the display
  4809. * @param {object} settings dataTables settings object
  4810. * @memberof DataTable#oApi
  4811. */
  4812. function _fnUpdateInfo(settings) {
  4813. /* Show information about the table */
  4814. var nodes = settings.aanFeatures.i;
  4815. if (nodes.length === 0) {
  4816. return;
  4817. }
  4818. var lang = settings.oLanguage,
  4819. start = settings._iDisplayStart + 1,
  4820. end = settings.fnDisplayEnd(),
  4821. max = settings.fnRecordsTotal(),
  4822. total = settings.fnRecordsDisplay(),
  4823. out = total ? lang.sInfo : lang.sInfoEmpty;
  4824. if (total !== max) {
  4825. /* Record set after filtering */
  4826. out += ' ' + lang.sInfoFiltered;
  4827. }
  4828. // Convert the macros
  4829. out += lang.sInfoPostFix;
  4830. out = _fnInfoMacros(settings, out);
  4831. var callback = lang.fnInfoCallback;
  4832. if (callback !== null) {
  4833. out = callback.call(settings.oInstance, settings, start, end, max, total, out);
  4834. }
  4835. $(nodes).html(out);
  4836. }
  4837. function _fnInfoMacros(settings, str) {
  4838. // When infinite scrolling, we are always starting at 1. _iDisplayStart is used only
  4839. // internally
  4840. var formatter = settings.fnFormatNumber,
  4841. start = settings._iDisplayStart + 1,
  4842. len = settings._iDisplayLength,
  4843. vis = settings.fnRecordsDisplay(),
  4844. all = len === -1;
  4845. 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)));
  4846. }
  4847. /**
  4848. * Draw the table for the first time, adding all required features
  4849. * @param {object} settings dataTables settings object
  4850. * @memberof DataTable#oApi
  4851. */
  4852. function _fnInitialise(settings) {
  4853. var i,
  4854. iLen,
  4855. iAjaxStart = settings.iInitDisplayStart;
  4856. var columns = settings.aoColumns,
  4857. column;
  4858. var features = settings.oFeatures;
  4859. var deferLoading = settings.bDeferLoading; // value modified by the draw
  4860. /* Ensure that the table data is fully initialised */
  4861. if (!settings.bInitialised) {
  4862. setTimeout(function () {
  4863. _fnInitialise(settings);
  4864. }, 200);
  4865. return;
  4866. }
  4867. /* Show the display HTML options */
  4868. _fnAddOptionsHtml(settings);
  4869. /* Build and draw the header / footer for the table */
  4870. _fnBuildHead(settings);
  4871. _fnDrawHead(settings, settings.aoHeader);
  4872. _fnDrawHead(settings, settings.aoFooter);
  4873. /* Okay to show that something is going on now */
  4874. _fnProcessingDisplay(settings, true);
  4875. /* Calculate sizes for columns */
  4876. if (features.bAutoWidth) {
  4877. _fnCalculateColumnWidths(settings);
  4878. }
  4879. for (i = 0, iLen = columns.length; i < iLen; i++) {
  4880. column = columns[i];
  4881. if (column.sWidth) {
  4882. column.nTh.style.width = _fnStringToCss(column.sWidth);
  4883. }
  4884. }
  4885. _fnCallbackFire(settings, null, 'preInit', [settings]);
  4886. // If there is default sorting required - let's do it. The sort function
  4887. // will do the drawing for us. Otherwise we draw the table regardless of the
  4888. // Ajax source - this allows the table to look initialised for Ajax sourcing
  4889. // data (show 'loading' message possibly)
  4890. _fnReDraw(settings);
  4891. // Server-side processing init complete is done by _fnAjaxUpdateDraw
  4892. var dataSrc = _fnDataSource(settings);
  4893. if (dataSrc != 'ssp' || deferLoading) {
  4894. // if there is an ajax source load the data
  4895. if (dataSrc == 'ajax') {
  4896. _fnBuildAjax(settings, [], function (json) {
  4897. var aData = _fnAjaxDataSrc(settings, json);
  4898. // Got the data - add it to the table
  4899. for (i = 0; i < aData.length; i++) {
  4900. _fnAddData(settings, aData[i]);
  4901. }
  4902. // Reset the init display for cookie saving. We've already done
  4903. // a filter, and therefore cleared it before. So we need to make
  4904. // it appear 'fresh'
  4905. settings.iInitDisplayStart = iAjaxStart;
  4906. _fnReDraw(settings);
  4907. _fnProcessingDisplay(settings, false);
  4908. _fnInitComplete(settings, json);
  4909. }, settings);
  4910. } else {
  4911. _fnProcessingDisplay(settings, false);
  4912. _fnInitComplete(settings);
  4913. }
  4914. }
  4915. }
  4916. /**
  4917. * Draw the table for the first time, adding all required features
  4918. * @param {object} oSettings dataTables settings object
  4919. * @param {object} [json] JSON from the server that completed the table, if using Ajax source
  4920. * with client-side processing (optional)
  4921. * @memberof DataTable#oApi
  4922. */
  4923. function _fnInitComplete(settings, json) {
  4924. settings._bInitComplete = true;
  4925. // When data was added after the initialisation (data or Ajax) we need to
  4926. // calculate the column sizing
  4927. if (json || settings.oInit.aaData) {
  4928. _fnAdjustColumnSizing(settings);
  4929. }
  4930. _fnCallbackFire(settings, null, 'plugin-init', [settings, json]);
  4931. _fnCallbackFire(settings, 'aoInitComplete', 'init', [settings, json]);
  4932. }
  4933. function _fnLengthChange(settings, val) {
  4934. var len = parseInt(val, 10);
  4935. settings._iDisplayLength = len;
  4936. _fnLengthOverflow(settings);
  4937. // Fire length change event
  4938. _fnCallbackFire(settings, null, 'length', [settings, len]);
  4939. }
  4940. /**
  4941. * Generate the node required for user display length changing
  4942. * @param {object} settings dataTables settings object
  4943. * @returns {node} Display length feature node
  4944. * @memberof DataTable#oApi
  4945. */
  4946. function _fnFeatureHtmlLength(settings) {
  4947. var classes = settings.oClasses,
  4948. tableId = settings.sTableId,
  4949. menu = settings.aLengthMenu,
  4950. d2 = $.isArray(menu[0]),
  4951. lengths = d2 ? menu[0] : menu,
  4952. language = d2 ? menu[1] : menu;
  4953. var select = $('<select/>', {
  4954. 'name': tableId + '_length',
  4955. 'aria-controls': tableId,
  4956. 'class': classes.sLengthSelect
  4957. });
  4958. for (var i = 0, ien = lengths.length; i < ien; i++) {
  4959. select[0][i] = new Option(typeof language[i] === 'number' ? settings.fnFormatNumber(language[i]) : language[i], lengths[i]);
  4960. }
  4961. var div = $('<div><label/></div>').addClass(classes.sLength);
  4962. if (!settings.aanFeatures.l) {
  4963. div[0].id = tableId + '_length';
  4964. }
  4965. div.children().append(settings.oLanguage.sLengthMenu.replace('_MENU_', select[0].outerHTML));
  4966. // Can't use `select` variable as user might provide their own and the
  4967. // reference is broken by the use of outerHTML
  4968. $('select', div).val(settings._iDisplayLength).on('change.DT', function (e) {
  4969. _fnLengthChange(settings, $(this).val());
  4970. _fnDraw(settings);
  4971. });
  4972. // Update node value whenever anything changes the table's length
  4973. $(settings.nTable).on('length.dt.DT', function (e, s, len) {
  4974. if (settings === s) {
  4975. $('select', div).val(len);
  4976. }
  4977. });
  4978. return div[0];
  4979. }
  4980. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  4981. * Note that most of the paging logic is done in
  4982. * DataTable.ext.pager
  4983. */
  4984. /**
  4985. * Generate the node required for default pagination
  4986. * @param {object} oSettings dataTables settings object
  4987. * @returns {node} Pagination feature node
  4988. * @memberof DataTable#oApi
  4989. */
  4990. function _fnFeatureHtmlPaginate(settings) {
  4991. var type = settings.sPaginationType,
  4992. plugin = DataTable.ext.pager[type],
  4993. modern = typeof plugin === 'function',
  4994. redraw = function redraw(settings) {
  4995. _fnDraw(settings);
  4996. },
  4997. node = $('<div/>').addClass(settings.oClasses.sPaging + type)[0],
  4998. features = settings.aanFeatures;
  4999. if (!modern) {
  5000. plugin.fnInit(settings, node, redraw);
  5001. }
  5002. /* Add a draw callback for the pagination on first instance, to update the paging display */
  5003. if (!features.p) {
  5004. node.id = settings.sTableId + '_paginate';
  5005. settings.aoDrawCallback.push({
  5006. "fn": function fn(settings) {
  5007. if (modern) {
  5008. var start = settings._iDisplayStart,
  5009. len = settings._iDisplayLength,
  5010. visRecords = settings.fnRecordsDisplay(),
  5011. all = len === -1,
  5012. page = all ? 0 : Math.ceil(start / len),
  5013. pages = all ? 1 : Math.ceil(visRecords / len),
  5014. buttons = plugin(page, pages),
  5015. i,
  5016. ien;
  5017. for (i = 0, ien = features.p.length; i < ien; i++) {
  5018. _fnRenderer(settings, 'pageButton')(settings, features.p[i], i, buttons, page, pages);
  5019. }
  5020. } else {
  5021. plugin.fnUpdate(settings, redraw);
  5022. }
  5023. },
  5024. "sName": "pagination"
  5025. });
  5026. }
  5027. return node;
  5028. }
  5029. /**
  5030. * Alter the display settings to change the page
  5031. * @param {object} settings DataTables settings object
  5032. * @param {string|int} action Paging action to take: "first", "previous",
  5033. * "next" or "last" or page number to jump to (integer)
  5034. * @param [bool] redraw Automatically draw the update or not
  5035. * @returns {bool} true page has changed, false - no change
  5036. * @memberof DataTable#oApi
  5037. */
  5038. function _fnPageChange(settings, action, redraw) {
  5039. var start = settings._iDisplayStart,
  5040. len = settings._iDisplayLength,
  5041. records = settings.fnRecordsDisplay();
  5042. if (records === 0 || len === -1) {
  5043. start = 0;
  5044. } else if (typeof action === "number") {
  5045. start = action * len;
  5046. if (start > records) {
  5047. start = 0;
  5048. }
  5049. } else if (action == "first") {
  5050. start = 0;
  5051. } else if (action == "previous") {
  5052. start = len >= 0 ? start - len : 0;
  5053. if (start < 0) {
  5054. start = 0;
  5055. }
  5056. } else if (action == "next") {
  5057. if (start + len < records) {
  5058. start += len;
  5059. }
  5060. } else if (action == "last") {
  5061. start = Math.floor((records - 1) / len) * len;
  5062. } else {
  5063. _fnLog(settings, 0, "Unknown paging action: " + action, 5);
  5064. }
  5065. var changed = settings._iDisplayStart !== start;
  5066. settings._iDisplayStart = start;
  5067. if (changed) {
  5068. _fnCallbackFire(settings, null, 'page', [settings]);
  5069. if (redraw) {
  5070. _fnDraw(settings);
  5071. }
  5072. }
  5073. return changed;
  5074. }
  5075. /**
  5076. * Generate the node required for the processing node
  5077. * @param {object} settings dataTables settings object
  5078. * @returns {node} Processing element
  5079. * @memberof DataTable#oApi
  5080. */
  5081. function _fnFeatureHtmlProcessing(settings) {
  5082. return $('<div/>', {
  5083. 'id': !settings.aanFeatures.r ? settings.sTableId + '_processing' : null,
  5084. 'class': settings.oClasses.sProcessing
  5085. }).html(settings.oLanguage.sProcessing).insertBefore(settings.nTable)[0];
  5086. }
  5087. /**
  5088. * Display or hide the processing indicator
  5089. * @param {object} settings dataTables settings object
  5090. * @param {bool} show Show the processing indicator (true) or not (false)
  5091. * @memberof DataTable#oApi
  5092. */
  5093. function _fnProcessingDisplay(settings, show) {
  5094. if (settings.oFeatures.bProcessing) {
  5095. $(settings.aanFeatures.r).css('display', show ? 'block' : 'none');
  5096. }
  5097. _fnCallbackFire(settings, null, 'processing', [settings, show]);
  5098. }
  5099. /**
  5100. * Add any control elements for the table - specifically scrolling
  5101. * @param {object} settings dataTables settings object
  5102. * @returns {node} Node to add to the DOM
  5103. * @memberof DataTable#oApi
  5104. */
  5105. function _fnFeatureHtmlTable(settings) {
  5106. var table = $(settings.nTable);
  5107. // Add the ARIA grid role to the table
  5108. table.attr('role', 'grid');
  5109. // Scrolling from here on in
  5110. var scroll = settings.oScroll;
  5111. if (scroll.sX === '' && scroll.sY === '') {
  5112. return settings.nTable;
  5113. }
  5114. var scrollX = scroll.sX;
  5115. var scrollY = scroll.sY;
  5116. var classes = settings.oClasses;
  5117. var caption = table.children('caption');
  5118. var captionSide = caption.length ? caption[0]._captionSide : null;
  5119. var headerClone = $(table[0].cloneNode(false));
  5120. var footerClone = $(table[0].cloneNode(false));
  5121. var footer = table.children('tfoot');
  5122. var _div = '<div/>';
  5123. var size = function size(s) {
  5124. return !s ? null : _fnStringToCss(s);
  5125. };
  5126. if (!footer.length) {
  5127. footer = null;
  5128. }
  5129. /*
  5130. * The HTML structure that we want to generate in this function is:
  5131. * div - scroller
  5132. * div - scroll head
  5133. * div - scroll head inner
  5134. * table - scroll head table
  5135. * thead - thead
  5136. * div - scroll body
  5137. * table - table (master table)
  5138. * thead - thead clone for sizing
  5139. * tbody - tbody
  5140. * div - scroll foot
  5141. * div - scroll foot inner
  5142. * table - scroll foot table
  5143. * tfoot - tfoot
  5144. */
  5145. var scroller = $(_div, { 'class': classes.sScrollWrapper }).append($(_div, { 'class': classes.sScrollHead }).css({
  5146. overflow: 'hidden',
  5147. position: 'relative',
  5148. border: 0,
  5149. width: scrollX ? size(scrollX) : '100%'
  5150. }).append($(_div, { 'class': classes.sScrollHeadInner }).css({
  5151. 'box-sizing': 'content-box',
  5152. width: scroll.sXInner || '100%'
  5153. }).append(headerClone.removeAttr('id').css('margin-left', 0).append(captionSide === 'top' ? caption : null).append(table.children('thead'))))).append($(_div, { 'class': classes.sScrollBody }).css({
  5154. position: 'relative',
  5155. overflow: 'auto',
  5156. width: size(scrollX)
  5157. }).append(table));
  5158. if (footer) {
  5159. scroller.append($(_div, { 'class': classes.sScrollFoot }).css({
  5160. overflow: 'hidden',
  5161. border: 0,
  5162. width: scrollX ? size(scrollX) : '100%'
  5163. }).append($(_div, { 'class': classes.sScrollFootInner }).append(footerClone.removeAttr('id').css('margin-left', 0).append(captionSide === 'bottom' ? caption : null).append(table.children('tfoot')))));
  5164. }
  5165. var children = scroller.children();
  5166. var scrollHead = children[0];
  5167. var scrollBody = children[1];
  5168. var scrollFoot = footer ? children[2] : null;
  5169. // When the body is scrolled, then we also want to scroll the headers
  5170. if (scrollX) {
  5171. $(scrollBody).on('scroll.DT', function (e) {
  5172. var scrollLeft = this.scrollLeft;
  5173. scrollHead.scrollLeft = scrollLeft;
  5174. if (footer) {
  5175. scrollFoot.scrollLeft = scrollLeft;
  5176. }
  5177. });
  5178. }
  5179. $(scrollBody).css(scrollY && scroll.bCollapse ? 'max-height' : 'height', scrollY);
  5180. settings.nScrollHead = scrollHead;
  5181. settings.nScrollBody = scrollBody;
  5182. settings.nScrollFoot = scrollFoot;
  5183. // On redraw - align columns
  5184. settings.aoDrawCallback.push({
  5185. "fn": _fnScrollDraw,
  5186. "sName": "scrolling"
  5187. });
  5188. return scroller[0];
  5189. }
  5190. /**
  5191. * Update the header, footer and body tables for resizing - i.e. column
  5192. * alignment.
  5193. *
  5194. * Welcome to the most horrible function DataTables. The process that this
  5195. * function follows is basically:
  5196. * 1. Re-create the table inside the scrolling div
  5197. * 2. Take live measurements from the DOM
  5198. * 3. Apply the measurements to align the columns
  5199. * 4. Clean up
  5200. *
  5201. * @param {object} settings dataTables settings object
  5202. * @memberof DataTable#oApi
  5203. */
  5204. function _fnScrollDraw(settings) {
  5205. // Given that this is such a monster function, a lot of variables are use
  5206. // to try and keep the minimised size as small as possible
  5207. var scroll = settings.oScroll,
  5208. scrollX = scroll.sX,
  5209. scrollXInner = scroll.sXInner,
  5210. scrollY = scroll.sY,
  5211. barWidth = scroll.iBarWidth,
  5212. divHeader = $(settings.nScrollHead),
  5213. divHeaderStyle = divHeader[0].style,
  5214. divHeaderInner = divHeader.children('div'),
  5215. divHeaderInnerStyle = divHeaderInner[0].style,
  5216. divHeaderTable = divHeaderInner.children('table'),
  5217. divBodyEl = settings.nScrollBody,
  5218. divBody = $(divBodyEl),
  5219. divBodyStyle = divBodyEl.style,
  5220. divFooter = $(settings.nScrollFoot),
  5221. divFooterInner = divFooter.children('div'),
  5222. divFooterTable = divFooterInner.children('table'),
  5223. header = $(settings.nTHead),
  5224. table = $(settings.nTable),
  5225. tableEl = table[0],
  5226. tableStyle = tableEl.style,
  5227. footer = settings.nTFoot ? $(settings.nTFoot) : null,
  5228. browser = settings.oBrowser,
  5229. ie67 = browser.bScrollOversize,
  5230. dtHeaderCells = _pluck(settings.aoColumns, 'nTh'),
  5231. headerTrgEls,
  5232. footerTrgEls,
  5233. headerSrcEls,
  5234. footerSrcEls,
  5235. headerCopy,
  5236. footerCopy,
  5237. headerWidths = [],
  5238. footerWidths = [],
  5239. headerContent = [],
  5240. footerContent = [],
  5241. idx,
  5242. correction,
  5243. sanityWidth,
  5244. zeroOut = function zeroOut(nSizer) {
  5245. var style = nSizer.style;
  5246. style.paddingTop = "0";
  5247. style.paddingBottom = "0";
  5248. style.borderTopWidth = "0";
  5249. style.borderBottomWidth = "0";
  5250. style.height = 0;
  5251. };
  5252. // If the scrollbar visibility has changed from the last draw, we need to
  5253. // adjust the column sizes as the table width will have changed to account
  5254. // for the scrollbar
  5255. var scrollBarVis = divBodyEl.scrollHeight > divBodyEl.clientHeight;
  5256. if (settings.scrollBarVis !== scrollBarVis && settings.scrollBarVis !== undefined) {
  5257. settings.scrollBarVis = scrollBarVis;
  5258. _fnAdjustColumnSizing(settings);
  5259. return; // adjust column sizing will call this function again
  5260. } else {
  5261. settings.scrollBarVis = scrollBarVis;
  5262. }
  5263. /*
  5264. * 1. Re-create the table inside the scrolling div
  5265. */
  5266. // Remove the old minimised thead and tfoot elements in the inner table
  5267. table.children('thead, tfoot').remove();
  5268. if (footer) {
  5269. footerCopy = footer.clone().prependTo(table);
  5270. footerTrgEls = footer.find('tr'); // the original tfoot is in its own table and must be sized
  5271. footerSrcEls = footerCopy.find('tr');
  5272. }
  5273. // Clone the current header and footer elements and then place it into the inner table
  5274. headerCopy = header.clone().prependTo(table);
  5275. headerTrgEls = header.find('tr'); // original header is in its own table
  5276. headerSrcEls = headerCopy.find('tr');
  5277. headerCopy.find('th, td').removeAttr('tabindex');
  5278. /*
  5279. * 2. Take live measurements from the DOM - do not alter the DOM itself!
  5280. */
  5281. // Remove old sizing and apply the calculated column widths
  5282. // Get the unique column headers in the newly created (cloned) header. We want to apply the
  5283. // calculated sizes to this header
  5284. if (!scrollX) {
  5285. divBodyStyle.width = '100%';
  5286. divHeader[0].style.width = '100%';
  5287. }
  5288. $.each(_fnGetUniqueThs(settings, headerCopy), function (i, el) {
  5289. idx = _fnVisibleToColumnIndex(settings, i);
  5290. el.style.width = settings.aoColumns[idx].sWidth;
  5291. });
  5292. if (footer) {
  5293. _fnApplyToChildren(function (n) {
  5294. n.style.width = "";
  5295. }, footerSrcEls);
  5296. }
  5297. // Size the table as a whole
  5298. sanityWidth = table.outerWidth();
  5299. if (scrollX === "") {
  5300. // No x scrolling
  5301. tableStyle.width = "100%";
  5302. // IE7 will make the width of the table when 100% include the scrollbar
  5303. // - which is shouldn't. When there is a scrollbar we need to take this
  5304. // into account.
  5305. if (ie67 && (table.find('tbody').height() > divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")) {
  5306. tableStyle.width = _fnStringToCss(table.outerWidth() - barWidth);
  5307. }
  5308. // Recalculate the sanity width
  5309. sanityWidth = table.outerWidth();
  5310. } else if (scrollXInner !== "") {
  5311. // legacy x scroll inner has been given - use it
  5312. tableStyle.width = _fnStringToCss(scrollXInner);
  5313. // Recalculate the sanity width
  5314. sanityWidth = table.outerWidth();
  5315. }
  5316. // Hidden header should have zero height, so remove padding and borders. Then
  5317. // set the width based on the real headers
  5318. // Apply all styles in one pass
  5319. _fnApplyToChildren(zeroOut, headerSrcEls);
  5320. // Read all widths in next pass
  5321. _fnApplyToChildren(function (nSizer) {
  5322. headerContent.push(nSizer.innerHTML);
  5323. headerWidths.push(_fnStringToCss($(nSizer).css('width')));
  5324. }, headerSrcEls);
  5325. // Apply all widths in final pass
  5326. _fnApplyToChildren(function (nToSize, i) {
  5327. // Only apply widths to the DataTables detected header cells - this
  5328. // prevents complex headers from having contradictory sizes applied
  5329. if ($.inArray(nToSize, dtHeaderCells) !== -1) {
  5330. nToSize.style.width = headerWidths[i];
  5331. }
  5332. }, headerTrgEls);
  5333. $(headerSrcEls).height(0);
  5334. /* Same again with the footer if we have one */
  5335. if (footer) {
  5336. _fnApplyToChildren(zeroOut, footerSrcEls);
  5337. _fnApplyToChildren(function (nSizer) {
  5338. footerContent.push(nSizer.innerHTML);
  5339. footerWidths.push(_fnStringToCss($(nSizer).css('width')));
  5340. }, footerSrcEls);
  5341. _fnApplyToChildren(function (nToSize, i) {
  5342. nToSize.style.width = footerWidths[i];
  5343. }, footerTrgEls);
  5344. $(footerSrcEls).height(0);
  5345. }
  5346. /*
  5347. * 3. Apply the measurements
  5348. */
  5349. // "Hide" the header and footer that we used for the sizing. We need to keep
  5350. // the content of the cell so that the width applied to the header and body
  5351. // both match, but we want to hide it completely. We want to also fix their
  5352. // width to what they currently are
  5353. _fnApplyToChildren(function (nSizer, i) {
  5354. nSizer.innerHTML = '<div class="dataTables_sizing" style="height:0;overflow:hidden;">' + headerContent[i] + '</div>';
  5355. nSizer.style.width = headerWidths[i];
  5356. }, headerSrcEls);
  5357. if (footer) {
  5358. _fnApplyToChildren(function (nSizer, i) {
  5359. nSizer.innerHTML = '<div class="dataTables_sizing" style="height:0;overflow:hidden;">' + footerContent[i] + '</div>';
  5360. nSizer.style.width = footerWidths[i];
  5361. }, footerSrcEls);
  5362. }
  5363. // Sanity check that the table is of a sensible width. If not then we are going to get
  5364. // misalignment - try to prevent this by not allowing the table to shrink below its min width
  5365. if (table.outerWidth() < sanityWidth) {
  5366. // The min width depends upon if we have a vertical scrollbar visible or not */
  5367. correction = divBodyEl.scrollHeight > divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll" ? sanityWidth + barWidth : sanityWidth;
  5368. // IE6/7 are a law unto themselves...
  5369. if (ie67 && (divBodyEl.scrollHeight > divBodyEl.offsetHeight || divBody.css('overflow-y') == "scroll")) {
  5370. tableStyle.width = _fnStringToCss(correction - barWidth);
  5371. }
  5372. // And give the user a warning that we've stopped the table getting too small
  5373. if (scrollX === "" || scrollXInner !== "") {
  5374. _fnLog(settings, 1, 'Possible column misalignment', 6);
  5375. }
  5376. } else {
  5377. correction = '100%';
  5378. }
  5379. // Apply to the container elements
  5380. divBodyStyle.width = _fnStringToCss(correction);
  5381. divHeaderStyle.width = _fnStringToCss(correction);
  5382. if (footer) {
  5383. settings.nScrollFoot.style.width = _fnStringToCss(correction);
  5384. }
  5385. /*
  5386. * 4. Clean up
  5387. */
  5388. if (!scrollY) {
  5389. /* IE7< puts a vertical scrollbar in place (when it shouldn't be) due to subtracting
  5390. * the scrollbar height from the visible display, rather than adding it on. We need to
  5391. * set the height in order to sort this. Don't want to do it in any other browsers.
  5392. */
  5393. if (ie67) {
  5394. divBodyStyle.height = _fnStringToCss(tableEl.offsetHeight + barWidth);
  5395. }
  5396. }
  5397. /* Finally set the width's of the header and footer tables */
  5398. var iOuterWidth = table.outerWidth();
  5399. divHeaderTable[0].style.width = _fnStringToCss(iOuterWidth);
  5400. divHeaderInnerStyle.width = _fnStringToCss(iOuterWidth);
  5401. // Figure out if there are scrollbar present - if so then we need a the header and footer to
  5402. // provide a bit more space to allow "overflow" scrolling (i.e. past the scrollbar)
  5403. var bScrolling = table.height() > divBodyEl.clientHeight || divBody.css('overflow-y') == "scroll";
  5404. var padding = 'padding' + (browser.bScrollbarLeft ? 'Left' : 'Right');
  5405. divHeaderInnerStyle[padding] = bScrolling ? barWidth + "px" : "0px";
  5406. if (footer) {
  5407. divFooterTable[0].style.width = _fnStringToCss(iOuterWidth);
  5408. divFooterInner[0].style.width = _fnStringToCss(iOuterWidth);
  5409. divFooterInner[0].style[padding] = bScrolling ? barWidth + "px" : "0px";
  5410. }
  5411. // Correct DOM ordering for colgroup - comes before the thead
  5412. table.children('colgroup').insertBefore(table.children('thead'));
  5413. /* Adjust the position of the header in case we loose the y-scrollbar */
  5414. divBody.scroll();
  5415. // If sorting or filtering has occurred, jump the scrolling back to the top
  5416. // only if we aren't holding the position
  5417. if ((settings.bSorted || settings.bFiltered) && !settings._drawHold) {
  5418. divBodyEl.scrollTop = 0;
  5419. }
  5420. }
  5421. /**
  5422. * Apply a given function to the display child nodes of an element array (typically
  5423. * TD children of TR rows
  5424. * @param {function} fn Method to apply to the objects
  5425. * @param array {nodes} an1 List of elements to look through for display children
  5426. * @param array {nodes} an2 Another list (identical structure to the first) - optional
  5427. * @memberof DataTable#oApi
  5428. */
  5429. function _fnApplyToChildren(fn, an1, an2) {
  5430. var index = 0,
  5431. i = 0,
  5432. iLen = an1.length;
  5433. var nNode1, nNode2;
  5434. while (i < iLen) {
  5435. nNode1 = an1[i].firstChild;
  5436. nNode2 = an2 ? an2[i].firstChild : null;
  5437. while (nNode1) {
  5438. if (nNode1.nodeType === 1) {
  5439. if (an2) {
  5440. fn(nNode1, nNode2, index);
  5441. } else {
  5442. fn(nNode1, index);
  5443. }
  5444. index++;
  5445. }
  5446. nNode1 = nNode1.nextSibling;
  5447. nNode2 = an2 ? nNode2.nextSibling : null;
  5448. }
  5449. i++;
  5450. }
  5451. }
  5452. var __re_html_remove = /<.*?>/g;
  5453. /**
  5454. * Calculate the width of columns for the table
  5455. * @param {object} oSettings dataTables settings object
  5456. * @memberof DataTable#oApi
  5457. */
  5458. function _fnCalculateColumnWidths(oSettings) {
  5459. var table = oSettings.nTable,
  5460. columns = oSettings.aoColumns,
  5461. scroll = oSettings.oScroll,
  5462. scrollY = scroll.sY,
  5463. scrollX = scroll.sX,
  5464. scrollXInner = scroll.sXInner,
  5465. columnCount = columns.length,
  5466. visibleColumns = _fnGetColumns(oSettings, 'bVisible'),
  5467. headerCells = $('th', oSettings.nTHead),
  5468. tableWidthAttr = table.getAttribute('width'),
  5469. // from DOM element
  5470. tableContainer = table.parentNode,
  5471. userInputs = false,
  5472. i,
  5473. column,
  5474. columnIdx,
  5475. width,
  5476. outerWidth,
  5477. browser = oSettings.oBrowser,
  5478. ie67 = browser.bScrollOversize;
  5479. var styleWidth = table.style.width;
  5480. if (styleWidth && styleWidth.indexOf('%') !== -1) {
  5481. tableWidthAttr = styleWidth;
  5482. }
  5483. /* Convert any user input sizes into pixel sizes */
  5484. for (i = 0; i < visibleColumns.length; i++) {
  5485. column = columns[visibleColumns[i]];
  5486. if (column.sWidth !== null) {
  5487. column.sWidth = _fnConvertToWidth(column.sWidthOrig, tableContainer);
  5488. userInputs = true;
  5489. }
  5490. }
  5491. /* If the number of columns in the DOM equals the number that we have to
  5492. * process in DataTables, then we can use the offsets that are created by
  5493. * the web- browser. No custom sizes can be set in order for this to happen,
  5494. * nor scrolling used
  5495. */
  5496. if (ie67 || !userInputs && !scrollX && !scrollY && columnCount == _fnVisbleColumns(oSettings) && columnCount == headerCells.length) {
  5497. for (i = 0; i < columnCount; i++) {
  5498. var colIdx = _fnVisibleToColumnIndex(oSettings, i);
  5499. if (colIdx !== null) {
  5500. columns[colIdx].sWidth = _fnStringToCss(headerCells.eq(i).width());
  5501. }
  5502. }
  5503. } else {
  5504. // Otherwise construct a single row, worst case, table with the widest
  5505. // node in the data, assign any user defined widths, then insert it into
  5506. // the DOM and allow the browser to do all the hard work of calculating
  5507. // table widths
  5508. var tmpTable = $(table).clone() // don't use cloneNode - IE8 will remove events on the main table
  5509. .css('visibility', 'hidden').removeAttr('id');
  5510. // Clean up the table body
  5511. tmpTable.find('tbody tr').remove();
  5512. var tr = $('<tr/>').appendTo(tmpTable.find('tbody'));
  5513. // Clone the table header and footer - we can't use the header / footer
  5514. // from the cloned table, since if scrolling is active, the table's
  5515. // real header and footer are contained in different table tags
  5516. tmpTable.find('thead, tfoot').remove();
  5517. tmpTable.append($(oSettings.nTHead).clone()).append($(oSettings.nTFoot).clone());
  5518. // Remove any assigned widths from the footer (from scrolling)
  5519. tmpTable.find('tfoot th, tfoot td').css('width', '');
  5520. // Apply custom sizing to the cloned header
  5521. headerCells = _fnGetUniqueThs(oSettings, tmpTable.find('thead')[0]);
  5522. for (i = 0; i < visibleColumns.length; i++) {
  5523. column = columns[visibleColumns[i]];
  5524. headerCells[i].style.width = column.sWidthOrig !== null && column.sWidthOrig !== '' ? _fnStringToCss(column.sWidthOrig) : '';
  5525. // For scrollX we need to force the column width otherwise the
  5526. // browser will collapse it. If this width is smaller than the
  5527. // width the column requires, then it will have no effect
  5528. if (column.sWidthOrig && scrollX) {
  5529. $(headerCells[i]).append($('<div/>').css({
  5530. width: column.sWidthOrig,
  5531. margin: 0,
  5532. padding: 0,
  5533. border: 0,
  5534. height: 1
  5535. }));
  5536. }
  5537. }
  5538. // Find the widest cell for each column and put it into the table
  5539. if (oSettings.aoData.length) {
  5540. for (i = 0; i < visibleColumns.length; i++) {
  5541. columnIdx = visibleColumns[i];
  5542. column = columns[columnIdx];
  5543. $(_fnGetWidestNode(oSettings, columnIdx)).clone(false).append(column.sContentPadding).appendTo(tr);
  5544. }
  5545. }
  5546. // Tidy the temporary table - remove name attributes so there aren't
  5547. // duplicated in the dom (radio elements for example)
  5548. $('[name]', tmpTable).removeAttr('name');
  5549. // Table has been built, attach to the document so we can work with it.
  5550. // A holding element is used, positioned at the top of the container
  5551. // with minimal height, so it has no effect on if the container scrolls
  5552. // or not. Otherwise it might trigger scrolling when it actually isn't
  5553. // needed
  5554. var holder = $('<div/>').css(scrollX || scrollY ? {
  5555. position: 'absolute',
  5556. top: 0,
  5557. left: 0,
  5558. height: 1,
  5559. right: 0,
  5560. overflow: 'hidden'
  5561. } : {}).append(tmpTable).appendTo(tableContainer);
  5562. // When scrolling (X or Y) we want to set the width of the table as
  5563. // appropriate. However, when not scrolling leave the table width as it
  5564. // is. This results in slightly different, but I think correct behaviour
  5565. if (scrollX && scrollXInner) {
  5566. tmpTable.width(scrollXInner);
  5567. } else if (scrollX) {
  5568. tmpTable.css('width', 'auto');
  5569. tmpTable.removeAttr('width');
  5570. // If there is no width attribute or style, then allow the table to
  5571. // collapse
  5572. if (tmpTable.width() < tableContainer.clientWidth && tableWidthAttr) {
  5573. tmpTable.width(tableContainer.clientWidth);
  5574. }
  5575. } else if (scrollY) {
  5576. tmpTable.width(tableContainer.clientWidth);
  5577. } else if (tableWidthAttr) {
  5578. tmpTable.width(tableWidthAttr);
  5579. }
  5580. // Get the width of each column in the constructed table - we need to
  5581. // know the inner width (so it can be assigned to the other table's
  5582. // cells) and the outer width so we can calculate the full width of the
  5583. // table. This is safe since DataTables requires a unique cell for each
  5584. // column, but if ever a header can span multiple columns, this will
  5585. // need to be modified.
  5586. var total = 0;
  5587. for (i = 0; i < visibleColumns.length; i++) {
  5588. var cell = $(headerCells[i]);
  5589. var border = cell.outerWidth() - cell.width();
  5590. // Use getBounding... where possible (not IE8-) because it can give
  5591. // sub-pixel accuracy, which we then want to round up!
  5592. var bounding = browser.bBounding ? Math.ceil(headerCells[i].getBoundingClientRect().width) : cell.outerWidth();
  5593. // Total is tracked to remove any sub-pixel errors as the outerWidth
  5594. // of the table might not equal the total given here (IE!).
  5595. total += bounding;
  5596. // Width for each column to use
  5597. columns[visibleColumns[i]].sWidth = _fnStringToCss(bounding - border);
  5598. }
  5599. table.style.width = _fnStringToCss(total);
  5600. // Finished with the table - ditch it
  5601. holder.remove();
  5602. }
  5603. // If there is a width attr, we want to attach an event listener which
  5604. // allows the table sizing to automatically adjust when the window is
  5605. // resized. Use the width attr rather than CSS, since we can't know if the
  5606. // CSS is a relative value or absolute - DOM read is always px.
  5607. if (tableWidthAttr) {
  5608. table.style.width = _fnStringToCss(tableWidthAttr);
  5609. }
  5610. if ((tableWidthAttr || scrollX) && !oSettings._reszEvt) {
  5611. var bindResize = function bindResize() {
  5612. $(window).on('resize.DT-' + oSettings.sInstance, _fnThrottle(function () {
  5613. _fnAdjustColumnSizing(oSettings);
  5614. }));
  5615. };
  5616. // IE6/7 will crash if we bind a resize event handler on page load.
  5617. // To be removed in 1.11 which drops IE6/7 support
  5618. if (ie67) {
  5619. setTimeout(bindResize, 1000);
  5620. } else {
  5621. bindResize();
  5622. }
  5623. oSettings._reszEvt = true;
  5624. }
  5625. }
  5626. /**
  5627. * Throttle the calls to a function. Arguments and context are maintained for
  5628. * the throttled function
  5629. * @param {function} fn Function to be called
  5630. * @param {int} [freq=200] call frequency in mS
  5631. * @returns {function} wrapped function
  5632. * @memberof DataTable#oApi
  5633. */
  5634. var _fnThrottle = DataTable.util.throttle;
  5635. /**
  5636. * Convert a CSS unit width to pixels (e.g. 2em)
  5637. * @param {string} width width to be converted
  5638. * @param {node} parent parent to get the with for (required for relative widths) - optional
  5639. * @returns {int} width in pixels
  5640. * @memberof DataTable#oApi
  5641. */
  5642. function _fnConvertToWidth(width, parent) {
  5643. if (!width) {
  5644. return 0;
  5645. }
  5646. var n = $('<div/>').css('width', _fnStringToCss(width)).appendTo(parent || document.body);
  5647. var val = n[0].offsetWidth;
  5648. n.remove();
  5649. return val;
  5650. }
  5651. /**
  5652. * Get the widest node
  5653. * @param {object} settings dataTables settings object
  5654. * @param {int} colIdx column of interest
  5655. * @returns {node} widest table node
  5656. * @memberof DataTable#oApi
  5657. */
  5658. function _fnGetWidestNode(settings, colIdx) {
  5659. var idx = _fnGetMaxLenString(settings, colIdx);
  5660. if (idx < 0) {
  5661. return null;
  5662. }
  5663. var data = settings.aoData[idx];
  5664. return !data.nTr ? // Might not have been created when deferred rendering
  5665. $('<td/>').html(_fnGetCellData(settings, idx, colIdx, 'display'))[0] : data.anCells[colIdx];
  5666. }
  5667. /**
  5668. * Get the maximum strlen for each data column
  5669. * @param {object} settings dataTables settings object
  5670. * @param {int} colIdx column of interest
  5671. * @returns {string} max string length for each column
  5672. * @memberof DataTable#oApi
  5673. */
  5674. function _fnGetMaxLenString(settings, colIdx) {
  5675. var s,
  5676. max = -1,
  5677. maxIdx = -1;
  5678. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  5679. s = _fnGetCellData(settings, i, colIdx, 'display') + '';
  5680. s = s.replace(__re_html_remove, '');
  5681. s = s.replace(/&nbsp;/g, ' ');
  5682. if (s.length > max) {
  5683. max = s.length;
  5684. maxIdx = i;
  5685. }
  5686. }
  5687. return maxIdx;
  5688. }
  5689. /**
  5690. * Append a CSS unit (only if required) to a string
  5691. * @param {string} value to css-ify
  5692. * @returns {string} value with css unit
  5693. * @memberof DataTable#oApi
  5694. */
  5695. function _fnStringToCss(s) {
  5696. if (s === null) {
  5697. return '0px';
  5698. }
  5699. if (typeof s == 'number') {
  5700. return s < 0 ? '0px' : s + 'px';
  5701. }
  5702. // Check it has a unit character already
  5703. return s.match(/\d$/) ? s + 'px' : s;
  5704. }
  5705. function _fnSortFlatten(settings) {
  5706. var i,
  5707. iLen,
  5708. k,
  5709. kLen,
  5710. aSort = [],
  5711. aiOrig = [],
  5712. aoColumns = settings.aoColumns,
  5713. aDataSort,
  5714. iCol,
  5715. sType,
  5716. srcCol,
  5717. fixed = settings.aaSortingFixed,
  5718. fixedObj = $.isPlainObject(fixed),
  5719. nestedSort = [],
  5720. add = function add(a) {
  5721. if (a.length && !$.isArray(a[0])) {
  5722. // 1D array
  5723. nestedSort.push(a);
  5724. } else {
  5725. // 2D array
  5726. $.merge(nestedSort, a);
  5727. }
  5728. };
  5729. // Build the sort array, with pre-fix and post-fix options if they have been
  5730. // specified
  5731. if ($.isArray(fixed)) {
  5732. add(fixed);
  5733. }
  5734. if (fixedObj && fixed.pre) {
  5735. add(fixed.pre);
  5736. }
  5737. add(settings.aaSorting);
  5738. if (fixedObj && fixed.post) {
  5739. add(fixed.post);
  5740. }
  5741. for (i = 0; i < nestedSort.length; i++) {
  5742. srcCol = nestedSort[i][0];
  5743. aDataSort = aoColumns[srcCol].aDataSort;
  5744. for (k = 0, kLen = aDataSort.length; k < kLen; k++) {
  5745. iCol = aDataSort[k];
  5746. sType = aoColumns[iCol].sType || 'string';
  5747. if (nestedSort[i]._idx === undefined) {
  5748. nestedSort[i]._idx = $.inArray(nestedSort[i][1], aoColumns[iCol].asSorting);
  5749. }
  5750. aSort.push({
  5751. src: srcCol,
  5752. col: iCol,
  5753. dir: nestedSort[i][1],
  5754. index: nestedSort[i]._idx,
  5755. type: sType,
  5756. formatter: DataTable.ext.type.order[sType + "-pre"]
  5757. });
  5758. }
  5759. }
  5760. return aSort;
  5761. }
  5762. /**
  5763. * Change the order of the table
  5764. * @param {object} oSettings dataTables settings object
  5765. * @memberof DataTable#oApi
  5766. * @todo This really needs split up!
  5767. */
  5768. function _fnSort(oSettings) {
  5769. var i,
  5770. ien,
  5771. iLen,
  5772. j,
  5773. jLen,
  5774. k,
  5775. kLen,
  5776. sDataType,
  5777. nTh,
  5778. aiOrig = [],
  5779. oExtSort = DataTable.ext.type.order,
  5780. aoData = oSettings.aoData,
  5781. aoColumns = oSettings.aoColumns,
  5782. aDataSort,
  5783. data,
  5784. iCol,
  5785. sType,
  5786. oSort,
  5787. formatters = 0,
  5788. sortCol,
  5789. displayMaster = oSettings.aiDisplayMaster,
  5790. aSort;
  5791. // Resolve any column types that are unknown due to addition or invalidation
  5792. // @todo Can this be moved into a 'data-ready' handler which is called when
  5793. // data is going to be used in the table?
  5794. _fnColumnTypes(oSettings);
  5795. aSort = _fnSortFlatten(oSettings);
  5796. for (i = 0, ien = aSort.length; i < ien; i++) {
  5797. sortCol = aSort[i];
  5798. // Track if we can use the fast sort algorithm
  5799. if (sortCol.formatter) {
  5800. formatters++;
  5801. }
  5802. // Load the data needed for the sort, for each cell
  5803. _fnSortData(oSettings, sortCol.col);
  5804. }
  5805. /* No sorting required if server-side or no sorting array */
  5806. if (_fnDataSource(oSettings) != 'ssp' && aSort.length !== 0) {
  5807. // Create a value - key array of the current row positions such that we can use their
  5808. // current position during the sort, if values match, in order to perform stable sorting
  5809. for (i = 0, iLen = displayMaster.length; i < iLen; i++) {
  5810. aiOrig[displayMaster[i]] = i;
  5811. }
  5812. /* Do the sort - here we want multi-column sorting based on a given data source (column)
  5813. * and sorting function (from oSort) in a certain direction. It's reasonably complex to
  5814. * follow on it's own, but this is what we want (example two column sorting):
  5815. * fnLocalSorting = function(a,b){
  5816. * var iTest;
  5817. * iTest = oSort['string-asc']('data11', 'data12');
  5818. * if (iTest !== 0)
  5819. * return iTest;
  5820. * iTest = oSort['numeric-desc']('data21', 'data22');
  5821. * if (iTest !== 0)
  5822. * return iTest;
  5823. * return oSort['numeric-asc']( aiOrig[a], aiOrig[b] );
  5824. * }
  5825. * Basically we have a test for each sorting column, if the data in that column is equal,
  5826. * test the next column. If all columns match, then we use a numeric sort on the row
  5827. * positions in the original data array to provide a stable sort.
  5828. *
  5829. * Note - I know it seems excessive to have two sorting methods, but the first is around
  5830. * 15% faster, so the second is only maintained for backwards compatibility with sorting
  5831. * methods which do not have a pre-sort formatting function.
  5832. */
  5833. if (formatters === aSort.length) {
  5834. // All sort types have formatting functions
  5835. displayMaster.sort(function (a, b) {
  5836. var x,
  5837. y,
  5838. k,
  5839. test,
  5840. sort,
  5841. len = aSort.length,
  5842. dataA = aoData[a]._aSortData,
  5843. dataB = aoData[b]._aSortData;
  5844. for (k = 0; k < len; k++) {
  5845. sort = aSort[k];
  5846. x = dataA[sort.col];
  5847. y = dataB[sort.col];
  5848. test = x < y ? -1 : x > y ? 1 : 0;
  5849. if (test !== 0) {
  5850. return sort.dir === 'asc' ? test : -test;
  5851. }
  5852. }
  5853. x = aiOrig[a];
  5854. y = aiOrig[b];
  5855. return x < y ? -1 : x > y ? 1 : 0;
  5856. });
  5857. } else {
  5858. // Depreciated - remove in 1.11 (providing a plug-in option)
  5859. // Not all sort types have formatting methods, so we have to call their sorting
  5860. // methods.
  5861. displayMaster.sort(function (a, b) {
  5862. var x,
  5863. y,
  5864. k,
  5865. l,
  5866. test,
  5867. sort,
  5868. fn,
  5869. len = aSort.length,
  5870. dataA = aoData[a]._aSortData,
  5871. dataB = aoData[b]._aSortData;
  5872. for (k = 0; k < len; k++) {
  5873. sort = aSort[k];
  5874. x = dataA[sort.col];
  5875. y = dataB[sort.col];
  5876. fn = oExtSort[sort.type + "-" + sort.dir] || oExtSort["string-" + sort.dir];
  5877. test = fn(x, y);
  5878. if (test !== 0) {
  5879. return test;
  5880. }
  5881. }
  5882. x = aiOrig[a];
  5883. y = aiOrig[b];
  5884. return x < y ? -1 : x > y ? 1 : 0;
  5885. });
  5886. }
  5887. }
  5888. /* Tell the draw function that we have sorted the data */
  5889. oSettings.bSorted = true;
  5890. }
  5891. function _fnSortAria(settings) {
  5892. var label;
  5893. var nextSort;
  5894. var columns = settings.aoColumns;
  5895. var aSort = _fnSortFlatten(settings);
  5896. var oAria = settings.oLanguage.oAria;
  5897. // ARIA attributes - need to loop all columns, to update all (removing old
  5898. // attributes as needed)
  5899. for (var i = 0, iLen = columns.length; i < iLen; i++) {
  5900. var col = columns[i];
  5901. var asSorting = col.asSorting;
  5902. var sTitle = col.sTitle.replace(/<.*?>/g, "");
  5903. var th = col.nTh;
  5904. // IE7 is throwing an error when setting these properties with jQuery's
  5905. // attr() and removeAttr() methods...
  5906. th.removeAttribute('aria-sort');
  5907. /* In ARIA only the first sorting column can be marked as sorting - no multi-sort option */
  5908. if (col.bSortable) {
  5909. if (aSort.length > 0 && aSort[0].col == i) {
  5910. th.setAttribute('aria-sort', aSort[0].dir == "asc" ? "ascending" : "descending");
  5911. nextSort = asSorting[aSort[0].index + 1] || asSorting[0];
  5912. } else {
  5913. nextSort = asSorting[0];
  5914. }
  5915. label = sTitle + (nextSort === "asc" ? oAria.sSortAscending : oAria.sSortDescending);
  5916. } else {
  5917. label = sTitle;
  5918. }
  5919. th.setAttribute('aria-label', label);
  5920. }
  5921. }
  5922. /**
  5923. * Function to run on user sort request
  5924. * @param {object} settings dataTables settings object
  5925. * @param {node} attachTo node to attach the handler to
  5926. * @param {int} colIdx column sorting index
  5927. * @param {boolean} [append=false] Append the requested sort to the existing
  5928. * sort if true (i.e. multi-column sort)
  5929. * @param {function} [callback] callback function
  5930. * @memberof DataTable#oApi
  5931. */
  5932. function _fnSortListener(settings, colIdx, append, callback) {
  5933. var col = settings.aoColumns[colIdx];
  5934. var sorting = settings.aaSorting;
  5935. var asSorting = col.asSorting;
  5936. var nextSortIdx;
  5937. var next = function next(a, overflow) {
  5938. var idx = a._idx;
  5939. if (idx === undefined) {
  5940. idx = $.inArray(a[1], asSorting);
  5941. }
  5942. return idx + 1 < asSorting.length ? idx + 1 : overflow ? null : 0;
  5943. };
  5944. // Convert to 2D array if needed
  5945. if (typeof sorting[0] === 'number') {
  5946. sorting = settings.aaSorting = [sorting];
  5947. }
  5948. // If appending the sort then we are multi-column sorting
  5949. if (append && settings.oFeatures.bSortMulti) {
  5950. // Are we already doing some kind of sort on this column?
  5951. var sortIdx = $.inArray(colIdx, _pluck(sorting, '0'));
  5952. if (sortIdx !== -1) {
  5953. // Yes, modify the sort
  5954. nextSortIdx = next(sorting[sortIdx], true);
  5955. if (nextSortIdx === null && sorting.length === 1) {
  5956. nextSortIdx = 0; // can't remove sorting completely
  5957. }
  5958. if (nextSortIdx === null) {
  5959. sorting.splice(sortIdx, 1);
  5960. } else {
  5961. sorting[sortIdx][1] = asSorting[nextSortIdx];
  5962. sorting[sortIdx]._idx = nextSortIdx;
  5963. }
  5964. } else {
  5965. // No sort on this column yet
  5966. sorting.push([colIdx, asSorting[0], 0]);
  5967. sorting[sorting.length - 1]._idx = 0;
  5968. }
  5969. } else if (sorting.length && sorting[0][0] == colIdx) {
  5970. // Single column - already sorting on this column, modify the sort
  5971. nextSortIdx = next(sorting[0]);
  5972. sorting.length = 1;
  5973. sorting[0][1] = asSorting[nextSortIdx];
  5974. sorting[0]._idx = nextSortIdx;
  5975. } else {
  5976. // Single column - sort only on this column
  5977. sorting.length = 0;
  5978. sorting.push([colIdx, asSorting[0]]);
  5979. sorting[0]._idx = 0;
  5980. }
  5981. // Run the sort by calling a full redraw
  5982. _fnReDraw(settings);
  5983. // callback used for async user interaction
  5984. if (typeof callback == 'function') {
  5985. callback(settings);
  5986. }
  5987. }
  5988. /**
  5989. * Attach a sort handler (click) to a node
  5990. * @param {object} settings dataTables settings object
  5991. * @param {node} attachTo node to attach the handler to
  5992. * @param {int} colIdx column sorting index
  5993. * @param {function} [callback] callback function
  5994. * @memberof DataTable#oApi
  5995. */
  5996. function _fnSortAttachListener(settings, attachTo, colIdx, callback) {
  5997. var col = settings.aoColumns[colIdx];
  5998. _fnBindAction(attachTo, {}, function (e) {
  5999. /* If the column is not sortable - don't to anything */
  6000. if (col.bSortable === false) {
  6001. return;
  6002. }
  6003. // If processing is enabled use a timeout to allow the processing
  6004. // display to be shown - otherwise to it synchronously
  6005. if (settings.oFeatures.bProcessing) {
  6006. _fnProcessingDisplay(settings, true);
  6007. setTimeout(function () {
  6008. _fnSortListener(settings, colIdx, e.shiftKey, callback);
  6009. // In server-side processing, the draw callback will remove the
  6010. // processing display
  6011. if (_fnDataSource(settings) !== 'ssp') {
  6012. _fnProcessingDisplay(settings, false);
  6013. }
  6014. }, 0);
  6015. } else {
  6016. _fnSortListener(settings, colIdx, e.shiftKey, callback);
  6017. }
  6018. });
  6019. }
  6020. /**
  6021. * Set the sorting classes on table's body, Note: it is safe to call this function
  6022. * when bSort and bSortClasses are false
  6023. * @param {object} oSettings dataTables settings object
  6024. * @memberof DataTable#oApi
  6025. */
  6026. function _fnSortingClasses(settings) {
  6027. var oldSort = settings.aLastSort;
  6028. var sortClass = settings.oClasses.sSortColumn;
  6029. var sort = _fnSortFlatten(settings);
  6030. var features = settings.oFeatures;
  6031. var i, ien, colIdx;
  6032. if (features.bSort && features.bSortClasses) {
  6033. // Remove old sorting classes
  6034. for (i = 0, ien = oldSort.length; i < ien; i++) {
  6035. colIdx = oldSort[i].src;
  6036. // Remove column sorting
  6037. $(_pluck(settings.aoData, 'anCells', colIdx)).removeClass(sortClass + (i < 2 ? i + 1 : 3));
  6038. }
  6039. // Add new column sorting
  6040. for (i = 0, ien = sort.length; i < ien; i++) {
  6041. colIdx = sort[i].src;
  6042. $(_pluck(settings.aoData, 'anCells', colIdx)).addClass(sortClass + (i < 2 ? i + 1 : 3));
  6043. }
  6044. }
  6045. settings.aLastSort = sort;
  6046. }
  6047. // Get the data to sort a column, be it from cache, fresh (populating the
  6048. // cache), or from a sort formatter
  6049. function _fnSortData(settings, idx) {
  6050. // Custom sorting function - provided by the sort data type
  6051. var column = settings.aoColumns[idx];
  6052. var customSort = DataTable.ext.order[column.sSortDataType];
  6053. var customData;
  6054. if (customSort) {
  6055. customData = customSort.call(settings.oInstance, settings, idx, _fnColumnIndexToVisible(settings, idx));
  6056. }
  6057. // Use / populate cache
  6058. var row, cellData;
  6059. var formatter = DataTable.ext.type.order[column.sType + "-pre"];
  6060. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  6061. row = settings.aoData[i];
  6062. if (!row._aSortData) {
  6063. row._aSortData = [];
  6064. }
  6065. if (!row._aSortData[idx] || customSort) {
  6066. cellData = customSort ? customData[i] : // If there was a custom sort function, use data from there
  6067. _fnGetCellData(settings, i, idx, 'sort');
  6068. row._aSortData[idx] = formatter ? formatter(cellData) : cellData;
  6069. }
  6070. }
  6071. }
  6072. /**
  6073. * Save the state of a table
  6074. * @param {object} oSettings dataTables settings object
  6075. * @memberof DataTable#oApi
  6076. */
  6077. function _fnSaveState(settings) {
  6078. if (!settings.oFeatures.bStateSave || settings.bDestroying) {
  6079. return;
  6080. }
  6081. /* Store the interesting variables */
  6082. var state = {
  6083. time: +new Date(),
  6084. start: settings._iDisplayStart,
  6085. length: settings._iDisplayLength,
  6086. order: $.extend(true, [], settings.aaSorting),
  6087. search: _fnSearchToCamel(settings.oPreviousSearch),
  6088. columns: $.map(settings.aoColumns, function (col, i) {
  6089. return {
  6090. visible: col.bVisible,
  6091. search: _fnSearchToCamel(settings.aoPreSearchCols[i])
  6092. };
  6093. })
  6094. };
  6095. _fnCallbackFire(settings, "aoStateSaveParams", 'stateSaveParams', [settings, state]);
  6096. settings.oSavedState = state;
  6097. settings.fnStateSaveCallback.call(settings.oInstance, settings, state);
  6098. }
  6099. /**
  6100. * Attempt to load a saved table state
  6101. * @param {object} oSettings dataTables settings object
  6102. * @param {object} oInit DataTables init object so we can override settings
  6103. * @param {function} callback Callback to execute when the state has been loaded
  6104. * @memberof DataTable#oApi
  6105. */
  6106. function _fnLoadState(settings, oInit, callback) {
  6107. var i, ien;
  6108. var columns = settings.aoColumns;
  6109. var loaded = function loaded(s) {
  6110. if (!s || !s.time) {
  6111. callback();
  6112. return;
  6113. }
  6114. // Allow custom and plug-in manipulation functions to alter the saved data set and
  6115. // cancelling of loading by returning false
  6116. var abStateLoad = _fnCallbackFire(settings, 'aoStateLoadParams', 'stateLoadParams', [settings, s]);
  6117. if ($.inArray(false, abStateLoad) !== -1) {
  6118. callback();
  6119. return;
  6120. }
  6121. // Reject old data
  6122. var duration = settings.iStateDuration;
  6123. if (duration > 0 && s.time < +new Date() - duration * 1000) {
  6124. callback();
  6125. return;
  6126. }
  6127. // Number of columns have changed - all bets are off, no restore of settings
  6128. if (s.columns && columns.length !== s.columns.length) {
  6129. callback();
  6130. return;
  6131. }
  6132. // Store the saved state so it might be accessed at any time
  6133. settings.oLoadedState = $.extend(true, {}, s);
  6134. // Restore key features - todo - for 1.11 this needs to be done by
  6135. // subscribed events
  6136. if (s.start !== undefined) {
  6137. settings._iDisplayStart = s.start;
  6138. settings.iInitDisplayStart = s.start;
  6139. }
  6140. if (s.length !== undefined) {
  6141. settings._iDisplayLength = s.length;
  6142. }
  6143. // Order
  6144. if (s.order !== undefined) {
  6145. settings.aaSorting = [];
  6146. $.each(s.order, function (i, col) {
  6147. settings.aaSorting.push(col[0] >= columns.length ? [0, col[1]] : col);
  6148. });
  6149. }
  6150. // Search
  6151. if (s.search !== undefined) {
  6152. $.extend(settings.oPreviousSearch, _fnSearchToHung(s.search));
  6153. }
  6154. // Columns
  6155. //
  6156. if (s.columns) {
  6157. for (i = 0, ien = s.columns.length; i < ien; i++) {
  6158. var col = s.columns[i];
  6159. // Visibility
  6160. if (col.visible !== undefined) {
  6161. columns[i].bVisible = col.visible;
  6162. }
  6163. // Search
  6164. if (col.search !== undefined) {
  6165. $.extend(settings.aoPreSearchCols[i], _fnSearchToHung(col.search));
  6166. }
  6167. }
  6168. }
  6169. _fnCallbackFire(settings, 'aoStateLoaded', 'stateLoaded', [settings, s]);
  6170. callback();
  6171. };
  6172. if (!settings.oFeatures.bStateSave) {
  6173. callback();
  6174. return;
  6175. }
  6176. var state = settings.fnStateLoadCallback.call(settings.oInstance, settings, loaded);
  6177. if (state !== undefined) {
  6178. loaded(state);
  6179. }
  6180. // otherwise, wait for the loaded callback to be executed
  6181. }
  6182. /**
  6183. * Return the settings object for a particular table
  6184. * @param {node} table table we are using as a dataTable
  6185. * @returns {object} Settings object - or null if not found
  6186. * @memberof DataTable#oApi
  6187. */
  6188. function _fnSettingsFromNode(table) {
  6189. var settings = DataTable.settings;
  6190. var idx = $.inArray(table, _pluck(settings, 'nTable'));
  6191. return idx !== -1 ? settings[idx] : null;
  6192. }
  6193. /**
  6194. * Log an error message
  6195. * @param {object} settings dataTables settings object
  6196. * @param {int} level log error messages, or display them to the user
  6197. * @param {string} msg error message
  6198. * @param {int} tn Technical note id to get more information about the error.
  6199. * @memberof DataTable#oApi
  6200. */
  6201. function _fnLog(settings, level, msg, tn) {
  6202. msg = 'DataTables warning: ' + (settings ? 'table id=' + settings.sTableId + ' - ' : '') + msg;
  6203. if (tn) {
  6204. msg += '. For more information about this error, please see ' + 'http://datatables.net/tn/' + tn;
  6205. }
  6206. if (!level) {
  6207. // Backwards compatibility pre 1.10
  6208. var ext = DataTable.ext;
  6209. var type = ext.sErrMode || ext.errMode;
  6210. if (settings) {
  6211. _fnCallbackFire(settings, null, 'error', [settings, tn, msg]);
  6212. }
  6213. if (type == 'alert') {
  6214. alert(msg);
  6215. } else if (type == 'throw') {
  6216. throw new Error(msg);
  6217. } else if (typeof type == 'function') {
  6218. type(settings, tn, msg);
  6219. }
  6220. } else if (window.console && console.log) {
  6221. console.log(msg);
  6222. }
  6223. }
  6224. /**
  6225. * See if a property is defined on one object, if so assign it to the other object
  6226. * @param {object} ret target object
  6227. * @param {object} src source object
  6228. * @param {string} name property
  6229. * @param {string} [mappedName] name to map too - optional, name used if not given
  6230. * @memberof DataTable#oApi
  6231. */
  6232. function _fnMap(ret, src, name, mappedName) {
  6233. if ($.isArray(name)) {
  6234. $.each(name, function (i, val) {
  6235. if ($.isArray(val)) {
  6236. _fnMap(ret, src, val[0], val[1]);
  6237. } else {
  6238. _fnMap(ret, src, val);
  6239. }
  6240. });
  6241. return;
  6242. }
  6243. if (mappedName === undefined) {
  6244. mappedName = name;
  6245. }
  6246. if (src[name] !== undefined) {
  6247. ret[mappedName] = src[name];
  6248. }
  6249. }
  6250. /**
  6251. * Extend objects - very similar to jQuery.extend, but deep copy objects, and
  6252. * shallow copy arrays. The reason we need to do this, is that we don't want to
  6253. * deep copy array init values (such as aaSorting) since the dev wouldn't be
  6254. * able to override them, but we do want to deep copy arrays.
  6255. * @param {object} out Object to extend
  6256. * @param {object} extender Object from which the properties will be applied to
  6257. * out
  6258. * @param {boolean} breakRefs If true, then arrays will be sliced to take an
  6259. * independent copy with the exception of the `data` or `aaData` parameters
  6260. * if they are present. This is so you can pass in a collection to
  6261. * DataTables and have that used as your data source without breaking the
  6262. * references
  6263. * @returns {object} out Reference, just for convenience - out === the return.
  6264. * @memberof DataTable#oApi
  6265. * @todo This doesn't take account of arrays inside the deep copied objects.
  6266. */
  6267. function _fnExtend(out, extender, breakRefs) {
  6268. var val;
  6269. for (var prop in extender) {
  6270. if (extender.hasOwnProperty(prop)) {
  6271. val = extender[prop];
  6272. if ($.isPlainObject(val)) {
  6273. if (!$.isPlainObject(out[prop])) {
  6274. out[prop] = {};
  6275. }
  6276. $.extend(true, out[prop], val);
  6277. } else if (breakRefs && prop !== 'data' && prop !== 'aaData' && $.isArray(val)) {
  6278. out[prop] = val.slice();
  6279. } else {
  6280. out[prop] = val;
  6281. }
  6282. }
  6283. }
  6284. return out;
  6285. }
  6286. /**
  6287. * Bind an event handers to allow a click or return key to activate the callback.
  6288. * This is good for accessibility since a return on the keyboard will have the
  6289. * same effect as a click, if the element has focus.
  6290. * @param {element} n Element to bind the action to
  6291. * @param {object} oData Data object to pass to the triggered function
  6292. * @param {function} fn Callback function for when the event is triggered
  6293. * @memberof DataTable#oApi
  6294. */
  6295. function _fnBindAction(n, oData, fn) {
  6296. $(n).on('click.DT', oData, function (e) {
  6297. n.blur(); // Remove focus outline for mouse users
  6298. fn(e);
  6299. }).on('keypress.DT', oData, function (e) {
  6300. if (e.which === 13) {
  6301. e.preventDefault();
  6302. fn(e);
  6303. }
  6304. }).on('selectstart.DT', function () {
  6305. /* Take the brutal approach to cancelling text selection */
  6306. return false;
  6307. });
  6308. }
  6309. /**
  6310. * Register a callback function. Easily allows a callback function to be added to
  6311. * an array store of callback functions that can then all be called together.
  6312. * @param {object} oSettings dataTables settings object
  6313. * @param {string} sStore Name of the array storage for the callbacks in oSettings
  6314. * @param {function} fn Function to be called back
  6315. * @param {string} sName Identifying name for the callback (i.e. a label)
  6316. * @memberof DataTable#oApi
  6317. */
  6318. function _fnCallbackReg(oSettings, sStore, fn, sName) {
  6319. if (fn) {
  6320. oSettings[sStore].push({
  6321. "fn": fn,
  6322. "sName": sName
  6323. });
  6324. }
  6325. }
  6326. /**
  6327. * Fire callback functions and trigger events. Note that the loop over the
  6328. * callback array store is done backwards! Further note that you do not want to
  6329. * fire off triggers in time sensitive applications (for example cell creation)
  6330. * as its slow.
  6331. * @param {object} settings dataTables settings object
  6332. * @param {string} callbackArr Name of the array storage for the callbacks in
  6333. * oSettings
  6334. * @param {string} eventName Name of the jQuery custom event to trigger. If
  6335. * null no trigger is fired
  6336. * @param {array} args Array of arguments to pass to the callback function /
  6337. * trigger
  6338. * @memberof DataTable#oApi
  6339. */
  6340. function _fnCallbackFire(settings, callbackArr, eventName, args) {
  6341. var ret = [];
  6342. if (callbackArr) {
  6343. ret = $.map(settings[callbackArr].slice().reverse(), function (val, i) {
  6344. return val.fn.apply(settings.oInstance, args);
  6345. });
  6346. }
  6347. if (eventName !== null) {
  6348. var e = $.Event(eventName + '.dt');
  6349. $(settings.nTable).trigger(e, args);
  6350. ret.push(e.result);
  6351. }
  6352. return ret;
  6353. }
  6354. function _fnLengthOverflow(settings) {
  6355. var start = settings._iDisplayStart,
  6356. end = settings.fnDisplayEnd(),
  6357. len = settings._iDisplayLength;
  6358. /* If we have space to show extra rows (backing up from the end point - then do so */
  6359. if (start >= end) {
  6360. start = end - len;
  6361. }
  6362. // Keep the start record on the current page
  6363. start -= start % len;
  6364. if (len === -1 || start < 0) {
  6365. start = 0;
  6366. }
  6367. settings._iDisplayStart = start;
  6368. }
  6369. function _fnRenderer(settings, type) {
  6370. var renderer = settings.renderer;
  6371. var host = DataTable.ext.renderer[type];
  6372. if ($.isPlainObject(renderer) && renderer[type]) {
  6373. // Specific renderer for this type. If available use it, otherwise use
  6374. // the default.
  6375. return host[renderer[type]] || host._;
  6376. } else if (typeof renderer === 'string') {
  6377. // Common renderer - if there is one available for this type use it,
  6378. // otherwise use the default
  6379. return host[renderer] || host._;
  6380. }
  6381. // Use the default
  6382. return host._;
  6383. }
  6384. /**
  6385. * Detect the data source being used for the table. Used to simplify the code
  6386. * a little (ajax) and to make it compress a little smaller.
  6387. *
  6388. * @param {object} settings dataTables settings object
  6389. * @returns {string} Data source
  6390. * @memberof DataTable#oApi
  6391. */
  6392. function _fnDataSource(settings) {
  6393. if (settings.oFeatures.bServerSide) {
  6394. return 'ssp';
  6395. } else if (settings.ajax || settings.sAjaxSource) {
  6396. return 'ajax';
  6397. }
  6398. return 'dom';
  6399. }
  6400. /**
  6401. * Computed structure of the DataTables API, defined by the options passed to
  6402. * `DataTable.Api.register()` when building the API.
  6403. *
  6404. * The structure is built in order to speed creation and extension of the Api
  6405. * objects since the extensions are effectively pre-parsed.
  6406. *
  6407. * The array is an array of objects with the following structure, where this
  6408. * base array represents the Api prototype base:
  6409. *
  6410. * [
  6411. * {
  6412. * name: 'data' -- string - Property name
  6413. * val: function () {}, -- function - Api method (or undefined if just an object
  6414. * methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  6415. * propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  6416. * },
  6417. * {
  6418. * name: 'row'
  6419. * val: {},
  6420. * methodExt: [ ... ],
  6421. * propExt: [
  6422. * {
  6423. * name: 'data'
  6424. * val: function () {},
  6425. * methodExt: [ ... ],
  6426. * propExt: [ ... ]
  6427. * },
  6428. * ...
  6429. * ]
  6430. * }
  6431. * ]
  6432. *
  6433. * @type {Array}
  6434. * @ignore
  6435. */
  6436. var __apiStruct = [];
  6437. /**
  6438. * `Array.prototype` reference.
  6439. *
  6440. * @type object
  6441. * @ignore
  6442. */
  6443. var __arrayProto = Array.prototype;
  6444. /**
  6445. * Abstraction for `context` parameter of the `Api` constructor to allow it to
  6446. * take several different forms for ease of use.
  6447. *
  6448. * Each of the input parameter types will be converted to a DataTables settings
  6449. * object where possible.
  6450. *
  6451. * @param {string|node|jQuery|object} mixed DataTable identifier. Can be one
  6452. * of:
  6453. *
  6454. * * `string` - jQuery selector. Any DataTables' matching the given selector
  6455. * with be found and used.
  6456. * * `node` - `TABLE` node which has already been formed into a DataTable.
  6457. * * `jQuery` - A jQuery object of `TABLE` nodes.
  6458. * * `object` - DataTables settings object
  6459. * * `DataTables.Api` - API instance
  6460. * @return {array|null} Matching DataTables settings objects. `null` or
  6461. * `undefined` is returned if no matching DataTable is found.
  6462. * @ignore
  6463. */
  6464. var _toSettings = function _toSettings(mixed) {
  6465. var idx, jq;
  6466. var settings = DataTable.settings;
  6467. var tables = $.map(settings, function (el, i) {
  6468. return el.nTable;
  6469. });
  6470. if (!mixed) {
  6471. return [];
  6472. } else if (mixed.nTable && mixed.oApi) {
  6473. // DataTables settings object
  6474. return [mixed];
  6475. } else if (mixed.nodeName && mixed.nodeName.toLowerCase() === 'table') {
  6476. // Table node
  6477. idx = $.inArray(mixed, tables);
  6478. return idx !== -1 ? [settings[idx]] : null;
  6479. } else if (mixed && typeof mixed.settings === 'function') {
  6480. return mixed.settings().toArray();
  6481. } else if (typeof mixed === 'string') {
  6482. // jQuery selector
  6483. jq = $(mixed);
  6484. } else if (mixed instanceof $) {
  6485. // jQuery object (also DataTables instance)
  6486. jq = mixed;
  6487. }
  6488. if (jq) {
  6489. return jq.map(function (i) {
  6490. idx = $.inArray(this, tables);
  6491. return idx !== -1 ? settings[idx] : null;
  6492. }).toArray();
  6493. }
  6494. };
  6495. /**
  6496. * DataTables API class - used to control and interface with one or more
  6497. * DataTables enhanced tables.
  6498. *
  6499. * The API class is heavily based on jQuery, presenting a chainable interface
  6500. * that you can use to interact with tables. Each instance of the API class has
  6501. * a "context" - i.e. the tables that it will operate on. This could be a single
  6502. * table, all tables on a page or a sub-set thereof.
  6503. *
  6504. * Additionally the API is designed to allow you to easily work with the data in
  6505. * the tables, retrieving and manipulating it as required. This is done by
  6506. * presenting the API class as an array like interface. The contents of the
  6507. * array depend upon the actions requested by each method (for example
  6508. * `rows().nodes()` will return an array of nodes, while `rows().data()` will
  6509. * return an array of objects or arrays depending upon your table's
  6510. * configuration). The API object has a number of array like methods (`push`,
  6511. * `pop`, `reverse` etc) as well as additional helper methods (`each`, `pluck`,
  6512. * `unique` etc) to assist your working with the data held in a table.
  6513. *
  6514. * Most methods (those which return an Api instance) are chainable, which means
  6515. * the return from a method call also has all of the methods available that the
  6516. * top level object had. For example, these two calls are equivalent:
  6517. *
  6518. * // Not chained
  6519. * api.row.add( {...} );
  6520. * api.draw();
  6521. *
  6522. * // Chained
  6523. * api.row.add( {...} ).draw();
  6524. *
  6525. * @class DataTable.Api
  6526. * @param {array|object|string|jQuery} context DataTable identifier. This is
  6527. * used to define which DataTables enhanced tables this API will operate on.
  6528. * Can be one of:
  6529. *
  6530. * * `string` - jQuery selector. Any DataTables' matching the given selector
  6531. * with be found and used.
  6532. * * `node` - `TABLE` node which has already been formed into a DataTable.
  6533. * * `jQuery` - A jQuery object of `TABLE` nodes.
  6534. * * `object` - DataTables settings object
  6535. * @param {array} [data] Data to initialise the Api instance with.
  6536. *
  6537. * @example
  6538. * // Direct initialisation during DataTables construction
  6539. * var api = $('#example').DataTable();
  6540. *
  6541. * @example
  6542. * // Initialisation using a DataTables jQuery object
  6543. * var api = $('#example').dataTable().api();
  6544. *
  6545. * @example
  6546. * // Initialisation as a constructor
  6547. * var api = new $.fn.DataTable.Api( 'table.dataTable' );
  6548. */
  6549. _Api2 = function _Api(context, data) {
  6550. if (!(this instanceof _Api2)) {
  6551. return new _Api2(context, data);
  6552. }
  6553. var settings = [];
  6554. var ctxSettings = function ctxSettings(o) {
  6555. var a = _toSettings(o);
  6556. if (a) {
  6557. settings = settings.concat(a);
  6558. }
  6559. };
  6560. if ($.isArray(context)) {
  6561. for (var i = 0, ien = context.length; i < ien; i++) {
  6562. ctxSettings(context[i]);
  6563. }
  6564. } else {
  6565. ctxSettings(context);
  6566. }
  6567. // Remove duplicates
  6568. this.context = _unique(settings);
  6569. // Initial data
  6570. if (data) {
  6571. $.merge(this, data);
  6572. }
  6573. // selector
  6574. this.selector = {
  6575. rows: null,
  6576. cols: null,
  6577. opts: null
  6578. };
  6579. _Api2.extend(this, this, __apiStruct);
  6580. };
  6581. DataTable.Api = _Api2;
  6582. // Don't destroy the existing prototype, just extend it. Required for jQuery 2's
  6583. // isPlainObject.
  6584. $.extend(_Api2.prototype, {
  6585. any: function any() {
  6586. return this.count() !== 0;
  6587. },
  6588. concat: __arrayProto.concat,
  6589. context: [], // array of table settings objects
  6590. count: function count() {
  6591. return this.flatten().length;
  6592. },
  6593. each: function each(fn) {
  6594. for (var i = 0, ien = this.length; i < ien; i++) {
  6595. fn.call(this, this[i], i, this);
  6596. }
  6597. return this;
  6598. },
  6599. eq: function eq(idx) {
  6600. var ctx = this.context;
  6601. return ctx.length > idx ? new _Api2(ctx[idx], this[idx]) : null;
  6602. },
  6603. filter: function filter(fn) {
  6604. var a = [];
  6605. if (__arrayProto.filter) {
  6606. a = __arrayProto.filter.call(this, fn, this);
  6607. } else {
  6608. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6609. for (var i = 0, ien = this.length; i < ien; i++) {
  6610. if (fn.call(this, this[i], i, this)) {
  6611. a.push(this[i]);
  6612. }
  6613. }
  6614. }
  6615. return new _Api2(this.context, a);
  6616. },
  6617. flatten: function flatten() {
  6618. var a = [];
  6619. return new _Api2(this.context, a.concat.apply(a, this.toArray()));
  6620. },
  6621. join: __arrayProto.join,
  6622. indexOf: __arrayProto.indexOf || function (obj, start) {
  6623. for (var i = start || 0, ien = this.length; i < ien; i++) {
  6624. if (this[i] === obj) {
  6625. return i;
  6626. }
  6627. }
  6628. return -1;
  6629. },
  6630. iterator: function iterator(flatten, type, fn, alwaysNew) {
  6631. var a = [],
  6632. ret,
  6633. i,
  6634. ien,
  6635. j,
  6636. jen,
  6637. context = this.context,
  6638. rows,
  6639. items,
  6640. item,
  6641. selector = this.selector;
  6642. // Argument shifting
  6643. if (typeof flatten === 'string') {
  6644. alwaysNew = fn;
  6645. fn = type;
  6646. type = flatten;
  6647. flatten = false;
  6648. }
  6649. for (i = 0, ien = context.length; i < ien; i++) {
  6650. var apiInst = new _Api2(context[i]);
  6651. if (type === 'table') {
  6652. ret = fn.call(apiInst, context[i], i);
  6653. if (ret !== undefined) {
  6654. a.push(ret);
  6655. }
  6656. } else if (type === 'columns' || type === 'rows') {
  6657. // this has same length as context - one entry for each table
  6658. ret = fn.call(apiInst, context[i], this[i], i);
  6659. if (ret !== undefined) {
  6660. a.push(ret);
  6661. }
  6662. } else if (type === 'column' || type === 'column-rows' || type === 'row' || type === 'cell') {
  6663. // columns and rows share the same structure.
  6664. // 'this' is an array of column indexes for each context
  6665. items = this[i];
  6666. if (type === 'column-rows') {
  6667. rows = _selector_row_indexes(context[i], selector.opts);
  6668. }
  6669. for (j = 0, jen = items.length; j < jen; j++) {
  6670. item = items[j];
  6671. if (type === 'cell') {
  6672. ret = fn.call(apiInst, context[i], item.row, item.column, i, j);
  6673. } else {
  6674. ret = fn.call(apiInst, context[i], item, i, j, rows);
  6675. }
  6676. if (ret !== undefined) {
  6677. a.push(ret);
  6678. }
  6679. }
  6680. }
  6681. }
  6682. if (a.length || alwaysNew) {
  6683. var api = new _Api2(context, flatten ? a.concat.apply([], a) : a);
  6684. var apiSelector = api.selector;
  6685. apiSelector.rows = selector.rows;
  6686. apiSelector.cols = selector.cols;
  6687. apiSelector.opts = selector.opts;
  6688. return api;
  6689. }
  6690. return this;
  6691. },
  6692. lastIndexOf: __arrayProto.lastIndexOf || function (obj, start) {
  6693. // Bit cheeky...
  6694. return this.indexOf.apply(this.toArray.reverse(), arguments);
  6695. },
  6696. length: 0,
  6697. map: function map(fn) {
  6698. var a = [];
  6699. if (__arrayProto.map) {
  6700. a = __arrayProto.map.call(this, fn, this);
  6701. } else {
  6702. // Compatibility for browsers without EMCA-252-5 (JS 1.6)
  6703. for (var i = 0, ien = this.length; i < ien; i++) {
  6704. a.push(fn.call(this, this[i], i));
  6705. }
  6706. }
  6707. return new _Api2(this.context, a);
  6708. },
  6709. pluck: function pluck(prop) {
  6710. return this.map(function (el) {
  6711. return el[prop];
  6712. });
  6713. },
  6714. pop: __arrayProto.pop,
  6715. push: __arrayProto.push,
  6716. // Does not return an API instance
  6717. reduce: __arrayProto.reduce || function (fn, init) {
  6718. return _fnReduce(this, fn, init, 0, this.length, 1);
  6719. },
  6720. reduceRight: __arrayProto.reduceRight || function (fn, init) {
  6721. return _fnReduce(this, fn, init, this.length - 1, -1, -1);
  6722. },
  6723. reverse: __arrayProto.reverse,
  6724. // Object with rows, columns and opts
  6725. selector: null,
  6726. shift: __arrayProto.shift,
  6727. slice: function slice() {
  6728. return new _Api2(this.context, this);
  6729. },
  6730. sort: __arrayProto.sort, // ? name - order?
  6731. splice: __arrayProto.splice,
  6732. toArray: function toArray() {
  6733. return __arrayProto.slice.call(this);
  6734. },
  6735. to$: function to$() {
  6736. return $(this);
  6737. },
  6738. toJQuery: function toJQuery() {
  6739. return $(this);
  6740. },
  6741. unique: function unique() {
  6742. return new _Api2(this.context, _unique(this));
  6743. },
  6744. unshift: __arrayProto.unshift
  6745. });
  6746. _Api2.extend = function (scope, obj, ext) {
  6747. // Only extend API instances and static properties of the API
  6748. if (!ext.length || !obj || !(obj instanceof _Api2) && !obj.__dt_wrapper) {
  6749. return;
  6750. }
  6751. var i,
  6752. ien,
  6753. j,
  6754. jen,
  6755. struct,
  6756. inner,
  6757. methodScoping = function methodScoping(scope, fn, struc) {
  6758. return function () {
  6759. var ret = fn.apply(scope, arguments);
  6760. // Method extension
  6761. _Api2.extend(ret, ret, struc.methodExt);
  6762. return ret;
  6763. };
  6764. };
  6765. for (i = 0, ien = ext.length; i < ien; i++) {
  6766. struct = ext[i];
  6767. // Value
  6768. obj[struct.name] = typeof struct.val === 'function' ? methodScoping(scope, struct.val, struct) : $.isPlainObject(struct.val) ? {} : struct.val;
  6769. obj[struct.name].__dt_wrapper = true;
  6770. // Property extension
  6771. _Api2.extend(scope, obj[struct.name], struct.propExt);
  6772. }
  6773. };
  6774. // @todo - Is there need for an augment function?
  6775. // _Api.augment = function ( inst, name )
  6776. // {
  6777. // // Find src object in the structure from the name
  6778. // var parts = name.split('.');
  6779. // _Api.extend( inst, obj );
  6780. // };
  6781. // [
  6782. // {
  6783. // name: 'data' -- string - Property name
  6784. // val: function () {}, -- function - Api method (or undefined if just an object
  6785. // methodExt: [ ... ], -- array - Array of Api object definitions to extend the method result
  6786. // propExt: [ ... ] -- array - Array of Api object definitions to extend the property
  6787. // },
  6788. // {
  6789. // name: 'row'
  6790. // val: {},
  6791. // methodExt: [ ... ],
  6792. // propExt: [
  6793. // {
  6794. // name: 'data'
  6795. // val: function () {},
  6796. // methodExt: [ ... ],
  6797. // propExt: [ ... ]
  6798. // },
  6799. // ...
  6800. // ]
  6801. // }
  6802. // ]
  6803. _Api2.register = _api_register = function _api_register(name, val) {
  6804. if ($.isArray(name)) {
  6805. for (var j = 0, jen = name.length; j < jen; j++) {
  6806. _Api2.register(name[j], val);
  6807. }
  6808. return;
  6809. }
  6810. var i,
  6811. ien,
  6812. heir = name.split('.'),
  6813. struct = __apiStruct,
  6814. key,
  6815. method;
  6816. var find = function find(src, name) {
  6817. for (var i = 0, ien = src.length; i < ien; i++) {
  6818. if (src[i].name === name) {
  6819. return src[i];
  6820. }
  6821. }
  6822. return null;
  6823. };
  6824. for (i = 0, ien = heir.length; i < ien; i++) {
  6825. method = heir[i].indexOf('()') !== -1;
  6826. key = method ? heir[i].replace('()', '') : heir[i];
  6827. var src = find(struct, key);
  6828. if (!src) {
  6829. src = {
  6830. name: key,
  6831. val: {},
  6832. methodExt: [],
  6833. propExt: []
  6834. };
  6835. struct.push(src);
  6836. }
  6837. if (i === ien - 1) {
  6838. src.val = val;
  6839. } else {
  6840. struct = method ? src.methodExt : src.propExt;
  6841. }
  6842. }
  6843. };
  6844. _Api2.registerPlural = _api_registerPlural = function _api_registerPlural(pluralName, singularName, val) {
  6845. _Api2.register(pluralName, val);
  6846. _Api2.register(singularName, function () {
  6847. var ret = val.apply(this, arguments);
  6848. if (ret === this) {
  6849. // Returned item is the API instance that was passed in, return it
  6850. return this;
  6851. } else if (ret instanceof _Api2) {
  6852. // New API instance returned, want the value from the first item
  6853. // in the returned array for the singular result.
  6854. return ret.length ? $.isArray(ret[0]) ? new _Api2(ret.context, ret[0]) : // Array results are 'enhanced'
  6855. ret[0] : undefined;
  6856. }
  6857. // Non-API return - just fire it back
  6858. return ret;
  6859. });
  6860. };
  6861. /**
  6862. * Selector for HTML tables. Apply the given selector to the give array of
  6863. * DataTables settings objects.
  6864. *
  6865. * @param {string|integer} [selector] jQuery selector string or integer
  6866. * @param {array} Array of DataTables settings objects to be filtered
  6867. * @return {array}
  6868. * @ignore
  6869. */
  6870. var __table_selector = function __table_selector(selector, a) {
  6871. // Integer is used to pick out a table by index
  6872. if (typeof selector === 'number') {
  6873. return [a[selector]];
  6874. }
  6875. // Perform a jQuery selector on the table nodes
  6876. var nodes = $.map(a, function (el, i) {
  6877. return el.nTable;
  6878. });
  6879. return $(nodes).filter(selector).map(function (i) {
  6880. // Need to translate back from the table node to the settings
  6881. var idx = $.inArray(this, nodes);
  6882. return a[idx];
  6883. }).toArray();
  6884. };
  6885. /**
  6886. * Context selector for the API's context (i.e. the tables the API instance
  6887. * refers to.
  6888. *
  6889. * @name DataTable.Api#tables
  6890. * @param {string|integer} [selector] Selector to pick which tables the iterator
  6891. * should operate on. If not given, all tables in the current context are
  6892. * used. This can be given as a jQuery selector (for example `':gt(0)'`) to
  6893. * select multiple tables or as an integer to select a single table.
  6894. * @returns {DataTable.Api} Returns a new API instance if a selector is given.
  6895. */
  6896. _api_register('tables()', function (selector) {
  6897. // A new instance is created if there was a selector specified
  6898. return selector ? new _Api2(__table_selector(selector, this.context)) : this;
  6899. });
  6900. _api_register('table()', function (selector) {
  6901. var tables = this.tables(selector);
  6902. var ctx = tables.context;
  6903. // Truncate to the first matched table
  6904. return ctx.length ? new _Api2(ctx[0]) : tables;
  6905. });
  6906. _api_registerPlural('tables().nodes()', 'table().node()', function () {
  6907. return this.iterator('table', function (ctx) {
  6908. return ctx.nTable;
  6909. }, 1);
  6910. });
  6911. _api_registerPlural('tables().body()', 'table().body()', function () {
  6912. return this.iterator('table', function (ctx) {
  6913. return ctx.nTBody;
  6914. }, 1);
  6915. });
  6916. _api_registerPlural('tables().header()', 'table().header()', function () {
  6917. return this.iterator('table', function (ctx) {
  6918. return ctx.nTHead;
  6919. }, 1);
  6920. });
  6921. _api_registerPlural('tables().footer()', 'table().footer()', function () {
  6922. return this.iterator('table', function (ctx) {
  6923. return ctx.nTFoot;
  6924. }, 1);
  6925. });
  6926. _api_registerPlural('tables().containers()', 'table().container()', function () {
  6927. return this.iterator('table', function (ctx) {
  6928. return ctx.nTableWrapper;
  6929. }, 1);
  6930. });
  6931. /**
  6932. * Redraw the tables in the current context.
  6933. */
  6934. _api_register('draw()', function (paging) {
  6935. return this.iterator('table', function (settings) {
  6936. if (paging === 'page') {
  6937. _fnDraw(settings);
  6938. } else {
  6939. if (typeof paging === 'string') {
  6940. paging = paging === 'full-hold' ? false : true;
  6941. }
  6942. _fnReDraw(settings, paging === false);
  6943. }
  6944. });
  6945. });
  6946. /**
  6947. * Get the current page index.
  6948. *
  6949. * @return {integer} Current page index (zero based)
  6950. */ /**
  6951. * Set the current page.
  6952. *
  6953. * Note that if you attempt to show a page which does not exist, DataTables will
  6954. * not throw an error, but rather reset the paging.
  6955. *
  6956. * @param {integer|string} action The paging action to take. This can be one of:
  6957. * * `integer` - The page index to jump to
  6958. * * `string` - An action to take:
  6959. * * `first` - Jump to first page.
  6960. * * `next` - Jump to the next page
  6961. * * `previous` - Jump to previous page
  6962. * * `last` - Jump to the last page.
  6963. * @returns {DataTables.Api} this
  6964. */
  6965. _api_register('page()', function (action) {
  6966. if (action === undefined) {
  6967. return this.page.info().page; // not an expensive call
  6968. }
  6969. // else, have an action to take on all tables
  6970. return this.iterator('table', function (settings) {
  6971. _fnPageChange(settings, action);
  6972. });
  6973. });
  6974. /**
  6975. * Paging information for the first table in the current context.
  6976. *
  6977. * If you require paging information for another table, use the `table()` method
  6978. * with a suitable selector.
  6979. *
  6980. * @return {object} Object with the following properties set:
  6981. * * `page` - Current page index (zero based - i.e. the first page is `0`)
  6982. * * `pages` - Total number of pages
  6983. * * `start` - Display index for the first record shown on the current page
  6984. * * `end` - Display index for the last record shown on the current page
  6985. * * `length` - Display length (number of records). Note that generally `start
  6986. * + length = end`, but this is not always true, for example if there are
  6987. * only 2 records to show on the final page, with a length of 10.
  6988. * * `recordsTotal` - Full data set length
  6989. * * `recordsDisplay` - Data set length once the current filtering criterion
  6990. * are applied.
  6991. */
  6992. _api_register('page.info()', function (action) {
  6993. if (this.context.length === 0) {
  6994. return undefined;
  6995. }
  6996. var settings = this.context[0],
  6997. start = settings._iDisplayStart,
  6998. len = settings.oFeatures.bPaginate ? settings._iDisplayLength : -1,
  6999. visRecords = settings.fnRecordsDisplay(),
  7000. all = len === -1;
  7001. return {
  7002. "page": all ? 0 : Math.floor(start / len),
  7003. "pages": all ? 1 : Math.ceil(visRecords / len),
  7004. "start": start,
  7005. "end": settings.fnDisplayEnd(),
  7006. "length": len,
  7007. "recordsTotal": settings.fnRecordsTotal(),
  7008. "recordsDisplay": visRecords,
  7009. "serverSide": _fnDataSource(settings) === 'ssp'
  7010. };
  7011. });
  7012. /**
  7013. * Get the current page length.
  7014. *
  7015. * @return {integer} Current page length. Note `-1` indicates that all records
  7016. * are to be shown.
  7017. */ /**
  7018. * Set the current page length.
  7019. *
  7020. * @param {integer} Page length to set. Use `-1` to show all records.
  7021. * @returns {DataTables.Api} this
  7022. */
  7023. _api_register('page.len()', function (len) {
  7024. // Note that we can't call this function 'length()' because `length`
  7025. // is a Javascript property of functions which defines how many arguments
  7026. // the function expects.
  7027. if (len === undefined) {
  7028. return this.context.length !== 0 ? this.context[0]._iDisplayLength : undefined;
  7029. }
  7030. // else, set the page length
  7031. return this.iterator('table', function (settings) {
  7032. _fnLengthChange(settings, len);
  7033. });
  7034. });
  7035. var __reload = function __reload(settings, holdPosition, callback) {
  7036. // Use the draw event to trigger a callback
  7037. if (callback) {
  7038. var api = new _Api2(settings);
  7039. api.one('draw', function () {
  7040. callback(api.ajax.json());
  7041. });
  7042. }
  7043. if (_fnDataSource(settings) == 'ssp') {
  7044. _fnReDraw(settings, holdPosition);
  7045. } else {
  7046. _fnProcessingDisplay(settings, true);
  7047. // Cancel an existing request
  7048. var xhr = settings.jqXHR;
  7049. if (xhr && xhr.readyState !== 4) {
  7050. xhr.abort();
  7051. }
  7052. // Trigger xhr
  7053. _fnBuildAjax(settings, [], function (json) {
  7054. _fnClearTable(settings);
  7055. var data = _fnAjaxDataSrc(settings, json);
  7056. for (var i = 0, ien = data.length; i < ien; i++) {
  7057. _fnAddData(settings, data[i]);
  7058. }
  7059. _fnReDraw(settings, holdPosition);
  7060. _fnProcessingDisplay(settings, false);
  7061. });
  7062. }
  7063. };
  7064. /**
  7065. * Get the JSON response from the last Ajax request that DataTables made to the
  7066. * server. Note that this returns the JSON from the first table in the current
  7067. * context.
  7068. *
  7069. * @return {object} JSON received from the server.
  7070. */
  7071. _api_register('ajax.json()', function () {
  7072. var ctx = this.context;
  7073. if (ctx.length > 0) {
  7074. return ctx[0].json;
  7075. }
  7076. // else return undefined;
  7077. });
  7078. /**
  7079. * Get the data submitted in the last Ajax request
  7080. */
  7081. _api_register('ajax.params()', function () {
  7082. var ctx = this.context;
  7083. if (ctx.length > 0) {
  7084. return ctx[0].oAjaxData;
  7085. }
  7086. // else return undefined;
  7087. });
  7088. /**
  7089. * Reload tables from the Ajax data source. Note that this function will
  7090. * automatically re-draw the table when the remote data has been loaded.
  7091. *
  7092. * @param {boolean} [reset=true] Reset (default) or hold the current paging
  7093. * position. A full re-sort and re-filter is performed when this method is
  7094. * called, which is why the pagination reset is the default action.
  7095. * @returns {DataTables.Api} this
  7096. */
  7097. _api_register('ajax.reload()', function (callback, resetPaging) {
  7098. return this.iterator('table', function (settings) {
  7099. __reload(settings, resetPaging === false, callback);
  7100. });
  7101. });
  7102. /**
  7103. * Get the current Ajax URL. Note that this returns the URL from the first
  7104. * table in the current context.
  7105. *
  7106. * @return {string} Current Ajax source URL
  7107. */ /**
  7108. * Set the Ajax URL. Note that this will set the URL for all tables in the
  7109. * current context.
  7110. *
  7111. * @param {string} url URL to set.
  7112. * @returns {DataTables.Api} this
  7113. */
  7114. _api_register('ajax.url()', function (url) {
  7115. var ctx = this.context;
  7116. if (url === undefined) {
  7117. // get
  7118. if (ctx.length === 0) {
  7119. return undefined;
  7120. }
  7121. ctx = ctx[0];
  7122. return ctx.ajax ? $.isPlainObject(ctx.ajax) ? ctx.ajax.url : ctx.ajax : ctx.sAjaxSource;
  7123. }
  7124. // set
  7125. return this.iterator('table', function (settings) {
  7126. if ($.isPlainObject(settings.ajax)) {
  7127. settings.ajax.url = url;
  7128. } else {
  7129. settings.ajax = url;
  7130. }
  7131. // No need to consider sAjaxSource here since DataTables gives priority
  7132. // to `ajax` over `sAjaxSource`. So setting `ajax` here, renders any
  7133. // value of `sAjaxSource` redundant.
  7134. });
  7135. });
  7136. /**
  7137. * Load data from the newly set Ajax URL. Note that this method is only
  7138. * available when `ajax.url()` is used to set a URL. Additionally, this method
  7139. * has the same effect as calling `ajax.reload()` but is provided for
  7140. * convenience when setting a new URL. Like `ajax.reload()` it will
  7141. * automatically redraw the table once the remote data has been loaded.
  7142. *
  7143. * @returns {DataTables.Api} this
  7144. */
  7145. _api_register('ajax.url().load()', function (callback, resetPaging) {
  7146. // Same as a reload, but makes sense to present it for easy access after a
  7147. // url change
  7148. return this.iterator('table', function (ctx) {
  7149. __reload(ctx, resetPaging === false, callback);
  7150. });
  7151. });
  7152. var _selector_run = function _selector_run(type, selector, selectFn, settings, opts) {
  7153. var out = [],
  7154. res,
  7155. a,
  7156. i,
  7157. ien,
  7158. j,
  7159. jen,
  7160. selectorType = typeof selector === 'undefined' ? 'undefined' : _typeof(selector);
  7161. // Can't just check for isArray here, as an API or jQuery instance might be
  7162. // given with their array like look
  7163. if (!selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined) {
  7164. selector = [selector];
  7165. }
  7166. for (i = 0, ien = selector.length; i < ien; i++) {
  7167. // Only split on simple strings - complex expressions will be jQuery selectors
  7168. a = selector[i] && selector[i].split && !selector[i].match(/[\[\(:]/) ? selector[i].split(',') : [selector[i]];
  7169. for (j = 0, jen = a.length; j < jen; j++) {
  7170. res = selectFn(typeof a[j] === 'string' ? $.trim(a[j]) : a[j]);
  7171. if (res && res.length) {
  7172. out = out.concat(res);
  7173. }
  7174. }
  7175. }
  7176. // selector extensions
  7177. var ext = _ext.selector[type];
  7178. if (ext.length) {
  7179. for (i = 0, ien = ext.length; i < ien; i++) {
  7180. out = ext[i](settings, opts, out);
  7181. }
  7182. }
  7183. return _unique(out);
  7184. };
  7185. var _selector_opts = function _selector_opts(opts) {
  7186. if (!opts) {
  7187. opts = {};
  7188. }
  7189. // Backwards compatibility for 1.9- which used the terminology filter rather
  7190. // than search
  7191. if (opts.filter && opts.search === undefined) {
  7192. opts.search = opts.filter;
  7193. }
  7194. return $.extend({
  7195. search: 'none',
  7196. order: 'current',
  7197. page: 'all'
  7198. }, opts);
  7199. };
  7200. var _selector_first = function _selector_first(inst) {
  7201. // Reduce the API instance to the first item found
  7202. for (var i = 0, ien = inst.length; i < ien; i++) {
  7203. if (inst[i].length > 0) {
  7204. // Assign the first element to the first item in the instance
  7205. // and truncate the instance and context
  7206. inst[0] = inst[i];
  7207. inst[0].length = 1;
  7208. inst.length = 1;
  7209. inst.context = [inst.context[i]];
  7210. return inst;
  7211. }
  7212. }
  7213. // Not found - return an empty instance
  7214. inst.length = 0;
  7215. return inst;
  7216. };
  7217. var _selector_row_indexes = function _selector_row_indexes(settings, opts) {
  7218. var i,
  7219. ien,
  7220. tmp,
  7221. a = [],
  7222. displayFiltered = settings.aiDisplay,
  7223. displayMaster = settings.aiDisplayMaster;
  7224. var search = opts.search,
  7225. // none, applied, removed
  7226. order = opts.order,
  7227. // applied, current, index (original - compatibility with 1.9)
  7228. page = opts.page; // all, current
  7229. if (_fnDataSource(settings) == 'ssp') {
  7230. // In server-side processing mode, most options are irrelevant since
  7231. // rows not shown don't exist and the index order is the applied order
  7232. // Removed is a special case - for consistency just return an empty
  7233. // array
  7234. return search === 'removed' ? [] : _range(0, displayMaster.length);
  7235. } else if (page == 'current') {
  7236. // Current page implies that order=current and fitler=applied, since it is
  7237. // fairly senseless otherwise, regardless of what order and search actually
  7238. // are
  7239. for (i = settings._iDisplayStart, ien = settings.fnDisplayEnd(); i < ien; i++) {
  7240. a.push(displayFiltered[i]);
  7241. }
  7242. } else if (order == 'current' || order == 'applied') {
  7243. a = search == 'none' ? displayMaster.slice() : // no search
  7244. search == 'applied' ? displayFiltered.slice() : // applied search
  7245. $.map(displayMaster, function (el, i) {
  7246. // removed search
  7247. return $.inArray(el, displayFiltered) === -1 ? el : null;
  7248. });
  7249. } else if (order == 'index' || order == 'original') {
  7250. for (i = 0, ien = settings.aoData.length; i < ien; i++) {
  7251. if (search == 'none') {
  7252. a.push(i);
  7253. } else {
  7254. // applied | removed
  7255. tmp = $.inArray(i, displayFiltered);
  7256. if (tmp === -1 && search == 'removed' || tmp >= 0 && search == 'applied') {
  7257. a.push(i);
  7258. }
  7259. }
  7260. }
  7261. }
  7262. return a;
  7263. };
  7264. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7265. * Rows
  7266. *
  7267. * {} - no selector - use all available rows
  7268. * {integer} - row aoData index
  7269. * {node} - TR node
  7270. * {string} - jQuery selector to apply to the TR elements
  7271. * {array} - jQuery array of nodes, or simply an array of TR nodes
  7272. *
  7273. */
  7274. var __row_selector = function __row_selector(settings, selector, opts) {
  7275. var rows;
  7276. var run = function run(sel) {
  7277. var selInt = _intVal(sel);
  7278. var i, ien;
  7279. // Short cut - selector is a number and no options provided (default is
  7280. // all records, so no need to check if the index is in there, since it
  7281. // must be - dev error if the index doesn't exist).
  7282. if (selInt !== null && !opts) {
  7283. return [selInt];
  7284. }
  7285. if (!rows) {
  7286. rows = _selector_row_indexes(settings, opts);
  7287. }
  7288. if (selInt !== null && $.inArray(selInt, rows) !== -1) {
  7289. // Selector - integer
  7290. return [selInt];
  7291. } else if (sel === null || sel === undefined || sel === '') {
  7292. // Selector - none
  7293. return rows;
  7294. }
  7295. // Selector - function
  7296. if (typeof sel === 'function') {
  7297. return $.map(rows, function (idx) {
  7298. var row = settings.aoData[idx];
  7299. return sel(idx, row._aData, row.nTr) ? idx : null;
  7300. });
  7301. }
  7302. // Get nodes in the order from the `rows` array with null values removed
  7303. var nodes = _removeEmpty(_pluck_order(settings.aoData, rows, 'nTr'));
  7304. // Selector - node
  7305. if (sel.nodeName) {
  7306. if (sel._DT_RowIndex !== undefined) {
  7307. return [sel._DT_RowIndex]; // Property added by DT for fast lookup
  7308. } else if (sel._DT_CellIndex) {
  7309. return [sel._DT_CellIndex.row];
  7310. } else {
  7311. var host = $(sel).closest('*[data-dt-row]');
  7312. return host.length ? [host.data('dt-row')] : [];
  7313. }
  7314. }
  7315. // ID selector. Want to always be able to select rows by id, regardless
  7316. // of if the tr element has been created or not, so can't rely upon
  7317. // jQuery here - hence a custom implementation. This does not match
  7318. // Sizzle's fast selector or HTML4 - in HTML5 the ID can be anything,
  7319. // but to select it using a CSS selector engine (like Sizzle or
  7320. // querySelect) it would need to need to be escaped for some characters.
  7321. // DataTables simplifies this for row selectors since you can select
  7322. // only a row. A # indicates an id any anything that follows is the id -
  7323. // unescaped.
  7324. if (typeof sel === 'string' && sel.charAt(0) === '#') {
  7325. // get row index from id
  7326. var rowObj = settings.aIds[sel.replace(/^#/, '')];
  7327. if (rowObj !== undefined) {
  7328. return [rowObj.idx];
  7329. }
  7330. // need to fall through to jQuery in case there is DOM id that
  7331. // matches
  7332. }
  7333. // Selector - jQuery selector string, array of nodes or jQuery object/
  7334. // As jQuery's .filter() allows jQuery objects to be passed in filter,
  7335. // it also allows arrays, so this will cope with all three options
  7336. return $(nodes).filter(sel).map(function () {
  7337. return this._DT_RowIndex;
  7338. }).toArray();
  7339. };
  7340. return _selector_run('row', selector, run, settings, opts);
  7341. };
  7342. _api_register('rows()', function (selector, opts) {
  7343. // argument shifting
  7344. if (selector === undefined) {
  7345. selector = '';
  7346. } else if ($.isPlainObject(selector)) {
  7347. opts = selector;
  7348. selector = '';
  7349. }
  7350. opts = _selector_opts(opts);
  7351. var inst = this.iterator('table', function (settings) {
  7352. return __row_selector(settings, selector, opts);
  7353. }, 1);
  7354. // Want argument shifting here and in __row_selector?
  7355. inst.selector.rows = selector;
  7356. inst.selector.opts = opts;
  7357. return inst;
  7358. });
  7359. _api_register('rows().nodes()', function () {
  7360. return this.iterator('row', function (settings, row) {
  7361. return settings.aoData[row].nTr || undefined;
  7362. }, 1);
  7363. });
  7364. _api_register('rows().data()', function () {
  7365. return this.iterator(true, 'rows', function (settings, rows) {
  7366. return _pluck_order(settings.aoData, rows, '_aData');
  7367. }, 1);
  7368. });
  7369. _api_registerPlural('rows().cache()', 'row().cache()', function (type) {
  7370. return this.iterator('row', function (settings, row) {
  7371. var r = settings.aoData[row];
  7372. return type === 'search' ? r._aFilterData : r._aSortData;
  7373. }, 1);
  7374. });
  7375. _api_registerPlural('rows().invalidate()', 'row().invalidate()', function (src) {
  7376. return this.iterator('row', function (settings, row) {
  7377. _fnInvalidate(settings, row, src);
  7378. });
  7379. });
  7380. _api_registerPlural('rows().indexes()', 'row().index()', function () {
  7381. return this.iterator('row', function (settings, row) {
  7382. return row;
  7383. }, 1);
  7384. });
  7385. _api_registerPlural('rows().ids()', 'row().id()', function (hash) {
  7386. var a = [];
  7387. var context = this.context;
  7388. // `iterator` will drop undefined values, but in this case we want them
  7389. for (var i = 0, ien = context.length; i < ien; i++) {
  7390. for (var j = 0, jen = this[i].length; j < jen; j++) {
  7391. var id = context[i].rowIdFn(context[i].aoData[this[i][j]]._aData);
  7392. a.push((hash === true ? '#' : '') + id);
  7393. }
  7394. }
  7395. return new _Api2(context, a);
  7396. });
  7397. _api_registerPlural('rows().remove()', 'row().remove()', function () {
  7398. var that = this;
  7399. this.iterator('row', function (settings, row, thatIdx) {
  7400. var data = settings.aoData;
  7401. var rowData = data[row];
  7402. var i, ien, j, jen;
  7403. var loopRow, loopCells;
  7404. data.splice(row, 1);
  7405. // Update the cached indexes
  7406. for (i = 0, ien = data.length; i < ien; i++) {
  7407. loopRow = data[i];
  7408. loopCells = loopRow.anCells;
  7409. // Rows
  7410. if (loopRow.nTr !== null) {
  7411. loopRow.nTr._DT_RowIndex = i;
  7412. }
  7413. // Cells
  7414. if (loopCells !== null) {
  7415. for (j = 0, jen = loopCells.length; j < jen; j++) {
  7416. loopCells[j]._DT_CellIndex.row = i;
  7417. }
  7418. }
  7419. }
  7420. // Delete from the display arrays
  7421. _fnDeleteIndex(settings.aiDisplayMaster, row);
  7422. _fnDeleteIndex(settings.aiDisplay, row);
  7423. _fnDeleteIndex(that[thatIdx], row, false); // maintain local indexes
  7424. // For server-side processing tables - subtract the deleted row from the count
  7425. if (settings._iRecordsDisplay > 0) {
  7426. settings._iRecordsDisplay--;
  7427. }
  7428. // Check for an 'overflow' they case for displaying the table
  7429. _fnLengthOverflow(settings);
  7430. // Remove the row's ID reference if there is one
  7431. var id = settings.rowIdFn(rowData._aData);
  7432. if (id !== undefined) {
  7433. delete settings.aIds[id];
  7434. }
  7435. });
  7436. this.iterator('table', function (settings) {
  7437. for (var i = 0, ien = settings.aoData.length; i < ien; i++) {
  7438. settings.aoData[i].idx = i;
  7439. }
  7440. });
  7441. return this;
  7442. });
  7443. _api_register('rows.add()', function (rows) {
  7444. var newRows = this.iterator('table', function (settings) {
  7445. var row, i, ien;
  7446. var out = [];
  7447. for (i = 0, ien = rows.length; i < ien; i++) {
  7448. row = rows[i];
  7449. if (row.nodeName && row.nodeName.toUpperCase() === 'TR') {
  7450. out.push(_fnAddTr(settings, row)[0]);
  7451. } else {
  7452. out.push(_fnAddData(settings, row));
  7453. }
  7454. }
  7455. return out;
  7456. }, 1);
  7457. // Return an Api.rows() extended instance, so rows().nodes() etc can be used
  7458. var modRows = this.rows(-1);
  7459. modRows.pop();
  7460. $.merge(modRows, newRows);
  7461. return modRows;
  7462. });
  7463. /**
  7464. *
  7465. */
  7466. _api_register('row()', function (selector, opts) {
  7467. return _selector_first(this.rows(selector, opts));
  7468. });
  7469. _api_register('row().data()', function (data) {
  7470. var ctx = this.context;
  7471. if (data === undefined) {
  7472. // Get
  7473. return ctx.length && this.length ? ctx[0].aoData[this[0]]._aData : undefined;
  7474. }
  7475. // Set
  7476. ctx[0].aoData[this[0]]._aData = data;
  7477. // Automatically invalidate
  7478. _fnInvalidate(ctx[0], this[0], 'data');
  7479. return this;
  7480. });
  7481. _api_register('row().node()', function () {
  7482. var ctx = this.context;
  7483. return ctx.length && this.length ? ctx[0].aoData[this[0]].nTr || null : null;
  7484. });
  7485. _api_register('row.add()', function (row) {
  7486. // Allow a jQuery object to be passed in - only a single row is added from
  7487. // it though - the first element in the set
  7488. if (row instanceof $ && row.length) {
  7489. row = row[0];
  7490. }
  7491. var rows = this.iterator('table', function (settings) {
  7492. if (row.nodeName && row.nodeName.toUpperCase() === 'TR') {
  7493. return _fnAddTr(settings, row)[0];
  7494. }
  7495. return _fnAddData(settings, row);
  7496. });
  7497. // Return an Api.rows() extended instance, with the newly added row selected
  7498. return this.row(rows[0]);
  7499. });
  7500. var __details_add = function __details_add(ctx, row, data, klass) {
  7501. // Convert to array of TR elements
  7502. var rows = [];
  7503. var addRow = function addRow(r, k) {
  7504. // Recursion to allow for arrays of jQuery objects
  7505. if ($.isArray(r) || r instanceof $) {
  7506. for (var i = 0, ien = r.length; i < ien; i++) {
  7507. addRow(r[i], k);
  7508. }
  7509. return;
  7510. }
  7511. // If we get a TR element, then just add it directly - up to the dev
  7512. // to add the correct number of columns etc
  7513. if (r.nodeName && r.nodeName.toLowerCase() === 'tr') {
  7514. rows.push(r);
  7515. } else {
  7516. // Otherwise create a row with a wrapper
  7517. var created = $('<tr><td/></tr>').addClass(k);
  7518. $('td', created).addClass(k).html(r)[0].colSpan = _fnVisbleColumns(ctx);
  7519. rows.push(created[0]);
  7520. }
  7521. };
  7522. addRow(data, klass);
  7523. if (row._details) {
  7524. row._details.detach();
  7525. }
  7526. row._details = $(rows);
  7527. // If the children were already shown, that state should be retained
  7528. if (row._detailsShow) {
  7529. row._details.insertAfter(row.nTr);
  7530. }
  7531. };
  7532. var __details_remove = function __details_remove(api, idx) {
  7533. var ctx = api.context;
  7534. if (ctx.length) {
  7535. var row = ctx[0].aoData[idx !== undefined ? idx : api[0]];
  7536. if (row && row._details) {
  7537. row._details.remove();
  7538. row._detailsShow = undefined;
  7539. row._details = undefined;
  7540. }
  7541. }
  7542. };
  7543. var __details_display = function __details_display(api, show) {
  7544. var ctx = api.context;
  7545. if (ctx.length && api.length) {
  7546. var row = ctx[0].aoData[api[0]];
  7547. if (row._details) {
  7548. row._detailsShow = show;
  7549. if (show) {
  7550. row._details.insertAfter(row.nTr);
  7551. } else {
  7552. row._details.detach();
  7553. }
  7554. __details_events(ctx[0]);
  7555. }
  7556. }
  7557. };
  7558. var __details_events = function __details_events(settings) {
  7559. var api = new _Api2(settings);
  7560. var namespace = '.dt.DT_details';
  7561. var drawEvent = 'draw' + namespace;
  7562. var colvisEvent = 'column-visibility' + namespace;
  7563. var destroyEvent = 'destroy' + namespace;
  7564. var data = settings.aoData;
  7565. api.off(drawEvent + ' ' + colvisEvent + ' ' + destroyEvent);
  7566. if (_pluck(data, '_details').length > 0) {
  7567. // On each draw, insert the required elements into the document
  7568. api.on(drawEvent, function (e, ctx) {
  7569. if (settings !== ctx) {
  7570. return;
  7571. }
  7572. api.rows({ page: 'current' }).eq(0).each(function (idx) {
  7573. // Internal data grab
  7574. var row = data[idx];
  7575. if (row._detailsShow) {
  7576. row._details.insertAfter(row.nTr);
  7577. }
  7578. });
  7579. });
  7580. // Column visibility change - update the colspan
  7581. api.on(colvisEvent, function (e, ctx, idx, vis) {
  7582. if (settings !== ctx) {
  7583. return;
  7584. }
  7585. // Update the colspan for the details rows (note, only if it already has
  7586. // a colspan)
  7587. var row,
  7588. visible = _fnVisbleColumns(ctx);
  7589. for (var i = 0, ien = data.length; i < ien; i++) {
  7590. row = data[i];
  7591. if (row._details) {
  7592. row._details.children('td[colspan]').attr('colspan', visible);
  7593. }
  7594. }
  7595. });
  7596. // Table destroyed - nuke any child rows
  7597. api.on(destroyEvent, function (e, ctx) {
  7598. if (settings !== ctx) {
  7599. return;
  7600. }
  7601. for (var i = 0, ien = data.length; i < ien; i++) {
  7602. if (data[i]._details) {
  7603. __details_remove(api, i);
  7604. }
  7605. }
  7606. });
  7607. }
  7608. };
  7609. // Strings for the method names to help minification
  7610. var _emp = '';
  7611. var _child_obj = _emp + 'row().child';
  7612. var _child_mth = _child_obj + '()';
  7613. // data can be:
  7614. // tr
  7615. // string
  7616. // jQuery or array of any of the above
  7617. _api_register(_child_mth, function (data, klass) {
  7618. var ctx = this.context;
  7619. if (data === undefined) {
  7620. // get
  7621. return ctx.length && this.length ? ctx[0].aoData[this[0]]._details : undefined;
  7622. } else if (data === true) {
  7623. // show
  7624. this.child.show();
  7625. } else if (data === false) {
  7626. // remove
  7627. __details_remove(this);
  7628. } else if (ctx.length && this.length) {
  7629. // set
  7630. __details_add(ctx[0], ctx[0].aoData[this[0]], data, klass);
  7631. }
  7632. return this;
  7633. });
  7634. _api_register([_child_obj + '.show()', _child_mth + '.show()' // only when `child()` was called with parameters (without
  7635. ], function (show) {
  7636. // it returns an object and this method is not executed)
  7637. __details_display(this, true);
  7638. return this;
  7639. });
  7640. _api_register([_child_obj + '.hide()', _child_mth + '.hide()' // only when `child()` was called with parameters (without
  7641. ], function () {
  7642. // it returns an object and this method is not executed)
  7643. __details_display(this, false);
  7644. return this;
  7645. });
  7646. _api_register([_child_obj + '.remove()', _child_mth + '.remove()' // only when `child()` was called with parameters (without
  7647. ], function () {
  7648. // it returns an object and this method is not executed)
  7649. __details_remove(this);
  7650. return this;
  7651. });
  7652. _api_register(_child_obj + '.isShown()', function () {
  7653. var ctx = this.context;
  7654. if (ctx.length && this.length) {
  7655. // _detailsShown as false or undefined will fall through to return false
  7656. return ctx[0].aoData[this[0]]._detailsShow || false;
  7657. }
  7658. return false;
  7659. });
  7660. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  7661. * Columns
  7662. *
  7663. * {integer} - column index (>=0 count from left, <0 count from right)
  7664. * "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
  7665. * "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
  7666. * "{string}:name" - column name
  7667. * "{string}" - jQuery selector on column header nodes
  7668. *
  7669. */
  7670. // can be an array of these items, comma separated list, or an array of comma
  7671. // separated lists
  7672. var __re_column_selector = /^([^:]+):(name|visIdx|visible)$/;
  7673. // r1 and r2 are redundant - but it means that the parameters match for the
  7674. // iterator callback in columns().data()
  7675. var __columnData = function __columnData(settings, column, r1, r2, rows) {
  7676. var a = [];
  7677. for (var row = 0, ien = rows.length; row < ien; row++) {
  7678. a.push(_fnGetCellData(settings, rows[row], column));
  7679. }
  7680. return a;
  7681. };
  7682. var __column_selector = function __column_selector(settings, selector, opts) {
  7683. var columns = settings.aoColumns,
  7684. names = _pluck(columns, 'sName'),
  7685. nodes = _pluck(columns, 'nTh');
  7686. var run = function run(s) {
  7687. var selInt = _intVal(s);
  7688. // Selector - all
  7689. if (s === '') {
  7690. return _range(columns.length);
  7691. }
  7692. // Selector - index
  7693. if (selInt !== null) {
  7694. return [selInt >= 0 ? selInt : // Count from left
  7695. columns.length + selInt // Count from right (+ because its a negative value)
  7696. ];
  7697. }
  7698. // Selector = function
  7699. if (typeof s === 'function') {
  7700. var rows = _selector_row_indexes(settings, opts);
  7701. return $.map(columns, function (col, idx) {
  7702. return s(idx, __columnData(settings, idx, 0, 0, rows), nodes[idx]) ? idx : null;
  7703. });
  7704. }
  7705. // jQuery or string selector
  7706. var match = typeof s === 'string' ? s.match(__re_column_selector) : '';
  7707. if (match) {
  7708. switch (match[2]) {
  7709. case 'visIdx':
  7710. case 'visible':
  7711. var idx = parseInt(match[1], 10);
  7712. // Visible index given, convert to column index
  7713. if (idx < 0) {
  7714. // Counting from the right
  7715. var visColumns = $.map(columns, function (col, i) {
  7716. return col.bVisible ? i : null;
  7717. });
  7718. return [visColumns[visColumns.length + idx]];
  7719. }
  7720. // Counting from the left
  7721. return [_fnVisibleToColumnIndex(settings, idx)];
  7722. case 'name':
  7723. // match by name. `names` is column index complete and in order
  7724. return $.map(names, function (name, i) {
  7725. return name === match[1] ? i : null;
  7726. });
  7727. default:
  7728. return [];
  7729. }
  7730. }
  7731. // Cell in the table body
  7732. if (s.nodeName && s._DT_CellIndex) {
  7733. return [s._DT_CellIndex.column];
  7734. }
  7735. // jQuery selector on the TH elements for the columns
  7736. var jqResult = $(nodes).filter(s).map(function () {
  7737. return $.inArray(this, nodes); // `nodes` is column index complete and in order
  7738. }).toArray();
  7739. if (jqResult.length || !s.nodeName) {
  7740. return jqResult;
  7741. }
  7742. // Otherwise a node which might have a `dt-column` data attribute, or be
  7743. // a child or such an element
  7744. var host = $(s).closest('*[data-dt-column]');
  7745. return host.length ? [host.data('dt-column')] : [];
  7746. };
  7747. return _selector_run('column', selector, run, settings, opts);
  7748. };
  7749. var __setColumnVis = function __setColumnVis(settings, column, vis) {
  7750. var cols = settings.aoColumns,
  7751. col = cols[column],
  7752. data = settings.aoData,
  7753. row,
  7754. cells,
  7755. i,
  7756. ien,
  7757. tr;
  7758. // Get
  7759. if (vis === undefined) {
  7760. return col.bVisible;
  7761. }
  7762. // Set
  7763. // No change
  7764. if (col.bVisible === vis) {
  7765. return;
  7766. }
  7767. if (vis) {
  7768. // Insert column
  7769. // Need to decide if we should use appendChild or insertBefore
  7770. var insertBefore = $.inArray(true, _pluck(cols, 'bVisible'), column + 1);
  7771. for (i = 0, ien = data.length; i < ien; i++) {
  7772. tr = data[i].nTr;
  7773. cells = data[i].anCells;
  7774. if (tr) {
  7775. // insertBefore can act like appendChild if 2nd arg is null
  7776. tr.insertBefore(cells[column], cells[insertBefore] || null);
  7777. }
  7778. }
  7779. } else {
  7780. // Remove column
  7781. $(_pluck(settings.aoData, 'anCells', column)).detach();
  7782. }
  7783. // Common actions
  7784. col.bVisible = vis;
  7785. _fnDrawHead(settings, settings.aoHeader);
  7786. _fnDrawHead(settings, settings.aoFooter);
  7787. _fnSaveState(settings);
  7788. };
  7789. _api_register('columns()', function (selector, opts) {
  7790. // argument shifting
  7791. if (selector === undefined) {
  7792. selector = '';
  7793. } else if ($.isPlainObject(selector)) {
  7794. opts = selector;
  7795. selector = '';
  7796. }
  7797. opts = _selector_opts(opts);
  7798. var inst = this.iterator('table', function (settings) {
  7799. return __column_selector(settings, selector, opts);
  7800. }, 1);
  7801. // Want argument shifting here and in _row_selector?
  7802. inst.selector.cols = selector;
  7803. inst.selector.opts = opts;
  7804. return inst;
  7805. });
  7806. _api_registerPlural('columns().header()', 'column().header()', function (selector, opts) {
  7807. return this.iterator('column', function (settings, column) {
  7808. return settings.aoColumns[column].nTh;
  7809. }, 1);
  7810. });
  7811. _api_registerPlural('columns().footer()', 'column().footer()', function (selector, opts) {
  7812. return this.iterator('column', function (settings, column) {
  7813. return settings.aoColumns[column].nTf;
  7814. }, 1);
  7815. });
  7816. _api_registerPlural('columns().data()', 'column().data()', function () {
  7817. return this.iterator('column-rows', __columnData, 1);
  7818. });
  7819. _api_registerPlural('columns().dataSrc()', 'column().dataSrc()', function () {
  7820. return this.iterator('column', function (settings, column) {
  7821. return settings.aoColumns[column].mData;
  7822. }, 1);
  7823. });
  7824. _api_registerPlural('columns().cache()', 'column().cache()', function (type) {
  7825. return this.iterator('column-rows', function (settings, column, i, j, rows) {
  7826. return _pluck_order(settings.aoData, rows, type === 'search' ? '_aFilterData' : '_aSortData', column);
  7827. }, 1);
  7828. });
  7829. _api_registerPlural('columns().nodes()', 'column().nodes()', function () {
  7830. return this.iterator('column-rows', function (settings, column, i, j, rows) {
  7831. return _pluck_order(settings.aoData, rows, 'anCells', column);
  7832. }, 1);
  7833. });
  7834. _api_registerPlural('columns().visible()', 'column().visible()', function (vis, calc) {
  7835. var ret = this.iterator('column', function (settings, column) {
  7836. if (vis === undefined) {
  7837. return settings.aoColumns[column].bVisible;
  7838. } // else
  7839. __setColumnVis(settings, column, vis);
  7840. });
  7841. // Group the column visibility changes
  7842. if (vis !== undefined) {
  7843. // Second loop once the first is done for events
  7844. this.iterator('column', function (settings, column) {
  7845. _fnCallbackFire(settings, null, 'column-visibility', [settings, column, vis, calc]);
  7846. });
  7847. if (calc === undefined || calc) {
  7848. this.columns.adjust();
  7849. }
  7850. }
  7851. return ret;
  7852. });
  7853. _api_registerPlural('columns().indexes()', 'column().index()', function (type) {
  7854. return this.iterator('column', function (settings, column) {
  7855. return type === 'visible' ? _fnColumnIndexToVisible(settings, column) : column;
  7856. }, 1);
  7857. });
  7858. _api_register('columns.adjust()', function () {
  7859. return this.iterator('table', function (settings) {
  7860. _fnAdjustColumnSizing(settings);
  7861. }, 1);
  7862. });
  7863. _api_register('column.index()', function (type, idx) {
  7864. if (this.context.length !== 0) {
  7865. var ctx = this.context[0];
  7866. if (type === 'fromVisible' || type === 'toData') {
  7867. return _fnVisibleToColumnIndex(ctx, idx);
  7868. } else if (type === 'fromData' || type === 'toVisible') {
  7869. return _fnColumnIndexToVisible(ctx, idx);
  7870. }
  7871. }
  7872. });
  7873. _api_register('column()', function (selector, opts) {
  7874. return _selector_first(this.columns(selector, opts));
  7875. });
  7876. var __cell_selector = function __cell_selector(settings, selector, opts) {
  7877. var data = settings.aoData;
  7878. var rows = _selector_row_indexes(settings, opts);
  7879. var cells = _removeEmpty(_pluck_order(data, rows, 'anCells'));
  7880. var allCells = $([].concat.apply([], cells));
  7881. var row;
  7882. var columns = settings.aoColumns.length;
  7883. var a, i, ien, j, o, host;
  7884. var run = function run(s) {
  7885. var fnSelector = typeof s === 'function';
  7886. if (s === null || s === undefined || fnSelector) {
  7887. // All cells and function selectors
  7888. a = [];
  7889. for (i = 0, ien = rows.length; i < ien; i++) {
  7890. row = rows[i];
  7891. for (j = 0; j < columns; j++) {
  7892. o = {
  7893. row: row,
  7894. column: j
  7895. };
  7896. if (fnSelector) {
  7897. // Selector - function
  7898. host = data[row];
  7899. if (s(o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null)) {
  7900. a.push(o);
  7901. }
  7902. } else {
  7903. // Selector - all
  7904. a.push(o);
  7905. }
  7906. }
  7907. }
  7908. return a;
  7909. }
  7910. // Selector - index
  7911. if ($.isPlainObject(s)) {
  7912. return [s];
  7913. }
  7914. // Selector - jQuery filtered cells
  7915. var jqResult = allCells.filter(s).map(function (i, el) {
  7916. return { // use a new object, in case someone changes the values
  7917. row: el._DT_CellIndex.row,
  7918. column: el._DT_CellIndex.column
  7919. };
  7920. }).toArray();
  7921. if (jqResult.length || !s.nodeName) {
  7922. return jqResult;
  7923. }
  7924. // Otherwise the selector is a node, and there is one last option - the
  7925. // element might be a child of an element which has dt-row and dt-column
  7926. // data attributes
  7927. host = $(s).closest('*[data-dt-row]');
  7928. return host.length ? [{
  7929. row: host.data('dt-row'),
  7930. column: host.data('dt-column')
  7931. }] : [];
  7932. };
  7933. return _selector_run('cell', selector, run, settings, opts);
  7934. };
  7935. _api_register('cells()', function (rowSelector, columnSelector, opts) {
  7936. // Argument shifting
  7937. if ($.isPlainObject(rowSelector)) {
  7938. // Indexes
  7939. if (rowSelector.row === undefined) {
  7940. // Selector options in first parameter
  7941. opts = rowSelector;
  7942. rowSelector = null;
  7943. } else {
  7944. // Cell index objects in first parameter
  7945. opts = columnSelector;
  7946. columnSelector = null;
  7947. }
  7948. }
  7949. if ($.isPlainObject(columnSelector)) {
  7950. opts = columnSelector;
  7951. columnSelector = null;
  7952. }
  7953. // Cell selector
  7954. if (columnSelector === null || columnSelector === undefined) {
  7955. return this.iterator('table', function (settings) {
  7956. return __cell_selector(settings, rowSelector, _selector_opts(opts));
  7957. });
  7958. }
  7959. // Row + column selector
  7960. var columns = this.columns(columnSelector, opts);
  7961. var rows = this.rows(rowSelector, opts);
  7962. var a, i, ien, j, jen;
  7963. var cells = this.iterator('table', function (settings, idx) {
  7964. a = [];
  7965. for (i = 0, ien = rows[idx].length; i < ien; i++) {
  7966. for (j = 0, jen = columns[idx].length; j < jen; j++) {
  7967. a.push({
  7968. row: rows[idx][i],
  7969. column: columns[idx][j]
  7970. });
  7971. }
  7972. }
  7973. return a;
  7974. }, 1);
  7975. $.extend(cells.selector, {
  7976. cols: columnSelector,
  7977. rows: rowSelector,
  7978. opts: opts
  7979. });
  7980. return cells;
  7981. });
  7982. _api_registerPlural('cells().nodes()', 'cell().node()', function () {
  7983. return this.iterator('cell', function (settings, row, column) {
  7984. var data = settings.aoData[row];
  7985. return data && data.anCells ? data.anCells[column] : undefined;
  7986. }, 1);
  7987. });
  7988. _api_register('cells().data()', function () {
  7989. return this.iterator('cell', function (settings, row, column) {
  7990. return _fnGetCellData(settings, row, column);
  7991. }, 1);
  7992. });
  7993. _api_registerPlural('cells().cache()', 'cell().cache()', function (type) {
  7994. type = type === 'search' ? '_aFilterData' : '_aSortData';
  7995. return this.iterator('cell', function (settings, row, column) {
  7996. return settings.aoData[row][type][column];
  7997. }, 1);
  7998. });
  7999. _api_registerPlural('cells().render()', 'cell().render()', function (type) {
  8000. return this.iterator('cell', function (settings, row, column) {
  8001. return _fnGetCellData(settings, row, column, type);
  8002. }, 1);
  8003. });
  8004. _api_registerPlural('cells().indexes()', 'cell().index()', function () {
  8005. return this.iterator('cell', function (settings, row, column) {
  8006. return {
  8007. row: row,
  8008. column: column,
  8009. columnVisible: _fnColumnIndexToVisible(settings, column)
  8010. };
  8011. }, 1);
  8012. });
  8013. _api_registerPlural('cells().invalidate()', 'cell().invalidate()', function (src) {
  8014. return this.iterator('cell', function (settings, row, column) {
  8015. _fnInvalidate(settings, row, src, column);
  8016. });
  8017. });
  8018. _api_register('cell()', function (rowSelector, columnSelector, opts) {
  8019. return _selector_first(this.cells(rowSelector, columnSelector, opts));
  8020. });
  8021. _api_register('cell().data()', function (data) {
  8022. var ctx = this.context;
  8023. var cell = this[0];
  8024. if (data === undefined) {
  8025. // Get
  8026. return ctx.length && cell.length ? _fnGetCellData(ctx[0], cell[0].row, cell[0].column) : undefined;
  8027. }
  8028. // Set
  8029. _fnSetCellData(ctx[0], cell[0].row, cell[0].column, data);
  8030. _fnInvalidate(ctx[0], cell[0].row, 'data', cell[0].column);
  8031. return this;
  8032. });
  8033. /**
  8034. * Get current ordering (sorting) that has been applied to the table.
  8035. *
  8036. * @returns {array} 2D array containing the sorting information for the first
  8037. * table in the current context. Each element in the parent array represents
  8038. * a column being sorted upon (i.e. multi-sorting with two columns would have
  8039. * 2 inner arrays). The inner arrays may have 2 or 3 elements. The first is
  8040. * the column index that the sorting condition applies to, the second is the
  8041. * direction of the sort (`desc` or `asc`) and, optionally, the third is the
  8042. * index of the sorting order from the `column.sorting` initialisation array.
  8043. */ /**
  8044. * Set the ordering for the table.
  8045. *
  8046. * @param {integer} order Column index to sort upon.
  8047. * @param {string} direction Direction of the sort to be applied (`asc` or `desc`)
  8048. * @returns {DataTables.Api} this
  8049. */ /**
  8050. * Set the ordering for the table.
  8051. *
  8052. * @param {array} order 1D array of sorting information to be applied.
  8053. * @param {array} [...] Optional additional sorting conditions
  8054. * @returns {DataTables.Api} this
  8055. */ /**
  8056. * Set the ordering for the table.
  8057. *
  8058. * @param {array} order 2D array of sorting information to be applied.
  8059. * @returns {DataTables.Api} this
  8060. */
  8061. _api_register('order()', function (order, dir) {
  8062. var ctx = this.context;
  8063. if (order === undefined) {
  8064. // get
  8065. return ctx.length !== 0 ? ctx[0].aaSorting : undefined;
  8066. }
  8067. // set
  8068. if (typeof order === 'number') {
  8069. // Simple column / direction passed in
  8070. order = [[order, dir]];
  8071. } else if (order.length && !$.isArray(order[0])) {
  8072. // Arguments passed in (list of 1D arrays)
  8073. order = Array.prototype.slice.call(arguments);
  8074. }
  8075. // otherwise a 2D array was passed in
  8076. return this.iterator('table', function (settings) {
  8077. settings.aaSorting = order.slice();
  8078. });
  8079. });
  8080. /**
  8081. * Attach a sort listener to an element for a given column
  8082. *
  8083. * @param {node|jQuery|string} node Identifier for the element(s) to attach the
  8084. * listener to. This can take the form of a single DOM node, a jQuery
  8085. * collection of nodes or a jQuery selector which will identify the node(s).
  8086. * @param {integer} column the column that a click on this node will sort on
  8087. * @param {function} [callback] callback function when sort is run
  8088. * @returns {DataTables.Api} this
  8089. */
  8090. _api_register('order.listener()', function (node, column, callback) {
  8091. return this.iterator('table', function (settings) {
  8092. _fnSortAttachListener(settings, node, column, callback);
  8093. });
  8094. });
  8095. _api_register('order.fixed()', function (set) {
  8096. if (!set) {
  8097. var ctx = this.context;
  8098. var fixed = ctx.length ? ctx[0].aaSortingFixed : undefined;
  8099. return $.isArray(fixed) ? { pre: fixed } : fixed;
  8100. }
  8101. return this.iterator('table', function (settings) {
  8102. settings.aaSortingFixed = $.extend(true, {}, set);
  8103. });
  8104. });
  8105. // Order by the selected column(s)
  8106. _api_register(['columns().order()', 'column().order()'], function (dir) {
  8107. var that = this;
  8108. return this.iterator('table', function (settings, i) {
  8109. var sort = [];
  8110. $.each(that[i], function (j, col) {
  8111. sort.push([col, dir]);
  8112. });
  8113. settings.aaSorting = sort;
  8114. });
  8115. });
  8116. _api_register('search()', function (input, regex, smart, caseInsen) {
  8117. var ctx = this.context;
  8118. if (input === undefined) {
  8119. // get
  8120. return ctx.length !== 0 ? ctx[0].oPreviousSearch.sSearch : undefined;
  8121. }
  8122. // set
  8123. return this.iterator('table', function (settings) {
  8124. if (!settings.oFeatures.bFilter) {
  8125. return;
  8126. }
  8127. _fnFilterComplete(settings, $.extend({}, settings.oPreviousSearch, {
  8128. "sSearch": input + "",
  8129. "bRegex": regex === null ? false : regex,
  8130. "bSmart": smart === null ? true : smart,
  8131. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  8132. }), 1);
  8133. });
  8134. });
  8135. _api_registerPlural('columns().search()', 'column().search()', function (input, regex, smart, caseInsen) {
  8136. return this.iterator('column', function (settings, column) {
  8137. var preSearch = settings.aoPreSearchCols;
  8138. if (input === undefined) {
  8139. // get
  8140. return preSearch[column].sSearch;
  8141. }
  8142. // set
  8143. if (!settings.oFeatures.bFilter) {
  8144. return;
  8145. }
  8146. $.extend(preSearch[column], {
  8147. "sSearch": input + "",
  8148. "bRegex": regex === null ? false : regex,
  8149. "bSmart": smart === null ? true : smart,
  8150. "bCaseInsensitive": caseInsen === null ? true : caseInsen
  8151. });
  8152. _fnFilterComplete(settings, settings.oPreviousSearch, 1);
  8153. });
  8154. });
  8155. /*
  8156. * State API methods
  8157. */
  8158. _api_register('state()', function () {
  8159. return this.context.length ? this.context[0].oSavedState : null;
  8160. });
  8161. _api_register('state.clear()', function () {
  8162. return this.iterator('table', function (settings) {
  8163. // Save an empty object
  8164. settings.fnStateSaveCallback.call(settings.oInstance, settings, {});
  8165. });
  8166. });
  8167. _api_register('state.loaded()', function () {
  8168. return this.context.length ? this.context[0].oLoadedState : null;
  8169. });
  8170. _api_register('state.save()', function () {
  8171. return this.iterator('table', function (settings) {
  8172. _fnSaveState(settings);
  8173. });
  8174. });
  8175. /**
  8176. * Provide a common method for plug-ins to check the version of DataTables being
  8177. * used, in order to ensure compatibility.
  8178. *
  8179. * @param {string} version Version string to check for, in the format "X.Y.Z".
  8180. * Note that the formats "X" and "X.Y" are also acceptable.
  8181. * @returns {boolean} true if this version of DataTables is greater or equal to
  8182. * the required version, or false if this version of DataTales is not
  8183. * suitable
  8184. * @static
  8185. * @dtopt API-Static
  8186. *
  8187. * @example
  8188. * alert( $.fn.dataTable.versionCheck( '1.9.0' ) );
  8189. */
  8190. DataTable.versionCheck = DataTable.fnVersionCheck = function (version) {
  8191. var aThis = DataTable.version.split('.');
  8192. var aThat = version.split('.');
  8193. var iThis, iThat;
  8194. for (var i = 0, iLen = aThat.length; i < iLen; i++) {
  8195. iThis = parseInt(aThis[i], 10) || 0;
  8196. iThat = parseInt(aThat[i], 10) || 0;
  8197. // Parts are the same, keep comparing
  8198. if (iThis === iThat) {
  8199. continue;
  8200. }
  8201. // Parts are different, return immediately
  8202. return iThis > iThat;
  8203. }
  8204. return true;
  8205. };
  8206. /**
  8207. * Check if a `<table>` node is a DataTable table already or not.
  8208. *
  8209. * @param {node|jquery|string} table Table node, jQuery object or jQuery
  8210. * selector for the table to test. Note that if more than more than one
  8211. * table is passed on, only the first will be checked
  8212. * @returns {boolean} true the table given is a DataTable, or false otherwise
  8213. * @static
  8214. * @dtopt API-Static
  8215. *
  8216. * @example
  8217. * if ( ! $.fn.DataTable.isDataTable( '#example' ) ) {
  8218. * $('#example').dataTable();
  8219. * }
  8220. */
  8221. DataTable.isDataTable = DataTable.fnIsDataTable = function (table) {
  8222. var t = $(table).get(0);
  8223. var is = false;
  8224. if (table instanceof DataTable.Api) {
  8225. return true;
  8226. }
  8227. $.each(DataTable.settings, function (i, o) {
  8228. var head = o.nScrollHead ? $('table', o.nScrollHead)[0] : null;
  8229. var foot = o.nScrollFoot ? $('table', o.nScrollFoot)[0] : null;
  8230. if (o.nTable === t || head === t || foot === t) {
  8231. is = true;
  8232. }
  8233. });
  8234. return is;
  8235. };
  8236. /**
  8237. * Get all DataTable tables that have been initialised - optionally you can
  8238. * select to get only currently visible tables.
  8239. *
  8240. * @param {boolean} [visible=false] Flag to indicate if you want all (default)
  8241. * or visible tables only.
  8242. * @returns {array} Array of `table` nodes (not DataTable instances) which are
  8243. * DataTables
  8244. * @static
  8245. * @dtopt API-Static
  8246. *
  8247. * @example
  8248. * $.each( $.fn.dataTable.tables(true), function () {
  8249. * $(table).DataTable().columns.adjust();
  8250. * } );
  8251. */
  8252. DataTable.tables = DataTable.fnTables = function (visible) {
  8253. var api = false;
  8254. if ($.isPlainObject(visible)) {
  8255. api = visible.api;
  8256. visible = visible.visible;
  8257. }
  8258. var a = $.map(DataTable.settings, function (o) {
  8259. if (!visible || visible && $(o.nTable).is(':visible')) {
  8260. return o.nTable;
  8261. }
  8262. });
  8263. return api ? new _Api2(a) : a;
  8264. };
  8265. /**
  8266. * Convert from camel case parameters to Hungarian notation. This is made public
  8267. * for the extensions to provide the same ability as DataTables core to accept
  8268. * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase
  8269. * parameters.
  8270. *
  8271. * @param {object} src The model object which holds all parameters that can be
  8272. * mapped.
  8273. * @param {object} user The object to convert from camel case to Hungarian.
  8274. * @param {boolean} force When set to `true`, properties which already have a
  8275. * Hungarian value in the `user` object will be overwritten. Otherwise they
  8276. * won't be.
  8277. */
  8278. DataTable.camelToHungarian = _fnCamelToHungarian;
  8279. /**
  8280. *
  8281. */
  8282. _api_register('$()', function (selector, opts) {
  8283. var rows = this.rows(opts).nodes(),
  8284. // Get all rows
  8285. jqRows = $(rows);
  8286. return $([].concat(jqRows.filter(selector).toArray(), jqRows.find(selector).toArray()));
  8287. });
  8288. // jQuery functions to operate on the tables
  8289. $.each(['on', 'one', 'off'], function (i, key) {
  8290. _api_register(key + '()', function () /* event, handler */{
  8291. var args = Array.prototype.slice.call(arguments);
  8292. // Add the `dt` namespace automatically if it isn't already present
  8293. args[0] = $.map(args[0].split(/\s/), function (e) {
  8294. return !e.match(/\.dt\b/) ? e + '.dt' : e;
  8295. }).join(' ');
  8296. var inst = $(this.tables().nodes());
  8297. inst[key].apply(inst, args);
  8298. return this;
  8299. });
  8300. });
  8301. _api_register('clear()', function () {
  8302. return this.iterator('table', function (settings) {
  8303. _fnClearTable(settings);
  8304. });
  8305. });
  8306. _api_register('settings()', function () {
  8307. return new _Api2(this.context, this.context);
  8308. });
  8309. _api_register('init()', function () {
  8310. var ctx = this.context;
  8311. return ctx.length ? ctx[0].oInit : null;
  8312. });
  8313. _api_register('data()', function () {
  8314. return this.iterator('table', function (settings) {
  8315. return _pluck(settings.aoData, '_aData');
  8316. }).flatten();
  8317. });
  8318. _api_register('destroy()', function (remove) {
  8319. remove = remove || false;
  8320. return this.iterator('table', function (settings) {
  8321. var orig = settings.nTableWrapper.parentNode;
  8322. var classes = settings.oClasses;
  8323. var table = settings.nTable;
  8324. var tbody = settings.nTBody;
  8325. var thead = settings.nTHead;
  8326. var tfoot = settings.nTFoot;
  8327. var jqTable = $(table);
  8328. var jqTbody = $(tbody);
  8329. var jqWrapper = $(settings.nTableWrapper);
  8330. var rows = $.map(settings.aoData, function (r) {
  8331. return r.nTr;
  8332. });
  8333. var i, ien;
  8334. // Flag to note that the table is currently being destroyed - no action
  8335. // should be taken
  8336. settings.bDestroying = true;
  8337. // Fire off the destroy callbacks for plug-ins etc
  8338. _fnCallbackFire(settings, "aoDestroyCallback", "destroy", [settings]);
  8339. // If not being removed from the document, make all columns visible
  8340. if (!remove) {
  8341. new _Api2(settings).columns().visible(true);
  8342. }
  8343. // Blitz all `DT` namespaced events (these are internal events, the
  8344. // lowercase, `dt` events are user subscribed and they are responsible
  8345. // for removing them
  8346. jqWrapper.off('.DT').find(':not(tbody *)').off('.DT');
  8347. $(window).off('.DT-' + settings.sInstance);
  8348. // When scrolling we had to break the table up - restore it
  8349. if (table != thead.parentNode) {
  8350. jqTable.children('thead').detach();
  8351. jqTable.append(thead);
  8352. }
  8353. if (tfoot && table != tfoot.parentNode) {
  8354. jqTable.children('tfoot').detach();
  8355. jqTable.append(tfoot);
  8356. }
  8357. settings.aaSorting = [];
  8358. settings.aaSortingFixed = [];
  8359. _fnSortingClasses(settings);
  8360. $(rows).removeClass(settings.asStripeClasses.join(' '));
  8361. $('th, td', thead).removeClass(classes.sSortable + ' ' + classes.sSortableAsc + ' ' + classes.sSortableDesc + ' ' + classes.sSortableNone);
  8362. // Add the TR elements back into the table in their original order
  8363. jqTbody.children().detach();
  8364. jqTbody.append(rows);
  8365. // Remove the DataTables generated nodes, events and classes
  8366. var removedMethod = remove ? 'remove' : 'detach';
  8367. jqTable[removedMethod]();
  8368. jqWrapper[removedMethod]();
  8369. // If we need to reattach the table to the document
  8370. if (!remove && orig) {
  8371. // insertBefore acts like appendChild if !arg[1]
  8372. orig.insertBefore(table, settings.nTableReinsertBefore);
  8373. // Restore the width of the original table - was read from the style property,
  8374. // so we can restore directly to that
  8375. jqTable.css('width', settings.sDestroyWidth).removeClass(classes.sTable);
  8376. // If the were originally stripe classes - then we add them back here.
  8377. // Note this is not fool proof (for example if not all rows had stripe
  8378. // classes - but it's a good effort without getting carried away
  8379. ien = settings.asDestroyStripes.length;
  8380. if (ien) {
  8381. jqTbody.children().each(function (i) {
  8382. $(this).addClass(settings.asDestroyStripes[i % ien]);
  8383. });
  8384. }
  8385. }
  8386. /* Remove the settings object from the settings array */
  8387. var idx = $.inArray(settings, DataTable.settings);
  8388. if (idx !== -1) {
  8389. DataTable.settings.splice(idx, 1);
  8390. }
  8391. });
  8392. });
  8393. // Add the `every()` method for rows, columns and cells in a compact form
  8394. $.each(['column', 'row', 'cell'], function (i, type) {
  8395. _api_register(type + 's().every()', function (fn) {
  8396. var opts = this.selector.opts;
  8397. var api = this;
  8398. return this.iterator(type, function (settings, arg1, arg2, arg3, arg4) {
  8399. // Rows and columns:
  8400. // arg1 - index
  8401. // arg2 - table counter
  8402. // arg3 - loop counter
  8403. // arg4 - undefined
  8404. // Cells:
  8405. // arg1 - row index
  8406. // arg2 - column index
  8407. // arg3 - table counter
  8408. // arg4 - loop counter
  8409. fn.call(api[type](arg1, type === 'cell' ? arg2 : opts, type === 'cell' ? opts : undefined), arg1, arg2, arg3, arg4);
  8410. });
  8411. });
  8412. });
  8413. // i18n method for extensions to be able to use the language object from the
  8414. // DataTable
  8415. _api_register('i18n()', function (token, def, plural) {
  8416. var ctx = this.context[0];
  8417. var resolved = _fnGetObjectDataFn(token)(ctx.oLanguage);
  8418. if (resolved === undefined) {
  8419. resolved = def;
  8420. }
  8421. if (plural !== undefined && $.isPlainObject(resolved)) {
  8422. resolved = resolved[plural] !== undefined ? resolved[plural] : resolved._;
  8423. }
  8424. return resolved.replace('%d', plural); // nb: plural might be undefined,
  8425. });
  8426. /**
  8427. * Version string for plug-ins to check compatibility. Allowed format is
  8428. * `a.b.c-d` where: a:int, b:int, c:int, d:string(dev|beta|alpha). `d` is used
  8429. * only for non-release builds. See http://semver.org/ for more information.
  8430. * @member
  8431. * @type string
  8432. * @default Version number
  8433. */
  8434. DataTable.version = "1.10.16";
  8435. /**
  8436. * Private data store, containing all of the settings objects that are
  8437. * created for the tables on a given page.
  8438. *
  8439. * Note that the `DataTable.settings` object is aliased to
  8440. * `jQuery.fn.dataTableExt` through which it may be accessed and
  8441. * manipulated, or `jQuery.fn.dataTable.settings`.
  8442. * @member
  8443. * @type array
  8444. * @default []
  8445. * @private
  8446. */
  8447. DataTable.settings = [];
  8448. /**
  8449. * Object models container, for the various models that DataTables has
  8450. * available to it. These models define the objects that are used to hold
  8451. * the active state and configuration of the table.
  8452. * @namespace
  8453. */
  8454. DataTable.models = {};
  8455. /**
  8456. * Template object for the way in which DataTables holds information about
  8457. * search information for the global filter and individual column filters.
  8458. * @namespace
  8459. */
  8460. DataTable.models.oSearch = {
  8461. /**
  8462. * Flag to indicate if the filtering should be case insensitive or not
  8463. * @type boolean
  8464. * @default true
  8465. */
  8466. "bCaseInsensitive": true,
  8467. /**
  8468. * Applied search term
  8469. * @type string
  8470. * @default <i>Empty string</i>
  8471. */
  8472. "sSearch": "",
  8473. /**
  8474. * Flag to indicate if the search term should be interpreted as a
  8475. * regular expression (true) or not (false) and therefore and special
  8476. * regex characters escaped.
  8477. * @type boolean
  8478. * @default false
  8479. */
  8480. "bRegex": false,
  8481. /**
  8482. * Flag to indicate if DataTables is to use its smart filtering or not.
  8483. * @type boolean
  8484. * @default true
  8485. */
  8486. "bSmart": true
  8487. };
  8488. /**
  8489. * Template object for the way in which DataTables holds information about
  8490. * each individual row. This is the object format used for the settings
  8491. * aoData array.
  8492. * @namespace
  8493. */
  8494. DataTable.models.oRow = {
  8495. /**
  8496. * TR element for the row
  8497. * @type node
  8498. * @default null
  8499. */
  8500. "nTr": null,
  8501. /**
  8502. * Array of TD elements for each row. This is null until the row has been
  8503. * created.
  8504. * @type array nodes
  8505. * @default []
  8506. */
  8507. "anCells": null,
  8508. /**
  8509. * Data object from the original data source for the row. This is either
  8510. * an array if using the traditional form of DataTables, or an object if
  8511. * using mData options. The exact type will depend on the passed in
  8512. * data from the data source, or will be an array if using DOM a data
  8513. * source.
  8514. * @type array|object
  8515. * @default []
  8516. */
  8517. "_aData": [],
  8518. /**
  8519. * Sorting data cache - this array is ostensibly the same length as the
  8520. * number of columns (although each index is generated only as it is
  8521. * needed), and holds the data that is used for sorting each column in the
  8522. * row. We do this cache generation at the start of the sort in order that
  8523. * the formatting of the sort data need be done only once for each cell
  8524. * per sort. This array should not be read from or written to by anything
  8525. * other than the master sorting methods.
  8526. * @type array
  8527. * @default null
  8528. * @private
  8529. */
  8530. "_aSortData": null,
  8531. /**
  8532. * Per cell filtering data cache. As per the sort data cache, used to
  8533. * increase the performance of the filtering in DataTables
  8534. * @type array
  8535. * @default null
  8536. * @private
  8537. */
  8538. "_aFilterData": null,
  8539. /**
  8540. * Filtering data cache. This is the same as the cell filtering cache, but
  8541. * in this case a string rather than an array. This is easily computed with
  8542. * a join on `_aFilterData`, but is provided as a cache so the join isn't
  8543. * needed on every search (memory traded for performance)
  8544. * @type array
  8545. * @default null
  8546. * @private
  8547. */
  8548. "_sFilterRow": null,
  8549. /**
  8550. * Cache of the class name that DataTables has applied to the row, so we
  8551. * can quickly look at this variable rather than needing to do a DOM check
  8552. * on className for the nTr property.
  8553. * @type string
  8554. * @default <i>Empty string</i>
  8555. * @private
  8556. */
  8557. "_sRowStripe": "",
  8558. /**
  8559. * Denote if the original data source was from the DOM, or the data source
  8560. * object. This is used for invalidating data, so DataTables can
  8561. * automatically read data from the original source, unless uninstructed
  8562. * otherwise.
  8563. * @type string
  8564. * @default null
  8565. * @private
  8566. */
  8567. "src": null,
  8568. /**
  8569. * Index in the aoData array. This saves an indexOf lookup when we have the
  8570. * object, but want to know the index
  8571. * @type integer
  8572. * @default -1
  8573. * @private
  8574. */
  8575. "idx": -1
  8576. };
  8577. /**
  8578. * Template object for the column information object in DataTables. This object
  8579. * is held in the settings aoColumns array and contains all the information that
  8580. * DataTables needs about each individual column.
  8581. *
  8582. * Note that this object is related to {@link DataTable.defaults.column}
  8583. * but this one is the internal data store for DataTables's cache of columns.
  8584. * It should NOT be manipulated outside of DataTables. Any configuration should
  8585. * be done through the initialisation options.
  8586. * @namespace
  8587. */
  8588. DataTable.models.oColumn = {
  8589. /**
  8590. * Column index. This could be worked out on-the-fly with $.inArray, but it
  8591. * is faster to just hold it as a variable
  8592. * @type integer
  8593. * @default null
  8594. */
  8595. "idx": null,
  8596. /**
  8597. * A list of the columns that sorting should occur on when this column
  8598. * is sorted. That this property is an array allows multi-column sorting
  8599. * to be defined for a column (for example first name / last name columns
  8600. * would benefit from this). The values are integers pointing to the
  8601. * columns to be sorted on (typically it will be a single integer pointing
  8602. * at itself, but that doesn't need to be the case).
  8603. * @type array
  8604. */
  8605. "aDataSort": null,
  8606. /**
  8607. * Define the sorting directions that are applied to the column, in sequence
  8608. * as the column is repeatedly sorted upon - i.e. the first value is used
  8609. * as the sorting direction when the column if first sorted (clicked on).
  8610. * Sort it again (click again) and it will move on to the next index.
  8611. * Repeat until loop.
  8612. * @type array
  8613. */
  8614. "asSorting": null,
  8615. /**
  8616. * Flag to indicate if the column is searchable, and thus should be included
  8617. * in the filtering or not.
  8618. * @type boolean
  8619. */
  8620. "bSearchable": null,
  8621. /**
  8622. * Flag to indicate if the column is sortable or not.
  8623. * @type boolean
  8624. */
  8625. "bSortable": null,
  8626. /**
  8627. * Flag to indicate if the column is currently visible in the table or not
  8628. * @type boolean
  8629. */
  8630. "bVisible": null,
  8631. /**
  8632. * Store for manual type assignment using the `column.type` option. This
  8633. * is held in store so we can manipulate the column's `sType` property.
  8634. * @type string
  8635. * @default null
  8636. * @private
  8637. */
  8638. "_sManualType": null,
  8639. /**
  8640. * Flag to indicate if HTML5 data attributes should be used as the data
  8641. * source for filtering or sorting. True is either are.
  8642. * @type boolean
  8643. * @default false
  8644. * @private
  8645. */
  8646. "_bAttrSrc": false,
  8647. /**
  8648. * Developer definable function that is called whenever a cell is created (Ajax source,
  8649. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  8650. * allowing you to modify the DOM element (add background colour for example) when the
  8651. * element is available.
  8652. * @type function
  8653. * @param {element} nTd The TD node that has been created
  8654. * @param {*} sData The Data for the cell
  8655. * @param {array|object} oData The data for the whole row
  8656. * @param {int} iRow The row index for the aoData data store
  8657. * @default null
  8658. */
  8659. "fnCreatedCell": null,
  8660. /**
  8661. * Function to get data from a cell in a column. You should <b>never</b>
  8662. * access data directly through _aData internally in DataTables - always use
  8663. * the method attached to this property. It allows mData to function as
  8664. * required. This function is automatically assigned by the column
  8665. * initialisation method
  8666. * @type function
  8667. * @param {array|object} oData The data array/object for the array
  8668. * (i.e. aoData[]._aData)
  8669. * @param {string} sSpecific The specific data type you want to get -
  8670. * 'display', 'type' 'filter' 'sort'
  8671. * @returns {*} The data for the cell from the given row's data
  8672. * @default null
  8673. */
  8674. "fnGetData": null,
  8675. /**
  8676. * Function to set data for a cell in the column. You should <b>never</b>
  8677. * set the data directly to _aData internally in DataTables - always use
  8678. * this method. It allows mData to function as required. This function
  8679. * is automatically assigned by the column initialisation method
  8680. * @type function
  8681. * @param {array|object} oData The data array/object for the array
  8682. * (i.e. aoData[]._aData)
  8683. * @param {*} sValue Value to set
  8684. * @default null
  8685. */
  8686. "fnSetData": null,
  8687. /**
  8688. * Property to read the value for the cells in the column from the data
  8689. * source array / object. If null, then the default content is used, if a
  8690. * function is given then the return from the function is used.
  8691. * @type function|int|string|null
  8692. * @default null
  8693. */
  8694. "mData": null,
  8695. /**
  8696. * Partner property to mData which is used (only when defined) to get
  8697. * the data - i.e. it is basically the same as mData, but without the
  8698. * 'set' option, and also the data fed to it is the result from mData.
  8699. * This is the rendering method to match the data method of mData.
  8700. * @type function|int|string|null
  8701. * @default null
  8702. */
  8703. "mRender": null,
  8704. /**
  8705. * Unique header TH/TD element for this column - this is what the sorting
  8706. * listener is attached to (if sorting is enabled.)
  8707. * @type node
  8708. * @default null
  8709. */
  8710. "nTh": null,
  8711. /**
  8712. * Unique footer TH/TD element for this column (if there is one). Not used
  8713. * in DataTables as such, but can be used for plug-ins to reference the
  8714. * footer for each column.
  8715. * @type node
  8716. * @default null
  8717. */
  8718. "nTf": null,
  8719. /**
  8720. * The class to apply to all TD elements in the table's TBODY for the column
  8721. * @type string
  8722. * @default null
  8723. */
  8724. "sClass": null,
  8725. /**
  8726. * When DataTables calculates the column widths to assign to each column,
  8727. * it finds the longest string in each column and then constructs a
  8728. * temporary table and reads the widths from that. The problem with this
  8729. * is that "mmm" is much wider then "iiii", but the latter is a longer
  8730. * string - thus the calculation can go wrong (doing it properly and putting
  8731. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  8732. * a "work around" we provide this option. It will append its value to the
  8733. * text that is found to be the longest string for the column - i.e. padding.
  8734. * @type string
  8735. */
  8736. "sContentPadding": null,
  8737. /**
  8738. * Allows a default value to be given for a column's data, and will be used
  8739. * whenever a null data source is encountered (this can be because mData
  8740. * is set to null, or because the data source itself is null).
  8741. * @type string
  8742. * @default null
  8743. */
  8744. "sDefaultContent": null,
  8745. /**
  8746. * Name for the column, allowing reference to the column by name as well as
  8747. * by index (needs a lookup to work by name).
  8748. * @type string
  8749. */
  8750. "sName": null,
  8751. /**
  8752. * Custom sorting data type - defines which of the available plug-ins in
  8753. * afnSortData the custom sorting will use - if any is defined.
  8754. * @type string
  8755. * @default std
  8756. */
  8757. "sSortDataType": 'std',
  8758. /**
  8759. * Class to be applied to the header element when sorting on this column
  8760. * @type string
  8761. * @default null
  8762. */
  8763. "sSortingClass": null,
  8764. /**
  8765. * Class to be applied to the header element when sorting on this column -
  8766. * when jQuery UI theming is used.
  8767. * @type string
  8768. * @default null
  8769. */
  8770. "sSortingClassJUI": null,
  8771. /**
  8772. * Title of the column - what is seen in the TH element (nTh).
  8773. * @type string
  8774. */
  8775. "sTitle": null,
  8776. /**
  8777. * Column sorting and filtering type
  8778. * @type string
  8779. * @default null
  8780. */
  8781. "sType": null,
  8782. /**
  8783. * Width of the column
  8784. * @type string
  8785. * @default null
  8786. */
  8787. "sWidth": null,
  8788. /**
  8789. * Width of the column when it was first "encountered"
  8790. * @type string
  8791. * @default null
  8792. */
  8793. "sWidthOrig": null
  8794. };
  8795. /*
  8796. * Developer note: The properties of the object below are given in Hungarian
  8797. * notation, that was used as the interface for DataTables prior to v1.10, however
  8798. * from v1.10 onwards the primary interface is camel case. In order to avoid
  8799. * breaking backwards compatibility utterly with this change, the Hungarian
  8800. * version is still, internally the primary interface, but is is not documented
  8801. * - hence the @name tags in each doc comment. This allows a Javascript function
  8802. * to create a map from Hungarian notation to camel case (going the other direction
  8803. * would require each property to be listed, which would at around 3K to the size
  8804. * of DataTables, while this method is about a 0.5K hit.
  8805. *
  8806. * Ultimately this does pave the way for Hungarian notation to be dropped
  8807. * completely, but that is a massive amount of work and will break current
  8808. * installs (therefore is on-hold until v2).
  8809. */
  8810. /**
  8811. * Initialisation options that can be given to DataTables at initialisation
  8812. * time.
  8813. * @namespace
  8814. */
  8815. DataTable.defaults = {
  8816. /**
  8817. * An array of data to use for the table, passed in at initialisation which
  8818. * will be used in preference to any data which is already in the DOM. This is
  8819. * particularly useful for constructing tables purely in Javascript, for
  8820. * example with a custom Ajax call.
  8821. * @type array
  8822. * @default null
  8823. *
  8824. * @dtopt Option
  8825. * @name DataTable.defaults.data
  8826. *
  8827. * @example
  8828. * // Using a 2D array data source
  8829. * $(document).ready( function () {
  8830. * $('#example').dataTable( {
  8831. * "data": [
  8832. * ['Trident', 'Internet Explorer 4.0', 'Win 95+', 4, 'X'],
  8833. * ['Trident', 'Internet Explorer 5.0', 'Win 95+', 5, 'C'],
  8834. * ],
  8835. * "columns": [
  8836. * { "title": "Engine" },
  8837. * { "title": "Browser" },
  8838. * { "title": "Platform" },
  8839. * { "title": "Version" },
  8840. * { "title": "Grade" }
  8841. * ]
  8842. * } );
  8843. * } );
  8844. *
  8845. * @example
  8846. * // Using an array of objects as a data source (`data`)
  8847. * $(document).ready( function () {
  8848. * $('#example').dataTable( {
  8849. * "data": [
  8850. * {
  8851. * "engine": "Trident",
  8852. * "browser": "Internet Explorer 4.0",
  8853. * "platform": "Win 95+",
  8854. * "version": 4,
  8855. * "grade": "X"
  8856. * },
  8857. * {
  8858. * "engine": "Trident",
  8859. * "browser": "Internet Explorer 5.0",
  8860. * "platform": "Win 95+",
  8861. * "version": 5,
  8862. * "grade": "C"
  8863. * }
  8864. * ],
  8865. * "columns": [
  8866. * { "title": "Engine", "data": "engine" },
  8867. * { "title": "Browser", "data": "browser" },
  8868. * { "title": "Platform", "data": "platform" },
  8869. * { "title": "Version", "data": "version" },
  8870. * { "title": "Grade", "data": "grade" }
  8871. * ]
  8872. * } );
  8873. * } );
  8874. */
  8875. "aaData": null,
  8876. /**
  8877. * If ordering is enabled, then DataTables will perform a first pass sort on
  8878. * initialisation. You can define which column(s) the sort is performed
  8879. * upon, and the sorting direction, with this variable. The `sorting` array
  8880. * should contain an array for each column to be sorted initially containing
  8881. * the column's index and a direction string ('asc' or 'desc').
  8882. * @type array
  8883. * @default [[0,'asc']]
  8884. *
  8885. * @dtopt Option
  8886. * @name DataTable.defaults.order
  8887. *
  8888. * @example
  8889. * // Sort by 3rd column first, and then 4th column
  8890. * $(document).ready( function() {
  8891. * $('#example').dataTable( {
  8892. * "order": [[2,'asc'], [3,'desc']]
  8893. * } );
  8894. * } );
  8895. *
  8896. * // No initial sorting
  8897. * $(document).ready( function() {
  8898. * $('#example').dataTable( {
  8899. * "order": []
  8900. * } );
  8901. * } );
  8902. */
  8903. "aaSorting": [[0, 'asc']],
  8904. /**
  8905. * This parameter is basically identical to the `sorting` parameter, but
  8906. * cannot be overridden by user interaction with the table. What this means
  8907. * is that you could have a column (visible or hidden) which the sorting
  8908. * will always be forced on first - any sorting after that (from the user)
  8909. * will then be performed as required. This can be useful for grouping rows
  8910. * together.
  8911. * @type array
  8912. * @default null
  8913. *
  8914. * @dtopt Option
  8915. * @name DataTable.defaults.orderFixed
  8916. *
  8917. * @example
  8918. * $(document).ready( function() {
  8919. * $('#example').dataTable( {
  8920. * "orderFixed": [[0,'asc']]
  8921. * } );
  8922. * } )
  8923. */
  8924. "aaSortingFixed": [],
  8925. /**
  8926. * DataTables can be instructed to load data to display in the table from a
  8927. * Ajax source. This option defines how that Ajax call is made and where to.
  8928. *
  8929. * The `ajax` property has three different modes of operation, depending on
  8930. * how it is defined. These are:
  8931. *
  8932. * * `string` - Set the URL from where the data should be loaded from.
  8933. * * `object` - Define properties for `jQuery.ajax`.
  8934. * * `function` - Custom data get function
  8935. *
  8936. * `string`
  8937. * --------
  8938. *
  8939. * As a string, the `ajax` property simply defines the URL from which
  8940. * DataTables will load data.
  8941. *
  8942. * `object`
  8943. * --------
  8944. *
  8945. * As an object, the parameters in the object are passed to
  8946. * [jQuery.ajax](http://api.jquery.com/jQuery.ajax/) allowing fine control
  8947. * of the Ajax request. DataTables has a number of default parameters which
  8948. * you can override using this option. Please refer to the jQuery
  8949. * documentation for a full description of the options available, although
  8950. * the following parameters provide additional options in DataTables or
  8951. * require special consideration:
  8952. *
  8953. * * `data` - As with jQuery, `data` can be provided as an object, but it
  8954. * can also be used as a function to manipulate the data DataTables sends
  8955. * to the server. The function takes a single parameter, an object of
  8956. * parameters with the values that DataTables has readied for sending. An
  8957. * object may be returned which will be merged into the DataTables
  8958. * defaults, or you can add the items to the object that was passed in and
  8959. * not return anything from the function. This supersedes `fnServerParams`
  8960. * from DataTables 1.9-.
  8961. *
  8962. * * `dataSrc` - By default DataTables will look for the property `data` (or
  8963. * `aaData` for compatibility with DataTables 1.9-) when obtaining data
  8964. * from an Ajax source or for server-side processing - this parameter
  8965. * allows that property to be changed. You can use Javascript dotted
  8966. * object notation to get a data source for multiple levels of nesting, or
  8967. * it my be used as a function. As a function it takes a single parameter,
  8968. * the JSON returned from the server, which can be manipulated as
  8969. * required, with the returned value being that used by DataTables as the
  8970. * data source for the table. This supersedes `sAjaxDataProp` from
  8971. * DataTables 1.9-.
  8972. *
  8973. * * `success` - Should not be overridden it is used internally in
  8974. * DataTables. To manipulate / transform the data returned by the server
  8975. * use `ajax.dataSrc`, or use `ajax` as a function (see below).
  8976. *
  8977. * `function`
  8978. * ----------
  8979. *
  8980. * As a function, making the Ajax call is left up to yourself allowing
  8981. * complete control of the Ajax request. Indeed, if desired, a method other
  8982. * than Ajax could be used to obtain the required data, such as Web storage
  8983. * or an AIR database.
  8984. *
  8985. * The function is given four parameters and no return is required. The
  8986. * parameters are:
  8987. *
  8988. * 1. _object_ - Data to send to the server
  8989. * 2. _function_ - Callback function that must be executed when the required
  8990. * data has been obtained. That data should be passed into the callback
  8991. * as the only parameter
  8992. * 3. _object_ - DataTables settings object for the table
  8993. *
  8994. * Note that this supersedes `fnServerData` from DataTables 1.9-.
  8995. *
  8996. * @type string|object|function
  8997. * @default null
  8998. *
  8999. * @dtopt Option
  9000. * @name DataTable.defaults.ajax
  9001. * @since 1.10.0
  9002. *
  9003. * @example
  9004. * // Get JSON data from a file via Ajax.
  9005. * // Note DataTables expects data in the form `{ data: [ ...data... ] }` by default).
  9006. * $('#example').dataTable( {
  9007. * "ajax": "data.json"
  9008. * } );
  9009. *
  9010. * @example
  9011. * // Get JSON data from a file via Ajax, using `dataSrc` to change
  9012. * // `data` to `tableData` (i.e. `{ tableData: [ ...data... ] }`)
  9013. * $('#example').dataTable( {
  9014. * "ajax": {
  9015. * "url": "data.json",
  9016. * "dataSrc": "tableData"
  9017. * }
  9018. * } );
  9019. *
  9020. * @example
  9021. * // Get JSON data from a file via Ajax, using `dataSrc` to read data
  9022. * // from a plain array rather than an array in an object
  9023. * $('#example').dataTable( {
  9024. * "ajax": {
  9025. * "url": "data.json",
  9026. * "dataSrc": ""
  9027. * }
  9028. * } );
  9029. *
  9030. * @example
  9031. * // Manipulate the data returned from the server - add a link to data
  9032. * // (note this can, should, be done using `render` for the column - this
  9033. * // is just a simple example of how the data can be manipulated).
  9034. * $('#example').dataTable( {
  9035. * "ajax": {
  9036. * "url": "data.json",
  9037. * "dataSrc": function ( json ) {
  9038. * for ( var i=0, ien=json.length ; i<ien ; i++ ) {
  9039. * json[i][0] = '<a href="/message/'+json[i][0]+'>View message</a>';
  9040. * }
  9041. * return json;
  9042. * }
  9043. * }
  9044. * } );
  9045. *
  9046. * @example
  9047. * // Add data to the request
  9048. * $('#example').dataTable( {
  9049. * "ajax": {
  9050. * "url": "data.json",
  9051. * "data": function ( d ) {
  9052. * return {
  9053. * "extra_search": $('#extra').val()
  9054. * };
  9055. * }
  9056. * }
  9057. * } );
  9058. *
  9059. * @example
  9060. * // Send request as POST
  9061. * $('#example').dataTable( {
  9062. * "ajax": {
  9063. * "url": "data.json",
  9064. * "type": "POST"
  9065. * }
  9066. * } );
  9067. *
  9068. * @example
  9069. * // Get the data from localStorage (could interface with a form for
  9070. * // adding, editing and removing rows).
  9071. * $('#example').dataTable( {
  9072. * "ajax": function (data, callback, settings) {
  9073. * callback(
  9074. * JSON.parse( localStorage.getItem('dataTablesData') )
  9075. * );
  9076. * }
  9077. * } );
  9078. */
  9079. "ajax": null,
  9080. /**
  9081. * This parameter allows you to readily specify the entries in the length drop
  9082. * down menu that DataTables shows when pagination is enabled. It can be
  9083. * either a 1D array of options which will be used for both the displayed
  9084. * option and the value, or a 2D array which will use the array in the first
  9085. * position as the value, and the array in the second position as the
  9086. * displayed options (useful for language strings such as 'All').
  9087. *
  9088. * Note that the `pageLength` property will be automatically set to the
  9089. * first value given in this array, unless `pageLength` is also provided.
  9090. * @type array
  9091. * @default [ 10, 25, 50, 100 ]
  9092. *
  9093. * @dtopt Option
  9094. * @name DataTable.defaults.lengthMenu
  9095. *
  9096. * @example
  9097. * $(document).ready( function() {
  9098. * $('#example').dataTable( {
  9099. * "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
  9100. * } );
  9101. * } );
  9102. */
  9103. "aLengthMenu": [10, 25, 50, 100],
  9104. /**
  9105. * The `columns` option in the initialisation parameter allows you to define
  9106. * details about the way individual columns behave. For a full list of
  9107. * column options that can be set, please see
  9108. * {@link DataTable.defaults.column}. Note that if you use `columns` to
  9109. * define your columns, you must have an entry in the array for every single
  9110. * column that you have in your table (these can be null if you don't which
  9111. * to specify any options).
  9112. * @member
  9113. *
  9114. * @name DataTable.defaults.column
  9115. */
  9116. "aoColumns": null,
  9117. /**
  9118. * Very similar to `columns`, `columnDefs` allows you to target a specific
  9119. * column, multiple columns, or all columns, using the `targets` property of
  9120. * each object in the array. This allows great flexibility when creating
  9121. * tables, as the `columnDefs` arrays can be of any length, targeting the
  9122. * columns you specifically want. `columnDefs` may use any of the column
  9123. * options available: {@link DataTable.defaults.column}, but it _must_
  9124. * have `targets` defined in each object in the array. Values in the `targets`
  9125. * array may be:
  9126. * <ul>
  9127. * <li>a string - class name will be matched on the TH for the column</li>
  9128. * <li>0 or a positive integer - column index counting from the left</li>
  9129. * <li>a negative integer - column index counting from the right</li>
  9130. * <li>the string "_all" - all columns (i.e. assign a default)</li>
  9131. * </ul>
  9132. * @member
  9133. *
  9134. * @name DataTable.defaults.columnDefs
  9135. */
  9136. "aoColumnDefs": null,
  9137. /**
  9138. * Basically the same as `search`, this parameter defines the individual column
  9139. * filtering state at initialisation time. The array must be of the same size
  9140. * as the number of columns, and each element be an object with the parameters
  9141. * `search` and `escapeRegex` (the latter is optional). 'null' is also
  9142. * accepted and the default will be used.
  9143. * @type array
  9144. * @default []
  9145. *
  9146. * @dtopt Option
  9147. * @name DataTable.defaults.searchCols
  9148. *
  9149. * @example
  9150. * $(document).ready( function() {
  9151. * $('#example').dataTable( {
  9152. * "searchCols": [
  9153. * null,
  9154. * { "search": "My filter" },
  9155. * null,
  9156. * { "search": "^[0-9]", "escapeRegex": false }
  9157. * ]
  9158. * } );
  9159. * } )
  9160. */
  9161. "aoSearchCols": [],
  9162. /**
  9163. * An array of CSS classes that should be applied to displayed rows. This
  9164. * array may be of any length, and DataTables will apply each class
  9165. * sequentially, looping when required.
  9166. * @type array
  9167. * @default null <i>Will take the values determined by the `oClasses.stripe*`
  9168. * options</i>
  9169. *
  9170. * @dtopt Option
  9171. * @name DataTable.defaults.stripeClasses
  9172. *
  9173. * @example
  9174. * $(document).ready( function() {
  9175. * $('#example').dataTable( {
  9176. * "stripeClasses": [ 'strip1', 'strip2', 'strip3' ]
  9177. * } );
  9178. * } )
  9179. */
  9180. "asStripeClasses": null,
  9181. /**
  9182. * Enable or disable automatic column width calculation. This can be disabled
  9183. * as an optimisation (it takes some time to calculate the widths) if the
  9184. * tables widths are passed in using `columns`.
  9185. * @type boolean
  9186. * @default true
  9187. *
  9188. * @dtopt Features
  9189. * @name DataTable.defaults.autoWidth
  9190. *
  9191. * @example
  9192. * $(document).ready( function () {
  9193. * $('#example').dataTable( {
  9194. * "autoWidth": false
  9195. * } );
  9196. * } );
  9197. */
  9198. "bAutoWidth": true,
  9199. /**
  9200. * Deferred rendering can provide DataTables with a huge speed boost when you
  9201. * are using an Ajax or JS data source for the table. This option, when set to
  9202. * true, will cause DataTables to defer the creation of the table elements for
  9203. * each row until they are needed for a draw - saving a significant amount of
  9204. * time.
  9205. * @type boolean
  9206. * @default false
  9207. *
  9208. * @dtopt Features
  9209. * @name DataTable.defaults.deferRender
  9210. *
  9211. * @example
  9212. * $(document).ready( function() {
  9213. * $('#example').dataTable( {
  9214. * "ajax": "sources/arrays.txt",
  9215. * "deferRender": true
  9216. * } );
  9217. * } );
  9218. */
  9219. "bDeferRender": false,
  9220. /**
  9221. * Replace a DataTable which matches the given selector and replace it with
  9222. * one which has the properties of the new initialisation object passed. If no
  9223. * table matches the selector, then the new DataTable will be constructed as
  9224. * per normal.
  9225. * @type boolean
  9226. * @default false
  9227. *
  9228. * @dtopt Options
  9229. * @name DataTable.defaults.destroy
  9230. *
  9231. * @example
  9232. * $(document).ready( function() {
  9233. * $('#example').dataTable( {
  9234. * "srollY": "200px",
  9235. * "paginate": false
  9236. * } );
  9237. *
  9238. * // Some time later....
  9239. * $('#example').dataTable( {
  9240. * "filter": false,
  9241. * "destroy": true
  9242. * } );
  9243. * } );
  9244. */
  9245. "bDestroy": false,
  9246. /**
  9247. * Enable or disable filtering of data. Filtering in DataTables is "smart" in
  9248. * that it allows the end user to input multiple words (space separated) and
  9249. * will match a row containing those words, even if not in the order that was
  9250. * specified (this allow matching across multiple columns). Note that if you
  9251. * wish to use filtering in DataTables this must remain 'true' - to remove the
  9252. * default filtering input box and retain filtering abilities, please use
  9253. * {@link DataTable.defaults.dom}.
  9254. * @type boolean
  9255. * @default true
  9256. *
  9257. * @dtopt Features
  9258. * @name DataTable.defaults.searching
  9259. *
  9260. * @example
  9261. * $(document).ready( function () {
  9262. * $('#example').dataTable( {
  9263. * "searching": false
  9264. * } );
  9265. * } );
  9266. */
  9267. "bFilter": true,
  9268. /**
  9269. * Enable or disable the table information display. This shows information
  9270. * about the data that is currently visible on the page, including information
  9271. * about filtered data if that action is being performed.
  9272. * @type boolean
  9273. * @default true
  9274. *
  9275. * @dtopt Features
  9276. * @name DataTable.defaults.info
  9277. *
  9278. * @example
  9279. * $(document).ready( function () {
  9280. * $('#example').dataTable( {
  9281. * "info": false
  9282. * } );
  9283. * } );
  9284. */
  9285. "bInfo": true,
  9286. /**
  9287. * Allows the end user to select the size of a formatted page from a select
  9288. * menu (sizes are 10, 25, 50 and 100). Requires pagination (`paginate`).
  9289. * @type boolean
  9290. * @default true
  9291. *
  9292. * @dtopt Features
  9293. * @name DataTable.defaults.lengthChange
  9294. *
  9295. * @example
  9296. * $(document).ready( function () {
  9297. * $('#example').dataTable( {
  9298. * "lengthChange": false
  9299. * } );
  9300. * } );
  9301. */
  9302. "bLengthChange": true,
  9303. /**
  9304. * Enable or disable pagination.
  9305. * @type boolean
  9306. * @default true
  9307. *
  9308. * @dtopt Features
  9309. * @name DataTable.defaults.paging
  9310. *
  9311. * @example
  9312. * $(document).ready( function () {
  9313. * $('#example').dataTable( {
  9314. * "paging": false
  9315. * } );
  9316. * } );
  9317. */
  9318. "bPaginate": true,
  9319. /**
  9320. * Enable or disable the display of a 'processing' indicator when the table is
  9321. * being processed (e.g. a sort). This is particularly useful for tables with
  9322. * large amounts of data where it can take a noticeable amount of time to sort
  9323. * the entries.
  9324. * @type boolean
  9325. * @default false
  9326. *
  9327. * @dtopt Features
  9328. * @name DataTable.defaults.processing
  9329. *
  9330. * @example
  9331. * $(document).ready( function () {
  9332. * $('#example').dataTable( {
  9333. * "processing": true
  9334. * } );
  9335. * } );
  9336. */
  9337. "bProcessing": false,
  9338. /**
  9339. * Retrieve the DataTables object for the given selector. Note that if the
  9340. * table has already been initialised, this parameter will cause DataTables
  9341. * to simply return the object that has already been set up - it will not take
  9342. * account of any changes you might have made to the initialisation object
  9343. * passed to DataTables (setting this parameter to true is an acknowledgement
  9344. * that you understand this). `destroy` can be used to reinitialise a table if
  9345. * you need.
  9346. * @type boolean
  9347. * @default false
  9348. *
  9349. * @dtopt Options
  9350. * @name DataTable.defaults.retrieve
  9351. *
  9352. * @example
  9353. * $(document).ready( function() {
  9354. * initTable();
  9355. * tableActions();
  9356. * } );
  9357. *
  9358. * function initTable ()
  9359. * {
  9360. * return $('#example').dataTable( {
  9361. * "scrollY": "200px",
  9362. * "paginate": false,
  9363. * "retrieve": true
  9364. * } );
  9365. * }
  9366. *
  9367. * function tableActions ()
  9368. * {
  9369. * var table = initTable();
  9370. * // perform API operations with oTable
  9371. * }
  9372. */
  9373. "bRetrieve": false,
  9374. /**
  9375. * When vertical (y) scrolling is enabled, DataTables will force the height of
  9376. * the table's viewport to the given height at all times (useful for layout).
  9377. * However, this can look odd when filtering data down to a small data set,
  9378. * and the footer is left "floating" further down. This parameter (when
  9379. * enabled) will cause DataTables to collapse the table's viewport down when
  9380. * the result set will fit within the given Y height.
  9381. * @type boolean
  9382. * @default false
  9383. *
  9384. * @dtopt Options
  9385. * @name DataTable.defaults.scrollCollapse
  9386. *
  9387. * @example
  9388. * $(document).ready( function() {
  9389. * $('#example').dataTable( {
  9390. * "scrollY": "200",
  9391. * "scrollCollapse": true
  9392. * } );
  9393. * } );
  9394. */
  9395. "bScrollCollapse": false,
  9396. /**
  9397. * Configure DataTables to use server-side processing. Note that the
  9398. * `ajax` parameter must also be given in order to give DataTables a
  9399. * source to obtain the required data for each draw.
  9400. * @type boolean
  9401. * @default false
  9402. *
  9403. * @dtopt Features
  9404. * @dtopt Server-side
  9405. * @name DataTable.defaults.serverSide
  9406. *
  9407. * @example
  9408. * $(document).ready( function () {
  9409. * $('#example').dataTable( {
  9410. * "serverSide": true,
  9411. * "ajax": "xhr.php"
  9412. * } );
  9413. * } );
  9414. */
  9415. "bServerSide": false,
  9416. /**
  9417. * Enable or disable sorting of columns. Sorting of individual columns can be
  9418. * disabled by the `sortable` option for each column.
  9419. * @type boolean
  9420. * @default true
  9421. *
  9422. * @dtopt Features
  9423. * @name DataTable.defaults.ordering
  9424. *
  9425. * @example
  9426. * $(document).ready( function () {
  9427. * $('#example').dataTable( {
  9428. * "ordering": false
  9429. * } );
  9430. * } );
  9431. */
  9432. "bSort": true,
  9433. /**
  9434. * Enable or display DataTables' ability to sort multiple columns at the
  9435. * same time (activated by shift-click by the user).
  9436. * @type boolean
  9437. * @default true
  9438. *
  9439. * @dtopt Options
  9440. * @name DataTable.defaults.orderMulti
  9441. *
  9442. * @example
  9443. * // Disable multiple column sorting ability
  9444. * $(document).ready( function () {
  9445. * $('#example').dataTable( {
  9446. * "orderMulti": false
  9447. * } );
  9448. * } );
  9449. */
  9450. "bSortMulti": true,
  9451. /**
  9452. * Allows control over whether DataTables should use the top (true) unique
  9453. * cell that is found for a single column, or the bottom (false - default).
  9454. * This is useful when using complex headers.
  9455. * @type boolean
  9456. * @default false
  9457. *
  9458. * @dtopt Options
  9459. * @name DataTable.defaults.orderCellsTop
  9460. *
  9461. * @example
  9462. * $(document).ready( function() {
  9463. * $('#example').dataTable( {
  9464. * "orderCellsTop": true
  9465. * } );
  9466. * } );
  9467. */
  9468. "bSortCellsTop": false,
  9469. /**
  9470. * Enable or disable the addition of the classes `sorting\_1`, `sorting\_2` and
  9471. * `sorting\_3` to the columns which are currently being sorted on. This is
  9472. * presented as a feature switch as it can increase processing time (while
  9473. * classes are removed and added) so for large data sets you might want to
  9474. * turn this off.
  9475. * @type boolean
  9476. * @default true
  9477. *
  9478. * @dtopt Features
  9479. * @name DataTable.defaults.orderClasses
  9480. *
  9481. * @example
  9482. * $(document).ready( function () {
  9483. * $('#example').dataTable( {
  9484. * "orderClasses": false
  9485. * } );
  9486. * } );
  9487. */
  9488. "bSortClasses": true,
  9489. /**
  9490. * Enable or disable state saving. When enabled HTML5 `localStorage` will be
  9491. * used to save table display information such as pagination information,
  9492. * display length, filtering and sorting. As such when the end user reloads
  9493. * the page the display display will match what thy had previously set up.
  9494. *
  9495. * Due to the use of `localStorage` the default state saving is not supported
  9496. * in IE6 or 7. If state saving is required in those browsers, use
  9497. * `stateSaveCallback` to provide a storage solution such as cookies.
  9498. * @type boolean
  9499. * @default false
  9500. *
  9501. * @dtopt Features
  9502. * @name DataTable.defaults.stateSave
  9503. *
  9504. * @example
  9505. * $(document).ready( function () {
  9506. * $('#example').dataTable( {
  9507. * "stateSave": true
  9508. * } );
  9509. * } );
  9510. */
  9511. "bStateSave": false,
  9512. /**
  9513. * This function is called when a TR element is created (and all TD child
  9514. * elements have been inserted), or registered if using a DOM source, allowing
  9515. * manipulation of the TR element (adding classes etc).
  9516. * @type function
  9517. * @param {node} row "TR" element for the current row
  9518. * @param {array} data Raw data array for this row
  9519. * @param {int} dataIndex The index of this row in the internal aoData array
  9520. *
  9521. * @dtopt Callbacks
  9522. * @name DataTable.defaults.createdRow
  9523. *
  9524. * @example
  9525. * $(document).ready( function() {
  9526. * $('#example').dataTable( {
  9527. * "createdRow": function( row, data, dataIndex ) {
  9528. * // Bold the grade for all 'A' grade browsers
  9529. * if ( data[4] == "A" )
  9530. * {
  9531. * $('td:eq(4)', row).html( '<b>A</b>' );
  9532. * }
  9533. * }
  9534. * } );
  9535. * } );
  9536. */
  9537. "fnCreatedRow": null,
  9538. /**
  9539. * This function is called on every 'draw' event, and allows you to
  9540. * dynamically modify any aspect you want about the created DOM.
  9541. * @type function
  9542. * @param {object} settings DataTables settings object
  9543. *
  9544. * @dtopt Callbacks
  9545. * @name DataTable.defaults.drawCallback
  9546. *
  9547. * @example
  9548. * $(document).ready( function() {
  9549. * $('#example').dataTable( {
  9550. * "drawCallback": function( settings ) {
  9551. * alert( 'DataTables has redrawn the table' );
  9552. * }
  9553. * } );
  9554. * } );
  9555. */
  9556. "fnDrawCallback": null,
  9557. /**
  9558. * Identical to fnHeaderCallback() but for the table footer this function
  9559. * allows you to modify the table footer on every 'draw' event.
  9560. * @type function
  9561. * @param {node} foot "TR" element for the footer
  9562. * @param {array} data Full table data (as derived from the original HTML)
  9563. * @param {int} start Index for the current display starting point in the
  9564. * display array
  9565. * @param {int} end Index for the current display ending point in the
  9566. * display array
  9567. * @param {array int} display Index array to translate the visual position
  9568. * to the full data array
  9569. *
  9570. * @dtopt Callbacks
  9571. * @name DataTable.defaults.footerCallback
  9572. *
  9573. * @example
  9574. * $(document).ready( function() {
  9575. * $('#example').dataTable( {
  9576. * "footerCallback": function( tfoot, data, start, end, display ) {
  9577. * tfoot.getElementsByTagName('th')[0].innerHTML = "Starting index is "+start;
  9578. * }
  9579. * } );
  9580. * } )
  9581. */
  9582. "fnFooterCallback": null,
  9583. /**
  9584. * When rendering large numbers in the information element for the table
  9585. * (i.e. "Showing 1 to 10 of 57 entries") DataTables will render large numbers
  9586. * to have a comma separator for the 'thousands' units (e.g. 1 million is
  9587. * rendered as "1,000,000") to help readability for the end user. This
  9588. * function will override the default method DataTables uses.
  9589. * @type function
  9590. * @member
  9591. * @param {int} toFormat number to be formatted
  9592. * @returns {string} formatted string for DataTables to show the number
  9593. *
  9594. * @dtopt Callbacks
  9595. * @name DataTable.defaults.formatNumber
  9596. *
  9597. * @example
  9598. * // Format a number using a single quote for the separator (note that
  9599. * // this can also be done with the language.thousands option)
  9600. * $(document).ready( function() {
  9601. * $('#example').dataTable( {
  9602. * "formatNumber": function ( toFormat ) {
  9603. * return toFormat.toString().replace(
  9604. * /\B(?=(\d{3})+(?!\d))/g, "'"
  9605. * );
  9606. * };
  9607. * } );
  9608. * } );
  9609. */
  9610. "fnFormatNumber": function fnFormatNumber(toFormat) {
  9611. return toFormat.toString().replace(/\B(?=(\d{3})+(?!\d))/g, this.oLanguage.sThousands);
  9612. },
  9613. /**
  9614. * This function is called on every 'draw' event, and allows you to
  9615. * dynamically modify the header row. This can be used to calculate and
  9616. * display useful information about the table.
  9617. * @type function
  9618. * @param {node} head "TR" element for the header
  9619. * @param {array} data Full table data (as derived from the original HTML)
  9620. * @param {int} start Index for the current display starting point in the
  9621. * display array
  9622. * @param {int} end Index for the current display ending point in the
  9623. * display array
  9624. * @param {array int} display Index array to translate the visual position
  9625. * to the full data array
  9626. *
  9627. * @dtopt Callbacks
  9628. * @name DataTable.defaults.headerCallback
  9629. *
  9630. * @example
  9631. * $(document).ready( function() {
  9632. * $('#example').dataTable( {
  9633. * "fheaderCallback": function( head, data, start, end, display ) {
  9634. * head.getElementsByTagName('th')[0].innerHTML = "Displaying "+(end-start)+" records";
  9635. * }
  9636. * } );
  9637. * } )
  9638. */
  9639. "fnHeaderCallback": null,
  9640. /**
  9641. * The information element can be used to convey information about the current
  9642. * state of the table. Although the internationalisation options presented by
  9643. * DataTables are quite capable of dealing with most customisations, there may
  9644. * be times where you wish to customise the string further. This callback
  9645. * allows you to do exactly that.
  9646. * @type function
  9647. * @param {object} oSettings DataTables settings object
  9648. * @param {int} start Starting position in data for the draw
  9649. * @param {int} end End position in data for the draw
  9650. * @param {int} max Total number of rows in the table (regardless of
  9651. * filtering)
  9652. * @param {int} total Total number of rows in the data set, after filtering
  9653. * @param {string} pre The string that DataTables has formatted using it's
  9654. * own rules
  9655. * @returns {string} The string to be displayed in the information element.
  9656. *
  9657. * @dtopt Callbacks
  9658. * @name DataTable.defaults.infoCallback
  9659. *
  9660. * @example
  9661. * $('#example').dataTable( {
  9662. * "infoCallback": function( settings, start, end, max, total, pre ) {
  9663. * return start +" to "+ end;
  9664. * }
  9665. * } );
  9666. */
  9667. "fnInfoCallback": null,
  9668. /**
  9669. * Called when the table has been initialised. Normally DataTables will
  9670. * initialise sequentially and there will be no need for this function,
  9671. * however, this does not hold true when using external language information
  9672. * since that is obtained using an async XHR call.
  9673. * @type function
  9674. * @param {object} settings DataTables settings object
  9675. * @param {object} json The JSON object request from the server - only
  9676. * present if client-side Ajax sourced data is used
  9677. *
  9678. * @dtopt Callbacks
  9679. * @name DataTable.defaults.initComplete
  9680. *
  9681. * @example
  9682. * $(document).ready( function() {
  9683. * $('#example').dataTable( {
  9684. * "initComplete": function(settings, json) {
  9685. * alert( 'DataTables has finished its initialisation.' );
  9686. * }
  9687. * } );
  9688. * } )
  9689. */
  9690. "fnInitComplete": null,
  9691. /**
  9692. * Called at the very start of each table draw and can be used to cancel the
  9693. * draw by returning false, any other return (including undefined) results in
  9694. * the full draw occurring).
  9695. * @type function
  9696. * @param {object} settings DataTables settings object
  9697. * @returns {boolean} False will cancel the draw, anything else (including no
  9698. * return) will allow it to complete.
  9699. *
  9700. * @dtopt Callbacks
  9701. * @name DataTable.defaults.preDrawCallback
  9702. *
  9703. * @example
  9704. * $(document).ready( function() {
  9705. * $('#example').dataTable( {
  9706. * "preDrawCallback": function( settings ) {
  9707. * if ( $('#test').val() == 1 ) {
  9708. * return false;
  9709. * }
  9710. * }
  9711. * } );
  9712. * } );
  9713. */
  9714. "fnPreDrawCallback": null,
  9715. /**
  9716. * This function allows you to 'post process' each row after it have been
  9717. * generated for each table draw, but before it is rendered on screen. This
  9718. * function might be used for setting the row class name etc.
  9719. * @type function
  9720. * @param {node} row "TR" element for the current row
  9721. * @param {array} data Raw data array for this row
  9722. * @param {int} displayIndex The display index for the current table draw
  9723. * @param {int} displayIndexFull The index of the data in the full list of
  9724. * rows (after filtering)
  9725. *
  9726. * @dtopt Callbacks
  9727. * @name DataTable.defaults.rowCallback
  9728. *
  9729. * @example
  9730. * $(document).ready( function() {
  9731. * $('#example').dataTable( {
  9732. * "rowCallback": function( row, data, displayIndex, displayIndexFull ) {
  9733. * // Bold the grade for all 'A' grade browsers
  9734. * if ( data[4] == "A" ) {
  9735. * $('td:eq(4)', row).html( '<b>A</b>' );
  9736. * }
  9737. * }
  9738. * } );
  9739. * } );
  9740. */
  9741. "fnRowCallback": null,
  9742. /**
  9743. * __Deprecated__ The functionality provided by this parameter has now been
  9744. * superseded by that provided through `ajax`, which should be used instead.
  9745. *
  9746. * This parameter allows you to override the default function which obtains
  9747. * the data from the server so something more suitable for your application.
  9748. * For example you could use POST data, or pull information from a Gears or
  9749. * AIR database.
  9750. * @type function
  9751. * @member
  9752. * @param {string} source HTTP source to obtain the data from (`ajax`)
  9753. * @param {array} data A key/value pair object containing the data to send
  9754. * to the server
  9755. * @param {function} callback to be called on completion of the data get
  9756. * process that will draw the data on the page.
  9757. * @param {object} settings DataTables settings object
  9758. *
  9759. * @dtopt Callbacks
  9760. * @dtopt Server-side
  9761. * @name DataTable.defaults.serverData
  9762. *
  9763. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9764. */
  9765. "fnServerData": null,
  9766. /**
  9767. * __Deprecated__ The functionality provided by this parameter has now been
  9768. * superseded by that provided through `ajax`, which should be used instead.
  9769. *
  9770. * It is often useful to send extra data to the server when making an Ajax
  9771. * request - for example custom filtering information, and this callback
  9772. * function makes it trivial to send extra information to the server. The
  9773. * passed in parameter is the data set that has been constructed by
  9774. * DataTables, and you can add to this or modify it as you require.
  9775. * @type function
  9776. * @param {array} data Data array (array of objects which are name/value
  9777. * pairs) that has been constructed by DataTables and will be sent to the
  9778. * server. In the case of Ajax sourced data with server-side processing
  9779. * this will be an empty array, for server-side processing there will be a
  9780. * significant number of parameters!
  9781. * @returns {undefined} Ensure that you modify the data array passed in,
  9782. * as this is passed by reference.
  9783. *
  9784. * @dtopt Callbacks
  9785. * @dtopt Server-side
  9786. * @name DataTable.defaults.serverParams
  9787. *
  9788. * @deprecated 1.10. Please use `ajax` for this functionality now.
  9789. */
  9790. "fnServerParams": null,
  9791. /**
  9792. * Load the table state. With this function you can define from where, and how, the
  9793. * state of a table is loaded. By default DataTables will load from `localStorage`
  9794. * but you might wish to use a server-side database or cookies.
  9795. * @type function
  9796. * @member
  9797. * @param {object} settings DataTables settings object
  9798. * @param {object} callback Callback that can be executed when done. It
  9799. * should be passed the loaded state object.
  9800. * @return {object} The DataTables state object to be loaded
  9801. *
  9802. * @dtopt Callbacks
  9803. * @name DataTable.defaults.stateLoadCallback
  9804. *
  9805. * @example
  9806. * $(document).ready( function() {
  9807. * $('#example').dataTable( {
  9808. * "stateSave": true,
  9809. * "stateLoadCallback": function (settings, callback) {
  9810. * $.ajax( {
  9811. * "url": "/state_load",
  9812. * "dataType": "json",
  9813. * "success": function (json) {
  9814. * callback( json );
  9815. * }
  9816. * } );
  9817. * }
  9818. * } );
  9819. * } );
  9820. */
  9821. "fnStateLoadCallback": function fnStateLoadCallback(settings) {
  9822. try {
  9823. return JSON.parse((settings.iStateDuration === -1 ? sessionStorage : localStorage).getItem('DataTables_' + settings.sInstance + '_' + location.pathname));
  9824. } catch (e) {}
  9825. },
  9826. /**
  9827. * Callback which allows modification of the saved state prior to loading that state.
  9828. * This callback is called when the table is loading state from the stored data, but
  9829. * prior to the settings object being modified by the saved state. Note that for
  9830. * plug-in authors, you should use the `stateLoadParams` event to load parameters for
  9831. * a plug-in.
  9832. * @type function
  9833. * @param {object} settings DataTables settings object
  9834. * @param {object} data The state object that is to be loaded
  9835. *
  9836. * @dtopt Callbacks
  9837. * @name DataTable.defaults.stateLoadParams
  9838. *
  9839. * @example
  9840. * // Remove a saved filter, so filtering is never loaded
  9841. * $(document).ready( function() {
  9842. * $('#example').dataTable( {
  9843. * "stateSave": true,
  9844. * "stateLoadParams": function (settings, data) {
  9845. * data.oSearch.sSearch = "";
  9846. * }
  9847. * } );
  9848. * } );
  9849. *
  9850. * @example
  9851. * // Disallow state loading by returning false
  9852. * $(document).ready( function() {
  9853. * $('#example').dataTable( {
  9854. * "stateSave": true,
  9855. * "stateLoadParams": function (settings, data) {
  9856. * return false;
  9857. * }
  9858. * } );
  9859. * } );
  9860. */
  9861. "fnStateLoadParams": null,
  9862. /**
  9863. * Callback that is called when the state has been loaded from the state saving method
  9864. * and the DataTables settings object has been modified as a result of the loaded state.
  9865. * @type function
  9866. * @param {object} settings DataTables settings object
  9867. * @param {object} data The state object that was loaded
  9868. *
  9869. * @dtopt Callbacks
  9870. * @name DataTable.defaults.stateLoaded
  9871. *
  9872. * @example
  9873. * // Show an alert with the filtering value that was saved
  9874. * $(document).ready( function() {
  9875. * $('#example').dataTable( {
  9876. * "stateSave": true,
  9877. * "stateLoaded": function (settings, data) {
  9878. * alert( 'Saved filter was: '+data.oSearch.sSearch );
  9879. * }
  9880. * } );
  9881. * } );
  9882. */
  9883. "fnStateLoaded": null,
  9884. /**
  9885. * Save the table state. This function allows you to define where and how the state
  9886. * information for the table is stored By default DataTables will use `localStorage`
  9887. * but you might wish to use a server-side database or cookies.
  9888. * @type function
  9889. * @member
  9890. * @param {object} settings DataTables settings object
  9891. * @param {object} data The state object to be saved
  9892. *
  9893. * @dtopt Callbacks
  9894. * @name DataTable.defaults.stateSaveCallback
  9895. *
  9896. * @example
  9897. * $(document).ready( function() {
  9898. * $('#example').dataTable( {
  9899. * "stateSave": true,
  9900. * "stateSaveCallback": function (settings, data) {
  9901. * // Send an Ajax request to the server with the state object
  9902. * $.ajax( {
  9903. * "url": "/state_save",
  9904. * "data": data,
  9905. * "dataType": "json",
  9906. * "method": "POST"
  9907. * "success": function () {}
  9908. * } );
  9909. * }
  9910. * } );
  9911. * } );
  9912. */
  9913. "fnStateSaveCallback": function fnStateSaveCallback(settings, data) {
  9914. try {
  9915. (settings.iStateDuration === -1 ? sessionStorage : localStorage).setItem('DataTables_' + settings.sInstance + '_' + location.pathname, JSON.stringify(data));
  9916. } catch (e) {}
  9917. },
  9918. /**
  9919. * Callback which allows modification of the state to be saved. Called when the table
  9920. * has changed state a new state save is required. This method allows modification of
  9921. * the state saving object prior to actually doing the save, including addition or
  9922. * other state properties or modification. Note that for plug-in authors, you should
  9923. * use the `stateSaveParams` event to save parameters for a plug-in.
  9924. * @type function
  9925. * @param {object} settings DataTables settings object
  9926. * @param {object} data The state object to be saved
  9927. *
  9928. * @dtopt Callbacks
  9929. * @name DataTable.defaults.stateSaveParams
  9930. *
  9931. * @example
  9932. * // Remove a saved filter, so filtering is never saved
  9933. * $(document).ready( function() {
  9934. * $('#example').dataTable( {
  9935. * "stateSave": true,
  9936. * "stateSaveParams": function (settings, data) {
  9937. * data.oSearch.sSearch = "";
  9938. * }
  9939. * } );
  9940. * } );
  9941. */
  9942. "fnStateSaveParams": null,
  9943. /**
  9944. * Duration for which the saved state information is considered valid. After this period
  9945. * has elapsed the state will be returned to the default.
  9946. * Value is given in seconds.
  9947. * @type int
  9948. * @default 7200 <i>(2 hours)</i>
  9949. *
  9950. * @dtopt Options
  9951. * @name DataTable.defaults.stateDuration
  9952. *
  9953. * @example
  9954. * $(document).ready( function() {
  9955. * $('#example').dataTable( {
  9956. * "stateDuration": 60*60*24; // 1 day
  9957. * } );
  9958. * } )
  9959. */
  9960. "iStateDuration": 7200,
  9961. /**
  9962. * When enabled DataTables will not make a request to the server for the first
  9963. * page draw - rather it will use the data already on the page (no sorting etc
  9964. * will be applied to it), thus saving on an XHR at load time. `deferLoading`
  9965. * is used to indicate that deferred loading is required, but it is also used
  9966. * to tell DataTables how many records there are in the full table (allowing
  9967. * the information element and pagination to be displayed correctly). In the case
  9968. * where a filtering is applied to the table on initial load, this can be
  9969. * indicated by giving the parameter as an array, where the first element is
  9970. * the number of records available after filtering and the second element is the
  9971. * number of records without filtering (allowing the table information element
  9972. * to be shown correctly).
  9973. * @type int | array
  9974. * @default null
  9975. *
  9976. * @dtopt Options
  9977. * @name DataTable.defaults.deferLoading
  9978. *
  9979. * @example
  9980. * // 57 records available in the table, no filtering applied
  9981. * $(document).ready( function() {
  9982. * $('#example').dataTable( {
  9983. * "serverSide": true,
  9984. * "ajax": "scripts/server_processing.php",
  9985. * "deferLoading": 57
  9986. * } );
  9987. * } );
  9988. *
  9989. * @example
  9990. * // 57 records after filtering, 100 without filtering (an initial filter applied)
  9991. * $(document).ready( function() {
  9992. * $('#example').dataTable( {
  9993. * "serverSide": true,
  9994. * "ajax": "scripts/server_processing.php",
  9995. * "deferLoading": [ 57, 100 ],
  9996. * "search": {
  9997. * "search": "my_filter"
  9998. * }
  9999. * } );
  10000. * } );
  10001. */
  10002. "iDeferLoading": null,
  10003. /**
  10004. * Number of rows to display on a single page when using pagination. If
  10005. * feature enabled (`lengthChange`) then the end user will be able to override
  10006. * this to a custom setting using a pop-up menu.
  10007. * @type int
  10008. * @default 10
  10009. *
  10010. * @dtopt Options
  10011. * @name DataTable.defaults.pageLength
  10012. *
  10013. * @example
  10014. * $(document).ready( function() {
  10015. * $('#example').dataTable( {
  10016. * "pageLength": 50
  10017. * } );
  10018. * } )
  10019. */
  10020. "iDisplayLength": 10,
  10021. /**
  10022. * Define the starting point for data display when using DataTables with
  10023. * pagination. Note that this parameter is the number of records, rather than
  10024. * the page number, so if you have 10 records per page and want to start on
  10025. * the third page, it should be "20".
  10026. * @type int
  10027. * @default 0
  10028. *
  10029. * @dtopt Options
  10030. * @name DataTable.defaults.displayStart
  10031. *
  10032. * @example
  10033. * $(document).ready( function() {
  10034. * $('#example').dataTable( {
  10035. * "displayStart": 20
  10036. * } );
  10037. * } )
  10038. */
  10039. "iDisplayStart": 0,
  10040. /**
  10041. * By default DataTables allows keyboard navigation of the table (sorting, paging,
  10042. * and filtering) by adding a `tabindex` attribute to the required elements. This
  10043. * allows you to tab through the controls and press the enter key to activate them.
  10044. * The tabindex is default 0, meaning that the tab follows the flow of the document.
  10045. * You can overrule this using this parameter if you wish. Use a value of -1 to
  10046. * disable built-in keyboard navigation.
  10047. * @type int
  10048. * @default 0
  10049. *
  10050. * @dtopt Options
  10051. * @name DataTable.defaults.tabIndex
  10052. *
  10053. * @example
  10054. * $(document).ready( function() {
  10055. * $('#example').dataTable( {
  10056. * "tabIndex": 1
  10057. * } );
  10058. * } );
  10059. */
  10060. "iTabIndex": 0,
  10061. /**
  10062. * Classes that DataTables assigns to the various components and features
  10063. * that it adds to the HTML table. This allows classes to be configured
  10064. * during initialisation in addition to through the static
  10065. * {@link DataTable.ext.oStdClasses} object).
  10066. * @namespace
  10067. * @name DataTable.defaults.classes
  10068. */
  10069. "oClasses": {},
  10070. /**
  10071. * All strings that DataTables uses in the user interface that it creates
  10072. * are defined in this object, allowing you to modified them individually or
  10073. * completely replace them all as required.
  10074. * @namespace
  10075. * @name DataTable.defaults.language
  10076. */
  10077. "oLanguage": {
  10078. /**
  10079. * Strings that are used for WAI-ARIA labels and controls only (these are not
  10080. * actually visible on the page, but will be read by screenreaders, and thus
  10081. * must be internationalised as well).
  10082. * @namespace
  10083. * @name DataTable.defaults.language.aria
  10084. */
  10085. "oAria": {
  10086. /**
  10087. * ARIA label that is added to the table headers when the column may be
  10088. * sorted ascending by activing the column (click or return when focused).
  10089. * Note that the column header is prefixed to this string.
  10090. * @type string
  10091. * @default : activate to sort column ascending
  10092. *
  10093. * @dtopt Language
  10094. * @name DataTable.defaults.language.aria.sortAscending
  10095. *
  10096. * @example
  10097. * $(document).ready( function() {
  10098. * $('#example').dataTable( {
  10099. * "language": {
  10100. * "aria": {
  10101. * "sortAscending": " - click/return to sort ascending"
  10102. * }
  10103. * }
  10104. * } );
  10105. * } );
  10106. */
  10107. "sSortAscending": ": activate to sort column ascending",
  10108. /**
  10109. * ARIA label that is added to the table headers when the column may be
  10110. * sorted descending by activing the column (click or return when focused).
  10111. * Note that the column header is prefixed to this string.
  10112. * @type string
  10113. * @default : activate to sort column ascending
  10114. *
  10115. * @dtopt Language
  10116. * @name DataTable.defaults.language.aria.sortDescending
  10117. *
  10118. * @example
  10119. * $(document).ready( function() {
  10120. * $('#example').dataTable( {
  10121. * "language": {
  10122. * "aria": {
  10123. * "sortDescending": " - click/return to sort descending"
  10124. * }
  10125. * }
  10126. * } );
  10127. * } );
  10128. */
  10129. "sSortDescending": ": activate to sort column descending"
  10130. },
  10131. /**
  10132. * Pagination string used by DataTables for the built-in pagination
  10133. * control types.
  10134. * @namespace
  10135. * @name DataTable.defaults.language.paginate
  10136. */
  10137. "oPaginate": {
  10138. /**
  10139. * Text to use when using the 'full_numbers' type of pagination for the
  10140. * button to take the user to the first page.
  10141. * @type string
  10142. * @default First
  10143. *
  10144. * @dtopt Language
  10145. * @name DataTable.defaults.language.paginate.first
  10146. *
  10147. * @example
  10148. * $(document).ready( function() {
  10149. * $('#example').dataTable( {
  10150. * "language": {
  10151. * "paginate": {
  10152. * "first": "First page"
  10153. * }
  10154. * }
  10155. * } );
  10156. * } );
  10157. */
  10158. "sFirst": "First",
  10159. /**
  10160. * Text to use when using the 'full_numbers' type of pagination for the
  10161. * button to take the user to the last page.
  10162. * @type string
  10163. * @default Last
  10164. *
  10165. * @dtopt Language
  10166. * @name DataTable.defaults.language.paginate.last
  10167. *
  10168. * @example
  10169. * $(document).ready( function() {
  10170. * $('#example').dataTable( {
  10171. * "language": {
  10172. * "paginate": {
  10173. * "last": "Last page"
  10174. * }
  10175. * }
  10176. * } );
  10177. * } );
  10178. */
  10179. "sLast": "Last",
  10180. /**
  10181. * Text to use for the 'next' pagination button (to take the user to the
  10182. * next page).
  10183. * @type string
  10184. * @default Next
  10185. *
  10186. * @dtopt Language
  10187. * @name DataTable.defaults.language.paginate.next
  10188. *
  10189. * @example
  10190. * $(document).ready( function() {
  10191. * $('#example').dataTable( {
  10192. * "language": {
  10193. * "paginate": {
  10194. * "next": "Next page"
  10195. * }
  10196. * }
  10197. * } );
  10198. * } );
  10199. */
  10200. "sNext": "Next",
  10201. /**
  10202. * Text to use for the 'previous' pagination button (to take the user to
  10203. * the previous page).
  10204. * @type string
  10205. * @default Previous
  10206. *
  10207. * @dtopt Language
  10208. * @name DataTable.defaults.language.paginate.previous
  10209. *
  10210. * @example
  10211. * $(document).ready( function() {
  10212. * $('#example').dataTable( {
  10213. * "language": {
  10214. * "paginate": {
  10215. * "previous": "Previous page"
  10216. * }
  10217. * }
  10218. * } );
  10219. * } );
  10220. */
  10221. "sPrevious": "Previous"
  10222. },
  10223. /**
  10224. * This string is shown in preference to `zeroRecords` when the table is
  10225. * empty of data (regardless of filtering). Note that this is an optional
  10226. * parameter - if it is not given, the value of `zeroRecords` will be used
  10227. * instead (either the default or given value).
  10228. * @type string
  10229. * @default No data available in table
  10230. *
  10231. * @dtopt Language
  10232. * @name DataTable.defaults.language.emptyTable
  10233. *
  10234. * @example
  10235. * $(document).ready( function() {
  10236. * $('#example').dataTable( {
  10237. * "language": {
  10238. * "emptyTable": "No data available in table"
  10239. * }
  10240. * } );
  10241. * } );
  10242. */
  10243. "sEmptyTable": "No data available in table",
  10244. /**
  10245. * This string gives information to the end user about the information
  10246. * that is current on display on the page. The following tokens can be
  10247. * used in the string and will be dynamically replaced as the table
  10248. * display updates. This tokens can be placed anywhere in the string, or
  10249. * removed as needed by the language requires:
  10250. *
  10251. * * `\_START\_` - Display index of the first record on the current page
  10252. * * `\_END\_` - Display index of the last record on the current page
  10253. * * `\_TOTAL\_` - Number of records in the table after filtering
  10254. * * `\_MAX\_` - Number of records in the table without filtering
  10255. * * `\_PAGE\_` - Current page number
  10256. * * `\_PAGES\_` - Total number of pages of data in the table
  10257. *
  10258. * @type string
  10259. * @default Showing _START_ to _END_ of _TOTAL_ entries
  10260. *
  10261. * @dtopt Language
  10262. * @name DataTable.defaults.language.info
  10263. *
  10264. * @example
  10265. * $(document).ready( function() {
  10266. * $('#example').dataTable( {
  10267. * "language": {
  10268. * "info": "Showing page _PAGE_ of _PAGES_"
  10269. * }
  10270. * } );
  10271. * } );
  10272. */
  10273. "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
  10274. /**
  10275. * Display information string for when the table is empty. Typically the
  10276. * format of this string should match `info`.
  10277. * @type string
  10278. * @default Showing 0 to 0 of 0 entries
  10279. *
  10280. * @dtopt Language
  10281. * @name DataTable.defaults.language.infoEmpty
  10282. *
  10283. * @example
  10284. * $(document).ready( function() {
  10285. * $('#example').dataTable( {
  10286. * "language": {
  10287. * "infoEmpty": "No entries to show"
  10288. * }
  10289. * } );
  10290. * } );
  10291. */
  10292. "sInfoEmpty": "Showing 0 to 0 of 0 entries",
  10293. /**
  10294. * When a user filters the information in a table, this string is appended
  10295. * to the information (`info`) to give an idea of how strong the filtering
  10296. * is. The variable _MAX_ is dynamically updated.
  10297. * @type string
  10298. * @default (filtered from _MAX_ total entries)
  10299. *
  10300. * @dtopt Language
  10301. * @name DataTable.defaults.language.infoFiltered
  10302. *
  10303. * @example
  10304. * $(document).ready( function() {
  10305. * $('#example').dataTable( {
  10306. * "language": {
  10307. * "infoFiltered": " - filtering from _MAX_ records"
  10308. * }
  10309. * } );
  10310. * } );
  10311. */
  10312. "sInfoFiltered": "(filtered from _MAX_ total entries)",
  10313. /**
  10314. * If can be useful to append extra information to the info string at times,
  10315. * and this variable does exactly that. This information will be appended to
  10316. * the `info` (`infoEmpty` and `infoFiltered` in whatever combination they are
  10317. * being used) at all times.
  10318. * @type string
  10319. * @default <i>Empty string</i>
  10320. *
  10321. * @dtopt Language
  10322. * @name DataTable.defaults.language.infoPostFix
  10323. *
  10324. * @example
  10325. * $(document).ready( function() {
  10326. * $('#example').dataTable( {
  10327. * "language": {
  10328. * "infoPostFix": "All records shown are derived from real information."
  10329. * }
  10330. * } );
  10331. * } );
  10332. */
  10333. "sInfoPostFix": "",
  10334. /**
  10335. * This decimal place operator is a little different from the other
  10336. * language options since DataTables doesn't output floating point
  10337. * numbers, so it won't ever use this for display of a number. Rather,
  10338. * what this parameter does is modify the sort methods of the table so
  10339. * that numbers which are in a format which has a character other than
  10340. * a period (`.`) as a decimal place will be sorted numerically.
  10341. *
  10342. * Note that numbers with different decimal places cannot be shown in
  10343. * the same table and still be sortable, the table must be consistent.
  10344. * However, multiple different tables on the page can use different
  10345. * decimal place characters.
  10346. * @type string
  10347. * @default
  10348. *
  10349. * @dtopt Language
  10350. * @name DataTable.defaults.language.decimal
  10351. *
  10352. * @example
  10353. * $(document).ready( function() {
  10354. * $('#example').dataTable( {
  10355. * "language": {
  10356. * "decimal": ","
  10357. * "thousands": "."
  10358. * }
  10359. * } );
  10360. * } );
  10361. */
  10362. "sDecimal": "",
  10363. /**
  10364. * DataTables has a build in number formatter (`formatNumber`) which is
  10365. * used to format large numbers that are used in the table information.
  10366. * By default a comma is used, but this can be trivially changed to any
  10367. * character you wish with this parameter.
  10368. * @type string
  10369. * @default ,
  10370. *
  10371. * @dtopt Language
  10372. * @name DataTable.defaults.language.thousands
  10373. *
  10374. * @example
  10375. * $(document).ready( function() {
  10376. * $('#example').dataTable( {
  10377. * "language": {
  10378. * "thousands": "'"
  10379. * }
  10380. * } );
  10381. * } );
  10382. */
  10383. "sThousands": ",",
  10384. /**
  10385. * Detail the action that will be taken when the drop down menu for the
  10386. * pagination length option is changed. The '_MENU_' variable is replaced
  10387. * with a default select list of 10, 25, 50 and 100, and can be replaced
  10388. * with a custom select box if required.
  10389. * @type string
  10390. * @default Show _MENU_ entries
  10391. *
  10392. * @dtopt Language
  10393. * @name DataTable.defaults.language.lengthMenu
  10394. *
  10395. * @example
  10396. * // Language change only
  10397. * $(document).ready( function() {
  10398. * $('#example').dataTable( {
  10399. * "language": {
  10400. * "lengthMenu": "Display _MENU_ records"
  10401. * }
  10402. * } );
  10403. * } );
  10404. *
  10405. * @example
  10406. * // Language and options change
  10407. * $(document).ready( function() {
  10408. * $('#example').dataTable( {
  10409. * "language": {
  10410. * "lengthMenu": 'Display <select>'+
  10411. * '<option value="10">10</option>'+
  10412. * '<option value="20">20</option>'+
  10413. * '<option value="30">30</option>'+
  10414. * '<option value="40">40</option>'+
  10415. * '<option value="50">50</option>'+
  10416. * '<option value="-1">All</option>'+
  10417. * '</select> records'
  10418. * }
  10419. * } );
  10420. * } );
  10421. */
  10422. "sLengthMenu": "Show _MENU_ entries",
  10423. /**
  10424. * When using Ajax sourced data and during the first draw when DataTables is
  10425. * gathering the data, this message is shown in an empty row in the table to
  10426. * indicate to the end user the the data is being loaded. Note that this
  10427. * parameter is not used when loading data by server-side processing, just
  10428. * Ajax sourced data with client-side processing.
  10429. * @type string
  10430. * @default Loading...
  10431. *
  10432. * @dtopt Language
  10433. * @name DataTable.defaults.language.loadingRecords
  10434. *
  10435. * @example
  10436. * $(document).ready( function() {
  10437. * $('#example').dataTable( {
  10438. * "language": {
  10439. * "loadingRecords": "Please wait - loading..."
  10440. * }
  10441. * } );
  10442. * } );
  10443. */
  10444. "sLoadingRecords": "Loading...",
  10445. /**
  10446. * Text which is displayed when the table is processing a user action
  10447. * (usually a sort command or similar).
  10448. * @type string
  10449. * @default Processing...
  10450. *
  10451. * @dtopt Language
  10452. * @name DataTable.defaults.language.processing
  10453. *
  10454. * @example
  10455. * $(document).ready( function() {
  10456. * $('#example').dataTable( {
  10457. * "language": {
  10458. * "processing": "DataTables is currently busy"
  10459. * }
  10460. * } );
  10461. * } );
  10462. */
  10463. "sProcessing": "Processing...",
  10464. /**
  10465. * Details the actions that will be taken when the user types into the
  10466. * filtering input text box. The variable "_INPUT_", if used in the string,
  10467. * is replaced with the HTML text box for the filtering input allowing
  10468. * control over where it appears in the string. If "_INPUT_" is not given
  10469. * then the input box is appended to the string automatically.
  10470. * @type string
  10471. * @default Search:
  10472. *
  10473. * @dtopt Language
  10474. * @name DataTable.defaults.language.search
  10475. *
  10476. * @example
  10477. * // Input text box will be appended at the end automatically
  10478. * $(document).ready( function() {
  10479. * $('#example').dataTable( {
  10480. * "language": {
  10481. * "search": "Filter records:"
  10482. * }
  10483. * } );
  10484. * } );
  10485. *
  10486. * @example
  10487. * // Specify where the filter should appear
  10488. * $(document).ready( function() {
  10489. * $('#example').dataTable( {
  10490. * "language": {
  10491. * "search": "Apply filter _INPUT_ to table"
  10492. * }
  10493. * } );
  10494. * } );
  10495. */
  10496. "sSearch": "Search:",
  10497. /**
  10498. * Assign a `placeholder` attribute to the search `input` element
  10499. * @type string
  10500. * @default
  10501. *
  10502. * @dtopt Language
  10503. * @name DataTable.defaults.language.searchPlaceholder
  10504. */
  10505. "sSearchPlaceholder": "",
  10506. /**
  10507. * All of the language information can be stored in a file on the
  10508. * server-side, which DataTables will look up if this parameter is passed.
  10509. * It must store the URL of the language file, which is in a JSON format,
  10510. * and the object has the same properties as the oLanguage object in the
  10511. * initialiser object (i.e. the above parameters). Please refer to one of
  10512. * the example language files to see how this works in action.
  10513. * @type string
  10514. * @default <i>Empty string - i.e. disabled</i>
  10515. *
  10516. * @dtopt Language
  10517. * @name DataTable.defaults.language.url
  10518. *
  10519. * @example
  10520. * $(document).ready( function() {
  10521. * $('#example').dataTable( {
  10522. * "language": {
  10523. * "url": "http://www.sprymedia.co.uk/dataTables/lang.txt"
  10524. * }
  10525. * } );
  10526. * } );
  10527. */
  10528. "sUrl": "",
  10529. /**
  10530. * Text shown inside the table records when the is no information to be
  10531. * displayed after filtering. `emptyTable` is shown when there is simply no
  10532. * information in the table at all (regardless of filtering).
  10533. * @type string
  10534. * @default No matching records found
  10535. *
  10536. * @dtopt Language
  10537. * @name DataTable.defaults.language.zeroRecords
  10538. *
  10539. * @example
  10540. * $(document).ready( function() {
  10541. * $('#example').dataTable( {
  10542. * "language": {
  10543. * "zeroRecords": "No records to display"
  10544. * }
  10545. * } );
  10546. * } );
  10547. */
  10548. "sZeroRecords": "No matching records found"
  10549. },
  10550. /**
  10551. * This parameter allows you to have define the global filtering state at
  10552. * initialisation time. As an object the `search` parameter must be
  10553. * defined, but all other parameters are optional. When `regex` is true,
  10554. * the search string will be treated as a regular expression, when false
  10555. * (default) it will be treated as a straight string. When `smart`
  10556. * DataTables will use it's smart filtering methods (to word match at
  10557. * any point in the data), when false this will not be done.
  10558. * @namespace
  10559. * @extends DataTable.models.oSearch
  10560. *
  10561. * @dtopt Options
  10562. * @name DataTable.defaults.search
  10563. *
  10564. * @example
  10565. * $(document).ready( function() {
  10566. * $('#example').dataTable( {
  10567. * "search": {"search": "Initial search"}
  10568. * } );
  10569. * } )
  10570. */
  10571. "oSearch": $.extend({}, DataTable.models.oSearch),
  10572. /**
  10573. * __Deprecated__ The functionality provided by this parameter has now been
  10574. * superseded by that provided through `ajax`, which should be used instead.
  10575. *
  10576. * By default DataTables will look for the property `data` (or `aaData` for
  10577. * compatibility with DataTables 1.9-) when obtaining data from an Ajax
  10578. * source or for server-side processing - this parameter allows that
  10579. * property to be changed. You can use Javascript dotted object notation to
  10580. * get a data source for multiple levels of nesting.
  10581. * @type string
  10582. * @default data
  10583. *
  10584. * @dtopt Options
  10585. * @dtopt Server-side
  10586. * @name DataTable.defaults.ajaxDataProp
  10587. *
  10588. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10589. */
  10590. "sAjaxDataProp": "data",
  10591. /**
  10592. * __Deprecated__ The functionality provided by this parameter has now been
  10593. * superseded by that provided through `ajax`, which should be used instead.
  10594. *
  10595. * You can instruct DataTables to load data from an external
  10596. * source using this parameter (use aData if you want to pass data in you
  10597. * already have). Simply provide a url a JSON object can be obtained from.
  10598. * @type string
  10599. * @default null
  10600. *
  10601. * @dtopt Options
  10602. * @dtopt Server-side
  10603. * @name DataTable.defaults.ajaxSource
  10604. *
  10605. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10606. */
  10607. "sAjaxSource": null,
  10608. /**
  10609. * This initialisation variable allows you to specify exactly where in the
  10610. * DOM you want DataTables to inject the various controls it adds to the page
  10611. * (for example you might want the pagination controls at the top of the
  10612. * table). DIV elements (with or without a custom class) can also be added to
  10613. * aid styling. The follow syntax is used:
  10614. * <ul>
  10615. * <li>The following options are allowed:
  10616. * <ul>
  10617. * <li>'l' - Length changing</li>
  10618. * <li>'f' - Filtering input</li>
  10619. * <li>'t' - The table!</li>
  10620. * <li>'i' - Information</li>
  10621. * <li>'p' - Pagination</li>
  10622. * <li>'r' - pRocessing</li>
  10623. * </ul>
  10624. * </li>
  10625. * <li>The following constants are allowed:
  10626. * <ul>
  10627. * <li>'H' - jQueryUI theme "header" classes ('fg-toolbar ui-widget-header ui-corner-tl ui-corner-tr ui-helper-clearfix')</li>
  10628. * <li>'F' - jQueryUI theme "footer" classes ('fg-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix')</li>
  10629. * </ul>
  10630. * </li>
  10631. * <li>The following syntax is expected:
  10632. * <ul>
  10633. * <li>'&lt;' and '&gt;' - div elements</li>
  10634. * <li>'&lt;"class" and '&gt;' - div with a class</li>
  10635. * <li>'&lt;"#id" and '&gt;' - div with an ID</li>
  10636. * </ul>
  10637. * </li>
  10638. * <li>Examples:
  10639. * <ul>
  10640. * <li>'&lt;"wrapper"flipt&gt;'</li>
  10641. * <li>'&lt;lf&lt;t&gt;ip&gt;'</li>
  10642. * </ul>
  10643. * </li>
  10644. * </ul>
  10645. * @type string
  10646. * @default lfrtip <i>(when `jQueryUI` is false)</i> <b>or</b>
  10647. * <"H"lfr>t<"F"ip> <i>(when `jQueryUI` is true)</i>
  10648. *
  10649. * @dtopt Options
  10650. * @name DataTable.defaults.dom
  10651. *
  10652. * @example
  10653. * $(document).ready( function() {
  10654. * $('#example').dataTable( {
  10655. * "dom": '&lt;"top"i&gt;rt&lt;"bottom"flp&gt;&lt;"clear"&gt;'
  10656. * } );
  10657. * } );
  10658. */
  10659. "sDom": "lfrtip",
  10660. /**
  10661. * Search delay option. This will throttle full table searches that use the
  10662. * DataTables provided search input element (it does not effect calls to
  10663. * `dt-api search()`, providing a delay before the search is made.
  10664. * @type integer
  10665. * @default 0
  10666. *
  10667. * @dtopt Options
  10668. * @name DataTable.defaults.searchDelay
  10669. *
  10670. * @example
  10671. * $(document).ready( function() {
  10672. * $('#example').dataTable( {
  10673. * "searchDelay": 200
  10674. * } );
  10675. * } )
  10676. */
  10677. "searchDelay": null,
  10678. /**
  10679. * DataTables features six different built-in options for the buttons to
  10680. * display for pagination control:
  10681. *
  10682. * * `numbers` - Page number buttons only
  10683. * * `simple` - 'Previous' and 'Next' buttons only
  10684. * * 'simple_numbers` - 'Previous' and 'Next' buttons, plus page numbers
  10685. * * `full` - 'First', 'Previous', 'Next' and 'Last' buttons
  10686. * * `full_numbers` - 'First', 'Previous', 'Next' and 'Last' buttons, plus page numbers
  10687. * * `first_last_numbers` - 'First' and 'Last' buttons, plus page numbers
  10688. *
  10689. * Further methods can be added using {@link DataTable.ext.oPagination}.
  10690. * @type string
  10691. * @default simple_numbers
  10692. *
  10693. * @dtopt Options
  10694. * @name DataTable.defaults.pagingType
  10695. *
  10696. * @example
  10697. * $(document).ready( function() {
  10698. * $('#example').dataTable( {
  10699. * "pagingType": "full_numbers"
  10700. * } );
  10701. * } )
  10702. */
  10703. "sPaginationType": "simple_numbers",
  10704. /**
  10705. * Enable horizontal scrolling. When a table is too wide to fit into a
  10706. * certain layout, or you have a large number of columns in the table, you
  10707. * can enable x-scrolling to show the table in a viewport, which can be
  10708. * scrolled. This property can be `true` which will allow the table to
  10709. * scroll horizontally when needed, or any CSS unit, or a number (in which
  10710. * case it will be treated as a pixel measurement). Setting as simply `true`
  10711. * is recommended.
  10712. * @type boolean|string
  10713. * @default <i>blank string - i.e. disabled</i>
  10714. *
  10715. * @dtopt Features
  10716. * @name DataTable.defaults.scrollX
  10717. *
  10718. * @example
  10719. * $(document).ready( function() {
  10720. * $('#example').dataTable( {
  10721. * "scrollX": true,
  10722. * "scrollCollapse": true
  10723. * } );
  10724. * } );
  10725. */
  10726. "sScrollX": "",
  10727. /**
  10728. * This property can be used to force a DataTable to use more width than it
  10729. * might otherwise do when x-scrolling is enabled. For example if you have a
  10730. * table which requires to be well spaced, this parameter is useful for
  10731. * "over-sizing" the table, and thus forcing scrolling. This property can by
  10732. * any CSS unit, or a number (in which case it will be treated as a pixel
  10733. * measurement).
  10734. * @type string
  10735. * @default <i>blank string - i.e. disabled</i>
  10736. *
  10737. * @dtopt Options
  10738. * @name DataTable.defaults.scrollXInner
  10739. *
  10740. * @example
  10741. * $(document).ready( function() {
  10742. * $('#example').dataTable( {
  10743. * "scrollX": "100%",
  10744. * "scrollXInner": "110%"
  10745. * } );
  10746. * } );
  10747. */
  10748. "sScrollXInner": "",
  10749. /**
  10750. * Enable vertical scrolling. Vertical scrolling will constrain the DataTable
  10751. * to the given height, and enable scrolling for any data which overflows the
  10752. * current viewport. This can be used as an alternative to paging to display
  10753. * a lot of data in a small area (although paging and scrolling can both be
  10754. * enabled at the same time). This property can be any CSS unit, or a number
  10755. * (in which case it will be treated as a pixel measurement).
  10756. * @type string
  10757. * @default <i>blank string - i.e. disabled</i>
  10758. *
  10759. * @dtopt Features
  10760. * @name DataTable.defaults.scrollY
  10761. *
  10762. * @example
  10763. * $(document).ready( function() {
  10764. * $('#example').dataTable( {
  10765. * "scrollY": "200px",
  10766. * "paginate": false
  10767. * } );
  10768. * } );
  10769. */
  10770. "sScrollY": "",
  10771. /**
  10772. * __Deprecated__ The functionality provided by this parameter has now been
  10773. * superseded by that provided through `ajax`, which should be used instead.
  10774. *
  10775. * Set the HTTP method that is used to make the Ajax call for server-side
  10776. * processing or Ajax sourced data.
  10777. * @type string
  10778. * @default GET
  10779. *
  10780. * @dtopt Options
  10781. * @dtopt Server-side
  10782. * @name DataTable.defaults.serverMethod
  10783. *
  10784. * @deprecated 1.10. Please use `ajax` for this functionality now.
  10785. */
  10786. "sServerMethod": "GET",
  10787. /**
  10788. * DataTables makes use of renderers when displaying HTML elements for
  10789. * a table. These renderers can be added or modified by plug-ins to
  10790. * generate suitable mark-up for a site. For example the Bootstrap
  10791. * integration plug-in for DataTables uses a paging button renderer to
  10792. * display pagination buttons in the mark-up required by Bootstrap.
  10793. *
  10794. * For further information about the renderers available see
  10795. * DataTable.ext.renderer
  10796. * @type string|object
  10797. * @default null
  10798. *
  10799. * @name DataTable.defaults.renderer
  10800. *
  10801. */
  10802. "renderer": null,
  10803. /**
  10804. * Set the data property name that DataTables should use to get a row's id
  10805. * to set as the `id` property in the node.
  10806. * @type string
  10807. * @default DT_RowId
  10808. *
  10809. * @name DataTable.defaults.rowId
  10810. */
  10811. "rowId": "DT_RowId"
  10812. };
  10813. _fnHungarianMap(DataTable.defaults);
  10814. /*
  10815. * Developer note - See note in model.defaults.js about the use of Hungarian
  10816. * notation and camel case.
  10817. */
  10818. /**
  10819. * Column options that can be given to DataTables at initialisation time.
  10820. * @namespace
  10821. */
  10822. DataTable.defaults.column = {
  10823. /**
  10824. * Define which column(s) an order will occur on for this column. This
  10825. * allows a column's ordering to take multiple columns into account when
  10826. * doing a sort or use the data from a different column. For example first
  10827. * name / last name columns make sense to do a multi-column sort over the
  10828. * two columns.
  10829. * @type array|int
  10830. * @default null <i>Takes the value of the column index automatically</i>
  10831. *
  10832. * @name DataTable.defaults.column.orderData
  10833. * @dtopt Columns
  10834. *
  10835. * @example
  10836. * // Using `columnDefs`
  10837. * $(document).ready( function() {
  10838. * $('#example').dataTable( {
  10839. * "columnDefs": [
  10840. * { "orderData": [ 0, 1 ], "targets": [ 0 ] },
  10841. * { "orderData": [ 1, 0 ], "targets": [ 1 ] },
  10842. * { "orderData": 2, "targets": [ 2 ] }
  10843. * ]
  10844. * } );
  10845. * } );
  10846. *
  10847. * @example
  10848. * // Using `columns`
  10849. * $(document).ready( function() {
  10850. * $('#example').dataTable( {
  10851. * "columns": [
  10852. * { "orderData": [ 0, 1 ] },
  10853. * { "orderData": [ 1, 0 ] },
  10854. * { "orderData": 2 },
  10855. * null,
  10856. * null
  10857. * ]
  10858. * } );
  10859. * } );
  10860. */
  10861. "aDataSort": null,
  10862. "iDataSort": -1,
  10863. /**
  10864. * You can control the default ordering direction, and even alter the
  10865. * behaviour of the sort handler (i.e. only allow ascending ordering etc)
  10866. * using this parameter.
  10867. * @type array
  10868. * @default [ 'asc', 'desc' ]
  10869. *
  10870. * @name DataTable.defaults.column.orderSequence
  10871. * @dtopt Columns
  10872. *
  10873. * @example
  10874. * // Using `columnDefs`
  10875. * $(document).ready( function() {
  10876. * $('#example').dataTable( {
  10877. * "columnDefs": [
  10878. * { "orderSequence": [ "asc" ], "targets": [ 1 ] },
  10879. * { "orderSequence": [ "desc", "asc", "asc" ], "targets": [ 2 ] },
  10880. * { "orderSequence": [ "desc" ], "targets": [ 3 ] }
  10881. * ]
  10882. * } );
  10883. * } );
  10884. *
  10885. * @example
  10886. * // Using `columns`
  10887. * $(document).ready( function() {
  10888. * $('#example').dataTable( {
  10889. * "columns": [
  10890. * null,
  10891. * { "orderSequence": [ "asc" ] },
  10892. * { "orderSequence": [ "desc", "asc", "asc" ] },
  10893. * { "orderSequence": [ "desc" ] },
  10894. * null
  10895. * ]
  10896. * } );
  10897. * } );
  10898. */
  10899. "asSorting": ['asc', 'desc'],
  10900. /**
  10901. * Enable or disable filtering on the data in this column.
  10902. * @type boolean
  10903. * @default true
  10904. *
  10905. * @name DataTable.defaults.column.searchable
  10906. * @dtopt Columns
  10907. *
  10908. * @example
  10909. * // Using `columnDefs`
  10910. * $(document).ready( function() {
  10911. * $('#example').dataTable( {
  10912. * "columnDefs": [
  10913. * { "searchable": false, "targets": [ 0 ] }
  10914. * ] } );
  10915. * } );
  10916. *
  10917. * @example
  10918. * // Using `columns`
  10919. * $(document).ready( function() {
  10920. * $('#example').dataTable( {
  10921. * "columns": [
  10922. * { "searchable": false },
  10923. * null,
  10924. * null,
  10925. * null,
  10926. * null
  10927. * ] } );
  10928. * } );
  10929. */
  10930. "bSearchable": true,
  10931. /**
  10932. * Enable or disable ordering on this column.
  10933. * @type boolean
  10934. * @default true
  10935. *
  10936. * @name DataTable.defaults.column.orderable
  10937. * @dtopt Columns
  10938. *
  10939. * @example
  10940. * // Using `columnDefs`
  10941. * $(document).ready( function() {
  10942. * $('#example').dataTable( {
  10943. * "columnDefs": [
  10944. * { "orderable": false, "targets": [ 0 ] }
  10945. * ] } );
  10946. * } );
  10947. *
  10948. * @example
  10949. * // Using `columns`
  10950. * $(document).ready( function() {
  10951. * $('#example').dataTable( {
  10952. * "columns": [
  10953. * { "orderable": false },
  10954. * null,
  10955. * null,
  10956. * null,
  10957. * null
  10958. * ] } );
  10959. * } );
  10960. */
  10961. "bSortable": true,
  10962. /**
  10963. * Enable or disable the display of this column.
  10964. * @type boolean
  10965. * @default true
  10966. *
  10967. * @name DataTable.defaults.column.visible
  10968. * @dtopt Columns
  10969. *
  10970. * @example
  10971. * // Using `columnDefs`
  10972. * $(document).ready( function() {
  10973. * $('#example').dataTable( {
  10974. * "columnDefs": [
  10975. * { "visible": false, "targets": [ 0 ] }
  10976. * ] } );
  10977. * } );
  10978. *
  10979. * @example
  10980. * // Using `columns`
  10981. * $(document).ready( function() {
  10982. * $('#example').dataTable( {
  10983. * "columns": [
  10984. * { "visible": false },
  10985. * null,
  10986. * null,
  10987. * null,
  10988. * null
  10989. * ] } );
  10990. * } );
  10991. */
  10992. "bVisible": true,
  10993. /**
  10994. * Developer definable function that is called whenever a cell is created (Ajax source,
  10995. * etc) or processed for input (DOM source). This can be used as a compliment to mRender
  10996. * allowing you to modify the DOM element (add background colour for example) when the
  10997. * element is available.
  10998. * @type function
  10999. * @param {element} td The TD node that has been created
  11000. * @param {*} cellData The Data for the cell
  11001. * @param {array|object} rowData The data for the whole row
  11002. * @param {int} row The row index for the aoData data store
  11003. * @param {int} col The column index for aoColumns
  11004. *
  11005. * @name DataTable.defaults.column.createdCell
  11006. * @dtopt Columns
  11007. *
  11008. * @example
  11009. * $(document).ready( function() {
  11010. * $('#example').dataTable( {
  11011. * "columnDefs": [ {
  11012. * "targets": [3],
  11013. * "createdCell": function (td, cellData, rowData, row, col) {
  11014. * if ( cellData == "1.7" ) {
  11015. * $(td).css('color', 'blue')
  11016. * }
  11017. * }
  11018. * } ]
  11019. * });
  11020. * } );
  11021. */
  11022. "fnCreatedCell": null,
  11023. /**
  11024. * This parameter has been replaced by `data` in DataTables to ensure naming
  11025. * consistency. `dataProp` can still be used, as there is backwards
  11026. * compatibility in DataTables for this option, but it is strongly
  11027. * recommended that you use `data` in preference to `dataProp`.
  11028. * @name DataTable.defaults.column.dataProp
  11029. */
  11030. /**
  11031. * This property can be used to read data from any data source property,
  11032. * including deeply nested objects / properties. `data` can be given in a
  11033. * number of different ways which effect its behaviour:
  11034. *
  11035. * * `integer` - treated as an array index for the data source. This is the
  11036. * default that DataTables uses (incrementally increased for each column).
  11037. * * `string` - read an object property from the data source. There are
  11038. * three 'special' options that can be used in the string to alter how
  11039. * DataTables reads the data from the source object:
  11040. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  11041. * Javascript to read from nested objects, so to can the options
  11042. * specified in `data`. For example: `browser.version` or
  11043. * `browser.name`. If your object parameter name contains a period, use
  11044. * `\\` to escape it - i.e. `first\\.name`.
  11045. * * `[]` - Array notation. DataTables can automatically combine data
  11046. * from and array source, joining the data with the characters provided
  11047. * between the two brackets. For example: `name[, ]` would provide a
  11048. * comma-space separated list from the source array. If no characters
  11049. * are provided between the brackets, the original array source is
  11050. * returned.
  11051. * * `()` - Function notation. Adding `()` to the end of a parameter will
  11052. * execute a function of the name given. For example: `browser()` for a
  11053. * simple function on the data source, `browser.version()` for a
  11054. * function in a nested property or even `browser().version` to get an
  11055. * object property if the function called returns an object. Note that
  11056. * function notation is recommended for use in `render` rather than
  11057. * `data` as it is much simpler to use as a renderer.
  11058. * * `null` - use the original data source for the row rather than plucking
  11059. * data directly from it. This action has effects on two other
  11060. * initialisation options:
  11061. * * `defaultContent` - When null is given as the `data` option and
  11062. * `defaultContent` is specified for the column, the value defined by
  11063. * `defaultContent` will be used for the cell.
  11064. * * `render` - When null is used for the `data` option and the `render`
  11065. * option is specified for the column, the whole data source for the
  11066. * row is used for the renderer.
  11067. * * `function` - the function given will be executed whenever DataTables
  11068. * needs to set or get the data for a cell in the column. The function
  11069. * takes three parameters:
  11070. * * Parameters:
  11071. * * `{array|object}` The data source for the row
  11072. * * `{string}` The type call data requested - this will be 'set' when
  11073. * setting data or 'filter', 'display', 'type', 'sort' or undefined
  11074. * when gathering data. Note that when `undefined` is given for the
  11075. * type DataTables expects to get the raw data for the object back<
  11076. * * `{*}` Data to set when the second parameter is 'set'.
  11077. * * Return:
  11078. * * The return value from the function is not required when 'set' is
  11079. * the type of call, but otherwise the return is what will be used
  11080. * for the data requested.
  11081. *
  11082. * Note that `data` is a getter and setter option. If you just require
  11083. * formatting of data for output, you will likely want to use `render` which
  11084. * is simply a getter and thus simpler to use.
  11085. *
  11086. * Note that prior to DataTables 1.9.2 `data` was called `mDataProp`. The
  11087. * name change reflects the flexibility of this property and is consistent
  11088. * with the naming of mRender. If 'mDataProp' is given, then it will still
  11089. * be used by DataTables, as it automatically maps the old name to the new
  11090. * if required.
  11091. *
  11092. * @type string|int|function|null
  11093. * @default null <i>Use automatically calculated column index</i>
  11094. *
  11095. * @name DataTable.defaults.column.data
  11096. * @dtopt Columns
  11097. *
  11098. * @example
  11099. * // Read table data from objects
  11100. * // JSON structure for each row:
  11101. * // {
  11102. * // "engine": {value},
  11103. * // "browser": {value},
  11104. * // "platform": {value},
  11105. * // "version": {value},
  11106. * // "grade": {value}
  11107. * // }
  11108. * $(document).ready( function() {
  11109. * $('#example').dataTable( {
  11110. * "ajaxSource": "sources/objects.txt",
  11111. * "columns": [
  11112. * { "data": "engine" },
  11113. * { "data": "browser" },
  11114. * { "data": "platform" },
  11115. * { "data": "version" },
  11116. * { "data": "grade" }
  11117. * ]
  11118. * } );
  11119. * } );
  11120. *
  11121. * @example
  11122. * // Read information from deeply nested objects
  11123. * // JSON structure for each row:
  11124. * // {
  11125. * // "engine": {value},
  11126. * // "browser": {value},
  11127. * // "platform": {
  11128. * // "inner": {value}
  11129. * // },
  11130. * // "details": [
  11131. * // {value}, {value}
  11132. * // ]
  11133. * // }
  11134. * $(document).ready( function() {
  11135. * $('#example').dataTable( {
  11136. * "ajaxSource": "sources/deep.txt",
  11137. * "columns": [
  11138. * { "data": "engine" },
  11139. * { "data": "browser" },
  11140. * { "data": "platform.inner" },
  11141. * { "data": "platform.details.0" },
  11142. * { "data": "platform.details.1" }
  11143. * ]
  11144. * } );
  11145. * } );
  11146. *
  11147. * @example
  11148. * // Using `data` as a function to provide different information for
  11149. * // sorting, filtering and display. In this case, currency (price)
  11150. * $(document).ready( function() {
  11151. * $('#example').dataTable( {
  11152. * "columnDefs": [ {
  11153. * "targets": [ 0 ],
  11154. * "data": function ( source, type, val ) {
  11155. * if (type === 'set') {
  11156. * source.price = val;
  11157. * // Store the computed dislay and filter values for efficiency
  11158. * source.price_display = val=="" ? "" : "$"+numberFormat(val);
  11159. * source.price_filter = val=="" ? "" : "$"+numberFormat(val)+" "+val;
  11160. * return;
  11161. * }
  11162. * else if (type === 'display') {
  11163. * return source.price_display;
  11164. * }
  11165. * else if (type === 'filter') {
  11166. * return source.price_filter;
  11167. * }
  11168. * // 'sort', 'type' and undefined all just use the integer
  11169. * return source.price;
  11170. * }
  11171. * } ]
  11172. * } );
  11173. * } );
  11174. *
  11175. * @example
  11176. * // Using default content
  11177. * $(document).ready( function() {
  11178. * $('#example').dataTable( {
  11179. * "columnDefs": [ {
  11180. * "targets": [ 0 ],
  11181. * "data": null,
  11182. * "defaultContent": "Click to edit"
  11183. * } ]
  11184. * } );
  11185. * } );
  11186. *
  11187. * @example
  11188. * // Using array notation - outputting a list from an array
  11189. * $(document).ready( function() {
  11190. * $('#example').dataTable( {
  11191. * "columnDefs": [ {
  11192. * "targets": [ 0 ],
  11193. * "data": "name[, ]"
  11194. * } ]
  11195. * } );
  11196. * } );
  11197. *
  11198. */
  11199. "mData": null,
  11200. /**
  11201. * This property is the rendering partner to `data` and it is suggested that
  11202. * when you want to manipulate data for display (including filtering,
  11203. * sorting etc) without altering the underlying data for the table, use this
  11204. * property. `render` can be considered to be the the read only companion to
  11205. * `data` which is read / write (then as such more complex). Like `data`
  11206. * this option can be given in a number of different ways to effect its
  11207. * behaviour:
  11208. *
  11209. * * `integer` - treated as an array index for the data source. This is the
  11210. * default that DataTables uses (incrementally increased for each column).
  11211. * * `string` - read an object property from the data source. There are
  11212. * three 'special' options that can be used in the string to alter how
  11213. * DataTables reads the data from the source object:
  11214. * * `.` - Dotted Javascript notation. Just as you use a `.` in
  11215. * Javascript to read from nested objects, so to can the options
  11216. * specified in `data`. For example: `browser.version` or
  11217. * `browser.name`. If your object parameter name contains a period, use
  11218. * `\\` to escape it - i.e. `first\\.name`.
  11219. * * `[]` - Array notation. DataTables can automatically combine data
  11220. * from and array source, joining the data with the characters provided
  11221. * between the two brackets. For example: `name[, ]` would provide a
  11222. * comma-space separated list from the source array. If no characters
  11223. * are provided between the brackets, the original array source is
  11224. * returned.
  11225. * * `()` - Function notation. Adding `()` to the end of a parameter will
  11226. * execute a function of the name given. For example: `browser()` for a
  11227. * simple function on the data source, `browser.version()` for a
  11228. * function in a nested property or even `browser().version` to get an
  11229. * object property if the function called returns an object.
  11230. * * `object` - use different data for the different data types requested by
  11231. * DataTables ('filter', 'display', 'type' or 'sort'). The property names
  11232. * of the object is the data type the property refers to and the value can
  11233. * defined using an integer, string or function using the same rules as
  11234. * `render` normally does. Note that an `_` option _must_ be specified.
  11235. * This is the default value to use if you haven't specified a value for
  11236. * the data type requested by DataTables.
  11237. * * `function` - the function given will be executed whenever DataTables
  11238. * needs to set or get the data for a cell in the column. The function
  11239. * takes three parameters:
  11240. * * Parameters:
  11241. * * {array|object} The data source for the row (based on `data`)
  11242. * * {string} The type call data requested - this will be 'filter',
  11243. * 'display', 'type' or 'sort'.
  11244. * * {array|object} The full data source for the row (not based on
  11245. * `data`)
  11246. * * Return:
  11247. * * The return value from the function is what will be used for the
  11248. * data requested.
  11249. *
  11250. * @type string|int|function|object|null
  11251. * @default null Use the data source value.
  11252. *
  11253. * @name DataTable.defaults.column.render
  11254. * @dtopt Columns
  11255. *
  11256. * @example
  11257. * // Create a comma separated list from an array of objects
  11258. * $(document).ready( function() {
  11259. * $('#example').dataTable( {
  11260. * "ajaxSource": "sources/deep.txt",
  11261. * "columns": [
  11262. * { "data": "engine" },
  11263. * { "data": "browser" },
  11264. * {
  11265. * "data": "platform",
  11266. * "render": "[, ].name"
  11267. * }
  11268. * ]
  11269. * } );
  11270. * } );
  11271. *
  11272. * @example
  11273. * // Execute a function to obtain data
  11274. * $(document).ready( function() {
  11275. * $('#example').dataTable( {
  11276. * "columnDefs": [ {
  11277. * "targets": [ 0 ],
  11278. * "data": null, // Use the full data source object for the renderer's source
  11279. * "render": "browserName()"
  11280. * } ]
  11281. * } );
  11282. * } );
  11283. *
  11284. * @example
  11285. * // As an object, extracting different data for the different types
  11286. * // This would be used with a data source such as:
  11287. * // { "phone": 5552368, "phone_filter": "5552368 555-2368", "phone_display": "555-2368" }
  11288. * // Here the `phone` integer is used for sorting and type detection, while `phone_filter`
  11289. * // (which has both forms) is used for filtering for if a user inputs either format, while
  11290. * // the formatted phone number is the one that is shown in the table.
  11291. * $(document).ready( function() {
  11292. * $('#example').dataTable( {
  11293. * "columnDefs": [ {
  11294. * "targets": [ 0 ],
  11295. * "data": null, // Use the full data source object for the renderer's source
  11296. * "render": {
  11297. * "_": "phone",
  11298. * "filter": "phone_filter",
  11299. * "display": "phone_display"
  11300. * }
  11301. * } ]
  11302. * } );
  11303. * } );
  11304. *
  11305. * @example
  11306. * // Use as a function to create a link from the data source
  11307. * $(document).ready( function() {
  11308. * $('#example').dataTable( {
  11309. * "columnDefs": [ {
  11310. * "targets": [ 0 ],
  11311. * "data": "download_link",
  11312. * "render": function ( data, type, full ) {
  11313. * return '<a href="'+data+'">Download</a>';
  11314. * }
  11315. * } ]
  11316. * } );
  11317. * } );
  11318. */
  11319. "mRender": null,
  11320. /**
  11321. * Change the cell type created for the column - either TD cells or TH cells. This
  11322. * can be useful as TH cells have semantic meaning in the table body, allowing them
  11323. * to act as a header for a row (you may wish to add scope='row' to the TH elements).
  11324. * @type string
  11325. * @default td
  11326. *
  11327. * @name DataTable.defaults.column.cellType
  11328. * @dtopt Columns
  11329. *
  11330. * @example
  11331. * // Make the first column use TH cells
  11332. * $(document).ready( function() {
  11333. * $('#example').dataTable( {
  11334. * "columnDefs": [ {
  11335. * "targets": [ 0 ],
  11336. * "cellType": "th"
  11337. * } ]
  11338. * } );
  11339. * } );
  11340. */
  11341. "sCellType": "td",
  11342. /**
  11343. * Class to give to each cell in this column.
  11344. * @type string
  11345. * @default <i>Empty string</i>
  11346. *
  11347. * @name DataTable.defaults.column.class
  11348. * @dtopt Columns
  11349. *
  11350. * @example
  11351. * // Using `columnDefs`
  11352. * $(document).ready( function() {
  11353. * $('#example').dataTable( {
  11354. * "columnDefs": [
  11355. * { "class": "my_class", "targets": [ 0 ] }
  11356. * ]
  11357. * } );
  11358. * } );
  11359. *
  11360. * @example
  11361. * // Using `columns`
  11362. * $(document).ready( function() {
  11363. * $('#example').dataTable( {
  11364. * "columns": [
  11365. * { "class": "my_class" },
  11366. * null,
  11367. * null,
  11368. * null,
  11369. * null
  11370. * ]
  11371. * } );
  11372. * } );
  11373. */
  11374. "sClass": "",
  11375. /**
  11376. * When DataTables calculates the column widths to assign to each column,
  11377. * it finds the longest string in each column and then constructs a
  11378. * temporary table and reads the widths from that. The problem with this
  11379. * is that "mmm" is much wider then "iiii", but the latter is a longer
  11380. * string - thus the calculation can go wrong (doing it properly and putting
  11381. * it into an DOM object and measuring that is horribly(!) slow). Thus as
  11382. * a "work around" we provide this option. It will append its value to the
  11383. * text that is found to be the longest string for the column - i.e. padding.
  11384. * Generally you shouldn't need this!
  11385. * @type string
  11386. * @default <i>Empty string<i>
  11387. *
  11388. * @name DataTable.defaults.column.contentPadding
  11389. * @dtopt Columns
  11390. *
  11391. * @example
  11392. * // Using `columns`
  11393. * $(document).ready( function() {
  11394. * $('#example').dataTable( {
  11395. * "columns": [
  11396. * null,
  11397. * null,
  11398. * null,
  11399. * {
  11400. * "contentPadding": "mmm"
  11401. * }
  11402. * ]
  11403. * } );
  11404. * } );
  11405. */
  11406. "sContentPadding": "",
  11407. /**
  11408. * Allows a default value to be given for a column's data, and will be used
  11409. * whenever a null data source is encountered (this can be because `data`
  11410. * is set to null, or because the data source itself is null).
  11411. * @type string
  11412. * @default null
  11413. *
  11414. * @name DataTable.defaults.column.defaultContent
  11415. * @dtopt Columns
  11416. *
  11417. * @example
  11418. * // Using `columnDefs`
  11419. * $(document).ready( function() {
  11420. * $('#example').dataTable( {
  11421. * "columnDefs": [
  11422. * {
  11423. * "data": null,
  11424. * "defaultContent": "Edit",
  11425. * "targets": [ -1 ]
  11426. * }
  11427. * ]
  11428. * } );
  11429. * } );
  11430. *
  11431. * @example
  11432. * // Using `columns`
  11433. * $(document).ready( function() {
  11434. * $('#example').dataTable( {
  11435. * "columns": [
  11436. * null,
  11437. * null,
  11438. * null,
  11439. * {
  11440. * "data": null,
  11441. * "defaultContent": "Edit"
  11442. * }
  11443. * ]
  11444. * } );
  11445. * } );
  11446. */
  11447. "sDefaultContent": null,
  11448. /**
  11449. * This parameter is only used in DataTables' server-side processing. It can
  11450. * be exceptionally useful to know what columns are being displayed on the
  11451. * client side, and to map these to database fields. When defined, the names
  11452. * also allow DataTables to reorder information from the server if it comes
  11453. * back in an unexpected order (i.e. if you switch your columns around on the
  11454. * client-side, your server-side code does not also need updating).
  11455. * @type string
  11456. * @default <i>Empty string</i>
  11457. *
  11458. * @name DataTable.defaults.column.name
  11459. * @dtopt Columns
  11460. *
  11461. * @example
  11462. * // Using `columnDefs`
  11463. * $(document).ready( function() {
  11464. * $('#example').dataTable( {
  11465. * "columnDefs": [
  11466. * { "name": "engine", "targets": [ 0 ] },
  11467. * { "name": "browser", "targets": [ 1 ] },
  11468. * { "name": "platform", "targets": [ 2 ] },
  11469. * { "name": "version", "targets": [ 3 ] },
  11470. * { "name": "grade", "targets": [ 4 ] }
  11471. * ]
  11472. * } );
  11473. * } );
  11474. *
  11475. * @example
  11476. * // Using `columns`
  11477. * $(document).ready( function() {
  11478. * $('#example').dataTable( {
  11479. * "columns": [
  11480. * { "name": "engine" },
  11481. * { "name": "browser" },
  11482. * { "name": "platform" },
  11483. * { "name": "version" },
  11484. * { "name": "grade" }
  11485. * ]
  11486. * } );
  11487. * } );
  11488. */
  11489. "sName": "",
  11490. /**
  11491. * Defines a data source type for the ordering which can be used to read
  11492. * real-time information from the table (updating the internally cached
  11493. * version) prior to ordering. This allows ordering to occur on user
  11494. * editable elements such as form inputs.
  11495. * @type string
  11496. * @default std
  11497. *
  11498. * @name DataTable.defaults.column.orderDataType
  11499. * @dtopt Columns
  11500. *
  11501. * @example
  11502. * // Using `columnDefs`
  11503. * $(document).ready( function() {
  11504. * $('#example').dataTable( {
  11505. * "columnDefs": [
  11506. * { "orderDataType": "dom-text", "targets": [ 2, 3 ] },
  11507. * { "type": "numeric", "targets": [ 3 ] },
  11508. * { "orderDataType": "dom-select", "targets": [ 4 ] },
  11509. * { "orderDataType": "dom-checkbox", "targets": [ 5 ] }
  11510. * ]
  11511. * } );
  11512. * } );
  11513. *
  11514. * @example
  11515. * // Using `columns`
  11516. * $(document).ready( function() {
  11517. * $('#example').dataTable( {
  11518. * "columns": [
  11519. * null,
  11520. * null,
  11521. * { "orderDataType": "dom-text" },
  11522. * { "orderDataType": "dom-text", "type": "numeric" },
  11523. * { "orderDataType": "dom-select" },
  11524. * { "orderDataType": "dom-checkbox" }
  11525. * ]
  11526. * } );
  11527. * } );
  11528. */
  11529. "sSortDataType": "std",
  11530. /**
  11531. * The title of this column.
  11532. * @type string
  11533. * @default null <i>Derived from the 'TH' value for this column in the
  11534. * original HTML table.</i>
  11535. *
  11536. * @name DataTable.defaults.column.title
  11537. * @dtopt Columns
  11538. *
  11539. * @example
  11540. * // Using `columnDefs`
  11541. * $(document).ready( function() {
  11542. * $('#example').dataTable( {
  11543. * "columnDefs": [
  11544. * { "title": "My column title", "targets": [ 0 ] }
  11545. * ]
  11546. * } );
  11547. * } );
  11548. *
  11549. * @example
  11550. * // Using `columns`
  11551. * $(document).ready( function() {
  11552. * $('#example').dataTable( {
  11553. * "columns": [
  11554. * { "title": "My column title" },
  11555. * null,
  11556. * null,
  11557. * null,
  11558. * null
  11559. * ]
  11560. * } );
  11561. * } );
  11562. */
  11563. "sTitle": null,
  11564. /**
  11565. * The type allows you to specify how the data for this column will be
  11566. * ordered. Four types (string, numeric, date and html (which will strip
  11567. * HTML tags before ordering)) are currently available. Note that only date
  11568. * formats understood by Javascript's Date() object will be accepted as type
  11569. * date. For example: "Mar 26, 2008 5:03 PM". May take the values: 'string',
  11570. * 'numeric', 'date' or 'html' (by default). Further types can be adding
  11571. * through plug-ins.
  11572. * @type string
  11573. * @default null <i>Auto-detected from raw data</i>
  11574. *
  11575. * @name DataTable.defaults.column.type
  11576. * @dtopt Columns
  11577. *
  11578. * @example
  11579. * // Using `columnDefs`
  11580. * $(document).ready( function() {
  11581. * $('#example').dataTable( {
  11582. * "columnDefs": [
  11583. * { "type": "html", "targets": [ 0 ] }
  11584. * ]
  11585. * } );
  11586. * } );
  11587. *
  11588. * @example
  11589. * // Using `columns`
  11590. * $(document).ready( function() {
  11591. * $('#example').dataTable( {
  11592. * "columns": [
  11593. * { "type": "html" },
  11594. * null,
  11595. * null,
  11596. * null,
  11597. * null
  11598. * ]
  11599. * } );
  11600. * } );
  11601. */
  11602. "sType": null,
  11603. /**
  11604. * Defining the width of the column, this parameter may take any CSS value
  11605. * (3em, 20px etc). DataTables applies 'smart' widths to columns which have not
  11606. * been given a specific width through this interface ensuring that the table
  11607. * remains readable.
  11608. * @type string
  11609. * @default null <i>Automatic</i>
  11610. *
  11611. * @name DataTable.defaults.column.width
  11612. * @dtopt Columns
  11613. *
  11614. * @example
  11615. * // Using `columnDefs`
  11616. * $(document).ready( function() {
  11617. * $('#example').dataTable( {
  11618. * "columnDefs": [
  11619. * { "width": "20%", "targets": [ 0 ] }
  11620. * ]
  11621. * } );
  11622. * } );
  11623. *
  11624. * @example
  11625. * // Using `columns`
  11626. * $(document).ready( function() {
  11627. * $('#example').dataTable( {
  11628. * "columns": [
  11629. * { "width": "20%" },
  11630. * null,
  11631. * null,
  11632. * null,
  11633. * null
  11634. * ]
  11635. * } );
  11636. * } );
  11637. */
  11638. "sWidth": null
  11639. };
  11640. _fnHungarianMap(DataTable.defaults.column);
  11641. /**
  11642. * DataTables settings object - this holds all the information needed for a
  11643. * given table, including configuration, data and current application of the
  11644. * table options. DataTables does not have a single instance for each DataTable
  11645. * with the settings attached to that instance, but rather instances of the
  11646. * DataTable "class" are created on-the-fly as needed (typically by a
  11647. * $().dataTable() call) and the settings object is then applied to that
  11648. * instance.
  11649. *
  11650. * Note that this object is related to {@link DataTable.defaults} but this
  11651. * one is the internal data store for DataTables's cache of columns. It should
  11652. * NOT be manipulated outside of DataTables. Any configuration should be done
  11653. * through the initialisation options.
  11654. * @namespace
  11655. * @todo Really should attach the settings object to individual instances so we
  11656. * don't need to create new instances on each $().dataTable() call (if the
  11657. * table already exists). It would also save passing oSettings around and
  11658. * into every single function. However, this is a very significant
  11659. * architecture change for DataTables and will almost certainly break
  11660. * backwards compatibility with older installations. This is something that
  11661. * will be done in 2.0.
  11662. */
  11663. DataTable.models.oSettings = {
  11664. /**
  11665. * Primary features of DataTables and their enablement state.
  11666. * @namespace
  11667. */
  11668. "oFeatures": {
  11669. /**
  11670. * Flag to say if DataTables should automatically try to calculate the
  11671. * optimum table and columns widths (true) or not (false).
  11672. * Note that this parameter will be set by the initialisation routine. To
  11673. * set a default use {@link DataTable.defaults}.
  11674. * @type boolean
  11675. */
  11676. "bAutoWidth": null,
  11677. /**
  11678. * Delay the creation of TR and TD elements until they are actually
  11679. * needed by a driven page draw. This can give a significant speed
  11680. * increase for Ajax source and Javascript source data, but makes no
  11681. * difference at all fro DOM and server-side processing tables.
  11682. * Note that this parameter will be set by the initialisation routine. To
  11683. * set a default use {@link DataTable.defaults}.
  11684. * @type boolean
  11685. */
  11686. "bDeferRender": null,
  11687. /**
  11688. * Enable filtering on the table or not. Note that if this is disabled
  11689. * then there is no filtering at all on the table, including fnFilter.
  11690. * To just remove the filtering input use sDom and remove the 'f' option.
  11691. * Note that this parameter will be set by the initialisation routine. To
  11692. * set a default use {@link DataTable.defaults}.
  11693. * @type boolean
  11694. */
  11695. "bFilter": null,
  11696. /**
  11697. * Table information element (the 'Showing x of y records' div) enable
  11698. * flag.
  11699. * Note that this parameter will be set by the initialisation routine. To
  11700. * set a default use {@link DataTable.defaults}.
  11701. * @type boolean
  11702. */
  11703. "bInfo": null,
  11704. /**
  11705. * Present a user control allowing the end user to change the page size
  11706. * when pagination is enabled.
  11707. * Note that this parameter will be set by the initialisation routine. To
  11708. * set a default use {@link DataTable.defaults}.
  11709. * @type boolean
  11710. */
  11711. "bLengthChange": null,
  11712. /**
  11713. * Pagination enabled or not. Note that if this is disabled then length
  11714. * changing must also be disabled.
  11715. * Note that this parameter will be set by the initialisation routine. To
  11716. * set a default use {@link DataTable.defaults}.
  11717. * @type boolean
  11718. */
  11719. "bPaginate": null,
  11720. /**
  11721. * Processing indicator enable flag whenever DataTables is enacting a
  11722. * user request - typically an Ajax request for server-side processing.
  11723. * Note that this parameter will be set by the initialisation routine. To
  11724. * set a default use {@link DataTable.defaults}.
  11725. * @type boolean
  11726. */
  11727. "bProcessing": null,
  11728. /**
  11729. * Server-side processing enabled flag - when enabled DataTables will
  11730. * get all data from the server for every draw - there is no filtering,
  11731. * sorting or paging done on the client-side.
  11732. * Note that this parameter will be set by the initialisation routine. To
  11733. * set a default use {@link DataTable.defaults}.
  11734. * @type boolean
  11735. */
  11736. "bServerSide": null,
  11737. /**
  11738. * Sorting enablement flag.
  11739. * Note that this parameter will be set by the initialisation routine. To
  11740. * set a default use {@link DataTable.defaults}.
  11741. * @type boolean
  11742. */
  11743. "bSort": null,
  11744. /**
  11745. * Multi-column sorting
  11746. * Note that this parameter will be set by the initialisation routine. To
  11747. * set a default use {@link DataTable.defaults}.
  11748. * @type boolean
  11749. */
  11750. "bSortMulti": null,
  11751. /**
  11752. * Apply a class to the columns which are being sorted to provide a
  11753. * visual highlight or not. This can slow things down when enabled since
  11754. * there is a lot of DOM interaction.
  11755. * Note that this parameter will be set by the initialisation routine. To
  11756. * set a default use {@link DataTable.defaults}.
  11757. * @type boolean
  11758. */
  11759. "bSortClasses": null,
  11760. /**
  11761. * State saving enablement flag.
  11762. * Note that this parameter will be set by the initialisation routine. To
  11763. * set a default use {@link DataTable.defaults}.
  11764. * @type boolean
  11765. */
  11766. "bStateSave": null
  11767. },
  11768. /**
  11769. * Scrolling settings for a table.
  11770. * @namespace
  11771. */
  11772. "oScroll": {
  11773. /**
  11774. * When the table is shorter in height than sScrollY, collapse the
  11775. * table container down to the height of the table (when true).
  11776. * Note that this parameter will be set by the initialisation routine. To
  11777. * set a default use {@link DataTable.defaults}.
  11778. * @type boolean
  11779. */
  11780. "bCollapse": null,
  11781. /**
  11782. * Width of the scrollbar for the web-browser's platform. Calculated
  11783. * during table initialisation.
  11784. * @type int
  11785. * @default 0
  11786. */
  11787. "iBarWidth": 0,
  11788. /**
  11789. * Viewport width for horizontal scrolling. Horizontal scrolling is
  11790. * disabled if an empty string.
  11791. * Note that this parameter will be set by the initialisation routine. To
  11792. * set a default use {@link DataTable.defaults}.
  11793. * @type string
  11794. */
  11795. "sX": null,
  11796. /**
  11797. * Width to expand the table to when using x-scrolling. Typically you
  11798. * should not need to use this.
  11799. * Note that this parameter will be set by the initialisation routine. To
  11800. * set a default use {@link DataTable.defaults}.
  11801. * @type string
  11802. * @deprecated
  11803. */
  11804. "sXInner": null,
  11805. /**
  11806. * Viewport height for vertical scrolling. Vertical scrolling is disabled
  11807. * if an empty string.
  11808. * Note that this parameter will be set by the initialisation routine. To
  11809. * set a default use {@link DataTable.defaults}.
  11810. * @type string
  11811. */
  11812. "sY": null
  11813. },
  11814. /**
  11815. * Language information for the table.
  11816. * @namespace
  11817. * @extends DataTable.defaults.oLanguage
  11818. */
  11819. "oLanguage": {
  11820. /**
  11821. * Information callback function. See
  11822. * {@link DataTable.defaults.fnInfoCallback}
  11823. * @type function
  11824. * @default null
  11825. */
  11826. "fnInfoCallback": null
  11827. },
  11828. /**
  11829. * Browser support parameters
  11830. * @namespace
  11831. */
  11832. "oBrowser": {
  11833. /**
  11834. * Indicate if the browser incorrectly calculates width:100% inside a
  11835. * scrolling element (IE6/7)
  11836. * @type boolean
  11837. * @default false
  11838. */
  11839. "bScrollOversize": false,
  11840. /**
  11841. * Determine if the vertical scrollbar is on the right or left of the
  11842. * scrolling container - needed for rtl language layout, although not
  11843. * all browsers move the scrollbar (Safari).
  11844. * @type boolean
  11845. * @default false
  11846. */
  11847. "bScrollbarLeft": false,
  11848. /**
  11849. * Flag for if `getBoundingClientRect` is fully supported or not
  11850. * @type boolean
  11851. * @default false
  11852. */
  11853. "bBounding": false,
  11854. /**
  11855. * Browser scrollbar width
  11856. * @type integer
  11857. * @default 0
  11858. */
  11859. "barWidth": 0
  11860. },
  11861. "ajax": null,
  11862. /**
  11863. * Array referencing the nodes which are used for the features. The
  11864. * parameters of this object match what is allowed by sDom - i.e.
  11865. * <ul>
  11866. * <li>'l' - Length changing</li>
  11867. * <li>'f' - Filtering input</li>
  11868. * <li>'t' - The table!</li>
  11869. * <li>'i' - Information</li>
  11870. * <li>'p' - Pagination</li>
  11871. * <li>'r' - pRocessing</li>
  11872. * </ul>
  11873. * @type array
  11874. * @default []
  11875. */
  11876. "aanFeatures": [],
  11877. /**
  11878. * Store data information - see {@link DataTable.models.oRow} for detailed
  11879. * information.
  11880. * @type array
  11881. * @default []
  11882. */
  11883. "aoData": [],
  11884. /**
  11885. * Array of indexes which are in the current display (after filtering etc)
  11886. * @type array
  11887. * @default []
  11888. */
  11889. "aiDisplay": [],
  11890. /**
  11891. * Array of indexes for display - no filtering
  11892. * @type array
  11893. * @default []
  11894. */
  11895. "aiDisplayMaster": [],
  11896. /**
  11897. * Map of row ids to data indexes
  11898. * @type object
  11899. * @default {}
  11900. */
  11901. "aIds": {},
  11902. /**
  11903. * Store information about each column that is in use
  11904. * @type array
  11905. * @default []
  11906. */
  11907. "aoColumns": [],
  11908. /**
  11909. * Store information about the table's header
  11910. * @type array
  11911. * @default []
  11912. */
  11913. "aoHeader": [],
  11914. /**
  11915. * Store information about the table's footer
  11916. * @type array
  11917. * @default []
  11918. */
  11919. "aoFooter": [],
  11920. /**
  11921. * Store the applied global search information in case we want to force a
  11922. * research or compare the old search to a new one.
  11923. * Note that this parameter will be set by the initialisation routine. To
  11924. * set a default use {@link DataTable.defaults}.
  11925. * @namespace
  11926. * @extends DataTable.models.oSearch
  11927. */
  11928. "oPreviousSearch": {},
  11929. /**
  11930. * Store the applied search for each column - see
  11931. * {@link DataTable.models.oSearch} for the format that is used for the
  11932. * filtering information for each column.
  11933. * @type array
  11934. * @default []
  11935. */
  11936. "aoPreSearchCols": [],
  11937. /**
  11938. * Sorting that is applied to the table. Note that the inner arrays are
  11939. * used in the following manner:
  11940. * <ul>
  11941. * <li>Index 0 - column number</li>
  11942. * <li>Index 1 - current sorting direction</li>
  11943. * </ul>
  11944. * Note that this parameter will be set by the initialisation routine. To
  11945. * set a default use {@link DataTable.defaults}.
  11946. * @type array
  11947. * @todo These inner arrays should really be objects
  11948. */
  11949. "aaSorting": null,
  11950. /**
  11951. * Sorting that is always applied to the table (i.e. prefixed in front of
  11952. * aaSorting).
  11953. * Note that this parameter will be set by the initialisation routine. To
  11954. * set a default use {@link DataTable.defaults}.
  11955. * @type array
  11956. * @default []
  11957. */
  11958. "aaSortingFixed": [],
  11959. /**
  11960. * Classes to use for the striping of a table.
  11961. * Note that this parameter will be set by the initialisation routine. To
  11962. * set a default use {@link DataTable.defaults}.
  11963. * @type array
  11964. * @default []
  11965. */
  11966. "asStripeClasses": null,
  11967. /**
  11968. * If restoring a table - we should restore its striping classes as well
  11969. * @type array
  11970. * @default []
  11971. */
  11972. "asDestroyStripes": [],
  11973. /**
  11974. * If restoring a table - we should restore its width
  11975. * @type int
  11976. * @default 0
  11977. */
  11978. "sDestroyWidth": 0,
  11979. /**
  11980. * Callback functions array for every time a row is inserted (i.e. on a draw).
  11981. * @type array
  11982. * @default []
  11983. */
  11984. "aoRowCallback": [],
  11985. /**
  11986. * Callback functions for the header on each draw.
  11987. * @type array
  11988. * @default []
  11989. */
  11990. "aoHeaderCallback": [],
  11991. /**
  11992. * Callback function for the footer on each draw.
  11993. * @type array
  11994. * @default []
  11995. */
  11996. "aoFooterCallback": [],
  11997. /**
  11998. * Array of callback functions for draw callback functions
  11999. * @type array
  12000. * @default []
  12001. */
  12002. "aoDrawCallback": [],
  12003. /**
  12004. * Array of callback functions for row created function
  12005. * @type array
  12006. * @default []
  12007. */
  12008. "aoRowCreatedCallback": [],
  12009. /**
  12010. * Callback functions for just before the table is redrawn. A return of
  12011. * false will be used to cancel the draw.
  12012. * @type array
  12013. * @default []
  12014. */
  12015. "aoPreDrawCallback": [],
  12016. /**
  12017. * Callback functions for when the table has been initialised.
  12018. * @type array
  12019. * @default []
  12020. */
  12021. "aoInitComplete": [],
  12022. /**
  12023. * Callbacks for modifying the settings to be stored for state saving, prior to
  12024. * saving state.
  12025. * @type array
  12026. * @default []
  12027. */
  12028. "aoStateSaveParams": [],
  12029. /**
  12030. * Callbacks for modifying the settings that have been stored for state saving
  12031. * prior to using the stored values to restore the state.
  12032. * @type array
  12033. * @default []
  12034. */
  12035. "aoStateLoadParams": [],
  12036. /**
  12037. * Callbacks for operating on the settings object once the saved state has been
  12038. * loaded
  12039. * @type array
  12040. * @default []
  12041. */
  12042. "aoStateLoaded": [],
  12043. /**
  12044. * Cache the table ID for quick access
  12045. * @type string
  12046. * @default <i>Empty string</i>
  12047. */
  12048. "sTableId": "",
  12049. /**
  12050. * The TABLE node for the main table
  12051. * @type node
  12052. * @default null
  12053. */
  12054. "nTable": null,
  12055. /**
  12056. * Permanent ref to the thead element
  12057. * @type node
  12058. * @default null
  12059. */
  12060. "nTHead": null,
  12061. /**
  12062. * Permanent ref to the tfoot element - if it exists
  12063. * @type node
  12064. * @default null
  12065. */
  12066. "nTFoot": null,
  12067. /**
  12068. * Permanent ref to the tbody element
  12069. * @type node
  12070. * @default null
  12071. */
  12072. "nTBody": null,
  12073. /**
  12074. * Cache the wrapper node (contains all DataTables controlled elements)
  12075. * @type node
  12076. * @default null
  12077. */
  12078. "nTableWrapper": null,
  12079. /**
  12080. * Indicate if when using server-side processing the loading of data
  12081. * should be deferred until the second draw.
  12082. * Note that this parameter will be set by the initialisation routine. To
  12083. * set a default use {@link DataTable.defaults}.
  12084. * @type boolean
  12085. * @default false
  12086. */
  12087. "bDeferLoading": false,
  12088. /**
  12089. * Indicate if all required information has been read in
  12090. * @type boolean
  12091. * @default false
  12092. */
  12093. "bInitialised": false,
  12094. /**
  12095. * Information about open rows. Each object in the array has the parameters
  12096. * 'nTr' and 'nParent'
  12097. * @type array
  12098. * @default []
  12099. */
  12100. "aoOpenRows": [],
  12101. /**
  12102. * Dictate the positioning of DataTables' control elements - see
  12103. * {@link DataTable.model.oInit.sDom}.
  12104. * Note that this parameter will be set by the initialisation routine. To
  12105. * set a default use {@link DataTable.defaults}.
  12106. * @type string
  12107. * @default null
  12108. */
  12109. "sDom": null,
  12110. /**
  12111. * Search delay (in mS)
  12112. * @type integer
  12113. * @default null
  12114. */
  12115. "searchDelay": null,
  12116. /**
  12117. * Which type of pagination should be used.
  12118. * Note that this parameter will be set by the initialisation routine. To
  12119. * set a default use {@link DataTable.defaults}.
  12120. * @type string
  12121. * @default two_button
  12122. */
  12123. "sPaginationType": "two_button",
  12124. /**
  12125. * The state duration (for `stateSave`) in seconds.
  12126. * Note that this parameter will be set by the initialisation routine. To
  12127. * set a default use {@link DataTable.defaults}.
  12128. * @type int
  12129. * @default 0
  12130. */
  12131. "iStateDuration": 0,
  12132. /**
  12133. * Array of callback functions for state saving. Each array element is an
  12134. * object with the following parameters:
  12135. * <ul>
  12136. * <li>function:fn - function to call. Takes two parameters, oSettings
  12137. * and the JSON string to save that has been thus far created. Returns
  12138. * a JSON string to be inserted into a json object
  12139. * (i.e. '"param": [ 0, 1, 2]')</li>
  12140. * <li>string:sName - name of callback</li>
  12141. * </ul>
  12142. * @type array
  12143. * @default []
  12144. */
  12145. "aoStateSave": [],
  12146. /**
  12147. * Array of callback functions for state loading. Each array element is an
  12148. * object with the following parameters:
  12149. * <ul>
  12150. * <li>function:fn - function to call. Takes two parameters, oSettings
  12151. * and the object stored. May return false to cancel state loading</li>
  12152. * <li>string:sName - name of callback</li>
  12153. * </ul>
  12154. * @type array
  12155. * @default []
  12156. */
  12157. "aoStateLoad": [],
  12158. /**
  12159. * State that was saved. Useful for back reference
  12160. * @type object
  12161. * @default null
  12162. */
  12163. "oSavedState": null,
  12164. /**
  12165. * State that was loaded. Useful for back reference
  12166. * @type object
  12167. * @default null
  12168. */
  12169. "oLoadedState": null,
  12170. /**
  12171. * Source url for AJAX data for the table.
  12172. * Note that this parameter will be set by the initialisation routine. To
  12173. * set a default use {@link DataTable.defaults}.
  12174. * @type string
  12175. * @default null
  12176. */
  12177. "sAjaxSource": null,
  12178. /**
  12179. * Property from a given object from which to read the table data from. This
  12180. * can be an empty string (when not server-side processing), in which case
  12181. * it is assumed an an array is given directly.
  12182. * Note that this parameter will be set by the initialisation routine. To
  12183. * set a default use {@link DataTable.defaults}.
  12184. * @type string
  12185. */
  12186. "sAjaxDataProp": null,
  12187. /**
  12188. * Note if draw should be blocked while getting data
  12189. * @type boolean
  12190. * @default true
  12191. */
  12192. "bAjaxDataGet": true,
  12193. /**
  12194. * The last jQuery XHR object that was used for server-side data gathering.
  12195. * This can be used for working with the XHR information in one of the
  12196. * callbacks
  12197. * @type object
  12198. * @default null
  12199. */
  12200. "jqXHR": null,
  12201. /**
  12202. * JSON returned from the server in the last Ajax request
  12203. * @type object
  12204. * @default undefined
  12205. */
  12206. "json": undefined,
  12207. /**
  12208. * Data submitted as part of the last Ajax request
  12209. * @type object
  12210. * @default undefined
  12211. */
  12212. "oAjaxData": undefined,
  12213. /**
  12214. * Function to get the server-side data.
  12215. * Note that this parameter will be set by the initialisation routine. To
  12216. * set a default use {@link DataTable.defaults}.
  12217. * @type function
  12218. */
  12219. "fnServerData": null,
  12220. /**
  12221. * Functions which are called prior to sending an Ajax request so extra
  12222. * parameters can easily be sent to the server
  12223. * @type array
  12224. * @default []
  12225. */
  12226. "aoServerParams": [],
  12227. /**
  12228. * Send the XHR HTTP method - GET or POST (could be PUT or DELETE if
  12229. * required).
  12230. * Note that this parameter will be set by the initialisation routine. To
  12231. * set a default use {@link DataTable.defaults}.
  12232. * @type string
  12233. */
  12234. "sServerMethod": null,
  12235. /**
  12236. * Format numbers for display.
  12237. * Note that this parameter will be set by the initialisation routine. To
  12238. * set a default use {@link DataTable.defaults}.
  12239. * @type function
  12240. */
  12241. "fnFormatNumber": null,
  12242. /**
  12243. * List of options that can be used for the user selectable length menu.
  12244. * Note that this parameter will be set by the initialisation routine. To
  12245. * set a default use {@link DataTable.defaults}.
  12246. * @type array
  12247. * @default []
  12248. */
  12249. "aLengthMenu": null,
  12250. /**
  12251. * Counter for the draws that the table does. Also used as a tracker for
  12252. * server-side processing
  12253. * @type int
  12254. * @default 0
  12255. */
  12256. "iDraw": 0,
  12257. /**
  12258. * Indicate if a redraw is being done - useful for Ajax
  12259. * @type boolean
  12260. * @default false
  12261. */
  12262. "bDrawing": false,
  12263. /**
  12264. * Draw index (iDraw) of the last error when parsing the returned data
  12265. * @type int
  12266. * @default -1
  12267. */
  12268. "iDrawError": -1,
  12269. /**
  12270. * Paging display length
  12271. * @type int
  12272. * @default 10
  12273. */
  12274. "_iDisplayLength": 10,
  12275. /**
  12276. * Paging start point - aiDisplay index
  12277. * @type int
  12278. * @default 0
  12279. */
  12280. "_iDisplayStart": 0,
  12281. /**
  12282. * Server-side processing - number of records in the result set
  12283. * (i.e. before filtering), Use fnRecordsTotal rather than
  12284. * this property to get the value of the number of records, regardless of
  12285. * the server-side processing setting.
  12286. * @type int
  12287. * @default 0
  12288. * @private
  12289. */
  12290. "_iRecordsTotal": 0,
  12291. /**
  12292. * Server-side processing - number of records in the current display set
  12293. * (i.e. after filtering). Use fnRecordsDisplay rather than
  12294. * this property to get the value of the number of records, regardless of
  12295. * the server-side processing setting.
  12296. * @type boolean
  12297. * @default 0
  12298. * @private
  12299. */
  12300. "_iRecordsDisplay": 0,
  12301. /**
  12302. * The classes to use for the table
  12303. * @type object
  12304. * @default {}
  12305. */
  12306. "oClasses": {},
  12307. /**
  12308. * Flag attached to the settings object so you can check in the draw
  12309. * callback if filtering has been done in the draw. Deprecated in favour of
  12310. * events.
  12311. * @type boolean
  12312. * @default false
  12313. * @deprecated
  12314. */
  12315. "bFiltered": false,
  12316. /**
  12317. * Flag attached to the settings object so you can check in the draw
  12318. * callback if sorting has been done in the draw. Deprecated in favour of
  12319. * events.
  12320. * @type boolean
  12321. * @default false
  12322. * @deprecated
  12323. */
  12324. "bSorted": false,
  12325. /**
  12326. * Indicate that if multiple rows are in the header and there is more than
  12327. * one unique cell per column, if the top one (true) or bottom one (false)
  12328. * should be used for sorting / title by DataTables.
  12329. * Note that this parameter will be set by the initialisation routine. To
  12330. * set a default use {@link DataTable.defaults}.
  12331. * @type boolean
  12332. */
  12333. "bSortCellsTop": null,
  12334. /**
  12335. * Initialisation object that is used for the table
  12336. * @type object
  12337. * @default null
  12338. */
  12339. "oInit": null,
  12340. /**
  12341. * Destroy callback functions - for plug-ins to attach themselves to the
  12342. * destroy so they can clean up markup and events.
  12343. * @type array
  12344. * @default []
  12345. */
  12346. "aoDestroyCallback": [],
  12347. /**
  12348. * Get the number of records in the current record set, before filtering
  12349. * @type function
  12350. */
  12351. "fnRecordsTotal": function fnRecordsTotal() {
  12352. return _fnDataSource(this) == 'ssp' ? this._iRecordsTotal * 1 : this.aiDisplayMaster.length;
  12353. },
  12354. /**
  12355. * Get the number of records in the current record set, after filtering
  12356. * @type function
  12357. */
  12358. "fnRecordsDisplay": function fnRecordsDisplay() {
  12359. return _fnDataSource(this) == 'ssp' ? this._iRecordsDisplay * 1 : this.aiDisplay.length;
  12360. },
  12361. /**
  12362. * Get the display end point - aiDisplay index
  12363. * @type function
  12364. */
  12365. "fnDisplayEnd": function fnDisplayEnd() {
  12366. var len = this._iDisplayLength,
  12367. start = this._iDisplayStart,
  12368. calc = start + len,
  12369. records = this.aiDisplay.length,
  12370. features = this.oFeatures,
  12371. paginate = features.bPaginate;
  12372. if (features.bServerSide) {
  12373. return paginate === false || len === -1 ? start + records : Math.min(start + len, this._iRecordsDisplay);
  12374. } else {
  12375. return !paginate || calc > records || len === -1 ? records : calc;
  12376. }
  12377. },
  12378. /**
  12379. * The DataTables object for this table
  12380. * @type object
  12381. * @default null
  12382. */
  12383. "oInstance": null,
  12384. /**
  12385. * Unique identifier for each instance of the DataTables object. If there
  12386. * is an ID on the table node, then it takes that value, otherwise an
  12387. * incrementing internal counter is used.
  12388. * @type string
  12389. * @default null
  12390. */
  12391. "sInstance": null,
  12392. /**
  12393. * tabindex attribute value that is added to DataTables control elements, allowing
  12394. * keyboard navigation of the table and its controls.
  12395. */
  12396. "iTabIndex": 0,
  12397. /**
  12398. * DIV container for the footer scrolling table if scrolling
  12399. */
  12400. "nScrollHead": null,
  12401. /**
  12402. * DIV container for the footer scrolling table if scrolling
  12403. */
  12404. "nScrollFoot": null,
  12405. /**
  12406. * Last applied sort
  12407. * @type array
  12408. * @default []
  12409. */
  12410. "aLastSort": [],
  12411. /**
  12412. * Stored plug-in instances
  12413. * @type object
  12414. * @default {}
  12415. */
  12416. "oPlugins": {},
  12417. /**
  12418. * Function used to get a row's id from the row's data
  12419. * @type function
  12420. * @default null
  12421. */
  12422. "rowIdFn": null,
  12423. /**
  12424. * Data location where to store a row's id
  12425. * @type string
  12426. * @default null
  12427. */
  12428. "rowId": null
  12429. };
  12430. /**
  12431. * Extension object for DataTables that is used to provide all extension
  12432. * options.
  12433. *
  12434. * Note that the `DataTable.ext` object is available through
  12435. * `jQuery.fn.dataTable.ext` where it may be accessed and manipulated. It is
  12436. * also aliased to `jQuery.fn.dataTableExt` for historic reasons.
  12437. * @namespace
  12438. * @extends DataTable.models.ext
  12439. */
  12440. /**
  12441. * DataTables extensions
  12442. *
  12443. * This namespace acts as a collection area for plug-ins that can be used to
  12444. * extend DataTables capabilities. Indeed many of the build in methods
  12445. * use this method to provide their own capabilities (sorting methods for
  12446. * example).
  12447. *
  12448. * Note that this namespace is aliased to `jQuery.fn.dataTableExt` for legacy
  12449. * reasons
  12450. *
  12451. * @namespace
  12452. */
  12453. DataTable.ext = _ext = {
  12454. /**
  12455. * Buttons. For use with the Buttons extension for DataTables. This is
  12456. * defined here so other extensions can define buttons regardless of load
  12457. * order. It is _not_ used by DataTables core.
  12458. *
  12459. * @type object
  12460. * @default {}
  12461. */
  12462. buttons: {},
  12463. /**
  12464. * Element class names
  12465. *
  12466. * @type object
  12467. * @default {}
  12468. */
  12469. classes: {},
  12470. /**
  12471. * DataTables build type (expanded by the download builder)
  12472. *
  12473. * @type string
  12474. */
  12475. builder: "-source-",
  12476. /**
  12477. * Error reporting.
  12478. *
  12479. * How should DataTables report an error. Can take the value 'alert',
  12480. * 'throw', 'none' or a function.
  12481. *
  12482. * @type string|function
  12483. * @default alert
  12484. */
  12485. errMode: "alert",
  12486. /**
  12487. * Feature plug-ins.
  12488. *
  12489. * This is an array of objects which describe the feature plug-ins that are
  12490. * available to DataTables. These feature plug-ins are then available for
  12491. * use through the `dom` initialisation option.
  12492. *
  12493. * Each feature plug-in is described by an object which must have the
  12494. * following properties:
  12495. *
  12496. * * `fnInit` - function that is used to initialise the plug-in,
  12497. * * `cFeature` - a character so the feature can be enabled by the `dom`
  12498. * instillation option. This is case sensitive.
  12499. *
  12500. * The `fnInit` function has the following input parameters:
  12501. *
  12502. * 1. `{object}` DataTables settings object: see
  12503. * {@link DataTable.models.oSettings}
  12504. *
  12505. * And the following return is expected:
  12506. *
  12507. * * {node|null} The element which contains your feature. Note that the
  12508. * return may also be void if your plug-in does not require to inject any
  12509. * DOM elements into DataTables control (`dom`) - for example this might
  12510. * be useful when developing a plug-in which allows table control via
  12511. * keyboard entry
  12512. *
  12513. * @type array
  12514. *
  12515. * @example
  12516. * $.fn.dataTable.ext.features.push( {
  12517. * "fnInit": function( oSettings ) {
  12518. * return new TableTools( { "oDTSettings": oSettings } );
  12519. * },
  12520. * "cFeature": "T"
  12521. * } );
  12522. */
  12523. feature: [],
  12524. /**
  12525. * Row searching.
  12526. *
  12527. * This method of searching is complimentary to the default type based
  12528. * searching, and a lot more comprehensive as it allows you complete control
  12529. * over the searching logic. Each element in this array is a function
  12530. * (parameters described below) that is called for every row in the table,
  12531. * and your logic decides if it should be included in the searching data set
  12532. * or not.
  12533. *
  12534. * Searching functions have the following input parameters:
  12535. *
  12536. * 1. `{object}` DataTables settings object: see
  12537. * {@link DataTable.models.oSettings}
  12538. * 2. `{array|object}` Data for the row to be processed (same as the
  12539. * original format that was passed in as the data source, or an array
  12540. * from a DOM data source
  12541. * 3. `{int}` Row index ({@link DataTable.models.oSettings.aoData}), which
  12542. * can be useful to retrieve the `TR` element if you need DOM interaction.
  12543. *
  12544. * And the following return is expected:
  12545. *
  12546. * * {boolean} Include the row in the searched result set (true) or not
  12547. * (false)
  12548. *
  12549. * Note that as with the main search ability in DataTables, technically this
  12550. * is "filtering", since it is subtractive. However, for consistency in
  12551. * naming we call it searching here.
  12552. *
  12553. * @type array
  12554. * @default []
  12555. *
  12556. * @example
  12557. * // The following example shows custom search being applied to the
  12558. * // fourth column (i.e. the data[3] index) based on two input values
  12559. * // from the end-user, matching the data in a certain range.
  12560. * $.fn.dataTable.ext.search.push(
  12561. * function( settings, data, dataIndex ) {
  12562. * var min = document.getElementById('min').value * 1;
  12563. * var max = document.getElementById('max').value * 1;
  12564. * var version = data[3] == "-" ? 0 : data[3]*1;
  12565. *
  12566. * if ( min == "" && max == "" ) {
  12567. * return true;
  12568. * }
  12569. * else if ( min == "" && version < max ) {
  12570. * return true;
  12571. * }
  12572. * else if ( min < version && "" == max ) {
  12573. * return true;
  12574. * }
  12575. * else if ( min < version && version < max ) {
  12576. * return true;
  12577. * }
  12578. * return false;
  12579. * }
  12580. * );
  12581. */
  12582. search: [],
  12583. /**
  12584. * Selector extensions
  12585. *
  12586. * The `selector` option can be used to extend the options available for the
  12587. * selector modifier options (`selector-modifier` object data type) that
  12588. * each of the three built in selector types offer (row, column and cell +
  12589. * their plural counterparts). For example the Select extension uses this
  12590. * mechanism to provide an option to select only rows, columns and cells
  12591. * that have been marked as selected by the end user (`{selected: true}`),
  12592. * which can be used in conjunction with the existing built in selector
  12593. * options.
  12594. *
  12595. * Each property is an array to which functions can be pushed. The functions
  12596. * take three attributes:
  12597. *
  12598. * * Settings object for the host table
  12599. * * Options object (`selector-modifier` object type)
  12600. * * Array of selected item indexes
  12601. *
  12602. * The return is an array of the resulting item indexes after the custom
  12603. * selector has been applied.
  12604. *
  12605. * @type object
  12606. */
  12607. selector: {
  12608. cell: [],
  12609. column: [],
  12610. row: []
  12611. },
  12612. /**
  12613. * Internal functions, exposed for used in plug-ins.
  12614. *
  12615. * Please note that you should not need to use the internal methods for
  12616. * anything other than a plug-in (and even then, try to avoid if possible).
  12617. * The internal function may change between releases.
  12618. *
  12619. * @type object
  12620. * @default {}
  12621. */
  12622. internal: {},
  12623. /**
  12624. * Legacy configuration options. Enable and disable legacy options that
  12625. * are available in DataTables.
  12626. *
  12627. * @type object
  12628. */
  12629. legacy: {
  12630. /**
  12631. * Enable / disable DataTables 1.9 compatible server-side processing
  12632. * requests
  12633. *
  12634. * @type boolean
  12635. * @default null
  12636. */
  12637. ajax: null
  12638. },
  12639. /**
  12640. * Pagination plug-in methods.
  12641. *
  12642. * Each entry in this object is a function and defines which buttons should
  12643. * be shown by the pagination rendering method that is used for the table:
  12644. * {@link DataTable.ext.renderer.pageButton}. The renderer addresses how the
  12645. * buttons are displayed in the document, while the functions here tell it
  12646. * what buttons to display. This is done by returning an array of button
  12647. * descriptions (what each button will do).
  12648. *
  12649. * Pagination types (the four built in options and any additional plug-in
  12650. * options defined here) can be used through the `paginationType`
  12651. * initialisation parameter.
  12652. *
  12653. * The functions defined take two parameters:
  12654. *
  12655. * 1. `{int} page` The current page index
  12656. * 2. `{int} pages` The number of pages in the table
  12657. *
  12658. * Each function is expected to return an array where each element of the
  12659. * array can be one of:
  12660. *
  12661. * * `first` - Jump to first page when activated
  12662. * * `last` - Jump to last page when activated
  12663. * * `previous` - Show previous page when activated
  12664. * * `next` - Show next page when activated
  12665. * * `{int}` - Show page of the index given
  12666. * * `{array}` - A nested array containing the above elements to add a
  12667. * containing 'DIV' element (might be useful for styling).
  12668. *
  12669. * Note that DataTables v1.9- used this object slightly differently whereby
  12670. * an object with two functions would be defined for each plug-in. That
  12671. * ability is still supported by DataTables 1.10+ to provide backwards
  12672. * compatibility, but this option of use is now decremented and no longer
  12673. * documented in DataTables 1.10+.
  12674. *
  12675. * @type object
  12676. * @default {}
  12677. *
  12678. * @example
  12679. * // Show previous, next and current page buttons only
  12680. * $.fn.dataTableExt.oPagination.current = function ( page, pages ) {
  12681. * return [ 'previous', page, 'next' ];
  12682. * };
  12683. */
  12684. pager: {},
  12685. renderer: {
  12686. pageButton: {},
  12687. header: {}
  12688. },
  12689. /**
  12690. * Ordering plug-ins - custom data source
  12691. *
  12692. * The extension options for ordering of data available here is complimentary
  12693. * to the default type based ordering that DataTables typically uses. It
  12694. * allows much greater control over the the data that is being used to
  12695. * order a column, but is necessarily therefore more complex.
  12696. *
  12697. * This type of ordering is useful if you want to do ordering based on data
  12698. * live from the DOM (for example the contents of an 'input' element) rather
  12699. * than just the static string that DataTables knows of.
  12700. *
  12701. * The way these plug-ins work is that you create an array of the values you
  12702. * wish to be ordering for the column in question and then return that
  12703. * array. The data in the array much be in the index order of the rows in
  12704. * the table (not the currently ordering order!). Which order data gathering
  12705. * function is run here depends on the `dt-init columns.orderDataType`
  12706. * parameter that is used for the column (if any).
  12707. *
  12708. * The functions defined take two parameters:
  12709. *
  12710. * 1. `{object}` DataTables settings object: see
  12711. * {@link DataTable.models.oSettings}
  12712. * 2. `{int}` Target column index
  12713. *
  12714. * Each function is expected to return an array:
  12715. *
  12716. * * `{array}` Data for the column to be ordering upon
  12717. *
  12718. * @type array
  12719. *
  12720. * @example
  12721. * // Ordering using `input` node values
  12722. * $.fn.dataTable.ext.order['dom-text'] = function ( settings, col )
  12723. * {
  12724. * return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
  12725. * return $('input', td).val();
  12726. * } );
  12727. * }
  12728. */
  12729. order: {},
  12730. /**
  12731. * Type based plug-ins.
  12732. *
  12733. * Each column in DataTables has a type assigned to it, either by automatic
  12734. * detection or by direct assignment using the `type` option for the column.
  12735. * The type of a column will effect how it is ordering and search (plug-ins
  12736. * can also make use of the column type if required).
  12737. *
  12738. * @namespace
  12739. */
  12740. type: {
  12741. /**
  12742. * Type detection functions.
  12743. *
  12744. * The functions defined in this object are used to automatically detect
  12745. * a column's type, making initialisation of DataTables super easy, even
  12746. * when complex data is in the table.
  12747. *
  12748. * The functions defined take two parameters:
  12749. *
  12750. * 1. `{*}` Data from the column cell to be analysed
  12751. * 2. `{settings}` DataTables settings object. This can be used to
  12752. * perform context specific type detection - for example detection
  12753. * based on language settings such as using a comma for a decimal
  12754. * place. Generally speaking the options from the settings will not
  12755. * be required
  12756. *
  12757. * Each function is expected to return:
  12758. *
  12759. * * `{string|null}` Data type detected, or null if unknown (and thus
  12760. * pass it on to the other type detection functions.
  12761. *
  12762. * @type array
  12763. *
  12764. * @example
  12765. * // Currency type detection plug-in:
  12766. * $.fn.dataTable.ext.type.detect.push(
  12767. * function ( data, settings ) {
  12768. * // Check the numeric part
  12769. * if ( ! $.isNumeric( data.substring(1) ) ) {
  12770. * return null;
  12771. * }
  12772. *
  12773. * // Check prefixed by currency
  12774. * if ( data.charAt(0) == '$' || data.charAt(0) == '&pound;' ) {
  12775. * return 'currency';
  12776. * }
  12777. * return null;
  12778. * }
  12779. * );
  12780. */
  12781. detect: [],
  12782. /**
  12783. * Type based search formatting.
  12784. *
  12785. * The type based searching functions can be used to pre-format the
  12786. * data to be search on. For example, it can be used to strip HTML
  12787. * tags or to de-format telephone numbers for numeric only searching.
  12788. *
  12789. * Note that is a search is not defined for a column of a given type,
  12790. * no search formatting will be performed.
  12791. *
  12792. * Pre-processing of searching data plug-ins - When you assign the sType
  12793. * for a column (or have it automatically detected for you by DataTables
  12794. * or a type detection plug-in), you will typically be using this for
  12795. * custom sorting, but it can also be used to provide custom searching
  12796. * by allowing you to pre-processing the data and returning the data in
  12797. * the format that should be searched upon. This is done by adding
  12798. * functions this object with a parameter name which matches the sType
  12799. * for that target column. This is the corollary of <i>afnSortData</i>
  12800. * for searching data.
  12801. *
  12802. * The functions defined take a single parameter:
  12803. *
  12804. * 1. `{*}` Data from the column cell to be prepared for searching
  12805. *
  12806. * Each function is expected to return:
  12807. *
  12808. * * `{string|null}` Formatted string that will be used for the searching.
  12809. *
  12810. * @type object
  12811. * @default {}
  12812. *
  12813. * @example
  12814. * $.fn.dataTable.ext.type.search['title-numeric'] = function ( d ) {
  12815. * return d.replace(/\n/g," ").replace( /<.*?>/g, "" );
  12816. * }
  12817. */
  12818. search: {},
  12819. /**
  12820. * Type based ordering.
  12821. *
  12822. * The column type tells DataTables what ordering to apply to the table
  12823. * when a column is sorted upon. The order for each type that is defined,
  12824. * is defined by the functions available in this object.
  12825. *
  12826. * Each ordering option can be described by three properties added to
  12827. * this object:
  12828. *
  12829. * * `{type}-pre` - Pre-formatting function
  12830. * * `{type}-asc` - Ascending order function
  12831. * * `{type}-desc` - Descending order function
  12832. *
  12833. * All three can be used together, only `{type}-pre` or only
  12834. * `{type}-asc` and `{type}-desc` together. It is generally recommended
  12835. * that only `{type}-pre` is used, as this provides the optimal
  12836. * implementation in terms of speed, although the others are provided
  12837. * for compatibility with existing Javascript sort functions.
  12838. *
  12839. * `{type}-pre`: Functions defined take a single parameter:
  12840. *
  12841. * 1. `{*}` Data from the column cell to be prepared for ordering
  12842. *
  12843. * And return:
  12844. *
  12845. * * `{*}` Data to be sorted upon
  12846. *
  12847. * `{type}-asc` and `{type}-desc`: Functions are typical Javascript sort
  12848. * functions, taking two parameters:
  12849. *
  12850. * 1. `{*}` Data to compare to the second parameter
  12851. * 2. `{*}` Data to compare to the first parameter
  12852. *
  12853. * And returning:
  12854. *
  12855. * * `{*}` Ordering match: <0 if first parameter should be sorted lower
  12856. * than the second parameter, ===0 if the two parameters are equal and
  12857. * >0 if the first parameter should be sorted height than the second
  12858. * parameter.
  12859. *
  12860. * @type object
  12861. * @default {}
  12862. *
  12863. * @example
  12864. * // Numeric ordering of formatted numbers with a pre-formatter
  12865. * $.extend( $.fn.dataTable.ext.type.order, {
  12866. * "string-pre": function(x) {
  12867. * a = (a === "-" || a === "") ? 0 : a.replace( /[^\d\-\.]/g, "" );
  12868. * return parseFloat( a );
  12869. * }
  12870. * } );
  12871. *
  12872. * @example
  12873. * // Case-sensitive string ordering, with no pre-formatting method
  12874. * $.extend( $.fn.dataTable.ext.order, {
  12875. * "string-case-asc": function(x,y) {
  12876. * return ((x < y) ? -1 : ((x > y) ? 1 : 0));
  12877. * },
  12878. * "string-case-desc": function(x,y) {
  12879. * return ((x < y) ? 1 : ((x > y) ? -1 : 0));
  12880. * }
  12881. * } );
  12882. */
  12883. order: {}
  12884. },
  12885. /**
  12886. * Unique DataTables instance counter
  12887. *
  12888. * @type int
  12889. * @private
  12890. */
  12891. _unique: 0,
  12892. //
  12893. // Depreciated
  12894. // The following properties are retained for backwards compatiblity only.
  12895. // The should not be used in new projects and will be removed in a future
  12896. // version
  12897. //
  12898. /**
  12899. * Version check function.
  12900. * @type function
  12901. * @depreciated Since 1.10
  12902. */
  12903. fnVersionCheck: DataTable.fnVersionCheck,
  12904. /**
  12905. * Index for what 'this' index API functions should use
  12906. * @type int
  12907. * @deprecated Since v1.10
  12908. */
  12909. iApiIndex: 0,
  12910. /**
  12911. * jQuery UI class container
  12912. * @type object
  12913. * @deprecated Since v1.10
  12914. */
  12915. oJUIClasses: {},
  12916. /**
  12917. * Software version
  12918. * @type string
  12919. * @deprecated Since v1.10
  12920. */
  12921. sVersion: DataTable.version
  12922. };
  12923. //
  12924. // Backwards compatibility. Alias to pre 1.10 Hungarian notation counter parts
  12925. //
  12926. $.extend(_ext, {
  12927. afnFiltering: _ext.search,
  12928. aTypes: _ext.type.detect,
  12929. ofnSearch: _ext.type.search,
  12930. oSort: _ext.type.order,
  12931. afnSortData: _ext.order,
  12932. aoFeatures: _ext.feature,
  12933. oApi: _ext.internal,
  12934. oStdClasses: _ext.classes,
  12935. oPagination: _ext.pager
  12936. });
  12937. $.extend(DataTable.ext.classes, {
  12938. "sTable": "dataTable",
  12939. "sNoFooter": "no-footer",
  12940. /* Paging buttons */
  12941. "sPageButton": "paginate_button",
  12942. "sPageButtonActive": "current",
  12943. "sPageButtonDisabled": "disabled",
  12944. /* Striping classes */
  12945. "sStripeOdd": "odd",
  12946. "sStripeEven": "even",
  12947. /* Empty row */
  12948. "sRowEmpty": "dataTables_empty",
  12949. /* Features */
  12950. "sWrapper": "dataTables_wrapper",
  12951. "sFilter": "dataTables_filter",
  12952. "sInfo": "dataTables_info",
  12953. "sPaging": "dataTables_paginate paging_", /* Note that the type is postfixed */
  12954. "sLength": "dataTables_length",
  12955. "sProcessing": "dataTables_processing",
  12956. /* Sorting */
  12957. "sSortAsc": "sorting_asc",
  12958. "sSortDesc": "sorting_desc",
  12959. "sSortable": "sorting", /* Sortable in both directions */
  12960. "sSortableAsc": "sorting_asc_disabled",
  12961. "sSortableDesc": "sorting_desc_disabled",
  12962. "sSortableNone": "sorting_disabled",
  12963. "sSortColumn": "sorting_", /* Note that an int is postfixed for the sorting order */
  12964. /* Filtering */
  12965. "sFilterInput": "",
  12966. /* Page length */
  12967. "sLengthSelect": "",
  12968. /* Scrolling */
  12969. "sScrollWrapper": "dataTables_scroll",
  12970. "sScrollHead": "dataTables_scrollHead",
  12971. "sScrollHeadInner": "dataTables_scrollHeadInner",
  12972. "sScrollBody": "dataTables_scrollBody",
  12973. "sScrollFoot": "dataTables_scrollFoot",
  12974. "sScrollFootInner": "dataTables_scrollFootInner",
  12975. /* Misc */
  12976. "sHeaderTH": "",
  12977. "sFooterTH": "",
  12978. // Deprecated
  12979. "sSortJUIAsc": "",
  12980. "sSortJUIDesc": "",
  12981. "sSortJUI": "",
  12982. "sSortJUIAscAllowed": "",
  12983. "sSortJUIDescAllowed": "",
  12984. "sSortJUIWrapper": "",
  12985. "sSortIcon": "",
  12986. "sJUIHeader": "",
  12987. "sJUIFooter": ""
  12988. });
  12989. var extPagination = DataTable.ext.pager;
  12990. function _numbers(page, pages) {
  12991. var numbers = [],
  12992. buttons = extPagination.numbers_length,
  12993. half = Math.floor(buttons / 2),
  12994. i = 1;
  12995. if (pages <= buttons) {
  12996. numbers = _range(0, pages);
  12997. } else if (page <= half) {
  12998. numbers = _range(0, buttons - 2);
  12999. numbers.push('ellipsis');
  13000. numbers.push(pages - 1);
  13001. } else if (page >= pages - 1 - half) {
  13002. numbers = _range(pages - (buttons - 2), pages);
  13003. numbers.splice(0, 0, 'ellipsis'); // no unshift in ie6
  13004. numbers.splice(0, 0, 0);
  13005. } else {
  13006. numbers = _range(page - half + 2, page + half - 1);
  13007. numbers.push('ellipsis');
  13008. numbers.push(pages - 1);
  13009. numbers.splice(0, 0, 'ellipsis');
  13010. numbers.splice(0, 0, 0);
  13011. }
  13012. numbers.DT_el = 'span';
  13013. return numbers;
  13014. }
  13015. $.extend(extPagination, {
  13016. simple: function simple(page, pages) {
  13017. return ['previous', 'next'];
  13018. },
  13019. full: function full(page, pages) {
  13020. return ['first', 'previous', 'next', 'last'];
  13021. },
  13022. numbers: function numbers(page, pages) {
  13023. return [_numbers(page, pages)];
  13024. },
  13025. simple_numbers: function simple_numbers(page, pages) {
  13026. return ['previous', _numbers(page, pages), 'next'];
  13027. },
  13028. full_numbers: function full_numbers(page, pages) {
  13029. return ['first', 'previous', _numbers(page, pages), 'next', 'last'];
  13030. },
  13031. first_last_numbers: function first_last_numbers(page, pages) {
  13032. return ['first', _numbers(page, pages), 'last'];
  13033. },
  13034. // For testing and plug-ins to use
  13035. _numbers: _numbers,
  13036. // Number of number buttons (including ellipsis) to show. _Must be odd!_
  13037. numbers_length: 7
  13038. });
  13039. $.extend(true, DataTable.ext.renderer, {
  13040. pageButton: {
  13041. _: function _(settings, host, idx, buttons, page, pages) {
  13042. var classes = settings.oClasses;
  13043. var lang = settings.oLanguage.oPaginate;
  13044. var aria = settings.oLanguage.oAria.paginate || {};
  13045. var btnDisplay,
  13046. btnClass,
  13047. counter = 0;
  13048. var attach = function attach(container, buttons) {
  13049. var i, ien, node, button;
  13050. var clickHandler = function clickHandler(e) {
  13051. _fnPageChange(settings, e.data.action, true);
  13052. };
  13053. for (i = 0, ien = buttons.length; i < ien; i++) {
  13054. button = buttons[i];
  13055. if ($.isArray(button)) {
  13056. var inner = $('<' + (button.DT_el || 'div') + '/>').appendTo(container);
  13057. attach(inner, button);
  13058. } else {
  13059. btnDisplay = null;
  13060. btnClass = '';
  13061. switch (button) {
  13062. case 'ellipsis':
  13063. container.append('<span class="ellipsis">&#x2026;</span>');
  13064. break;
  13065. case 'first':
  13066. btnDisplay = lang.sFirst;
  13067. btnClass = button + (page > 0 ? '' : ' ' + classes.sPageButtonDisabled);
  13068. break;
  13069. case 'previous':
  13070. btnDisplay = lang.sPrevious;
  13071. btnClass = button + (page > 0 ? '' : ' ' + classes.sPageButtonDisabled);
  13072. break;
  13073. case 'next':
  13074. btnDisplay = lang.sNext;
  13075. btnClass = button + (page < pages - 1 ? '' : ' ' + classes.sPageButtonDisabled);
  13076. break;
  13077. case 'last':
  13078. btnDisplay = lang.sLast;
  13079. btnClass = button + (page < pages - 1 ? '' : ' ' + classes.sPageButtonDisabled);
  13080. break;
  13081. default:
  13082. btnDisplay = button + 1;
  13083. btnClass = page === button ? classes.sPageButtonActive : '';
  13084. break;
  13085. }
  13086. if (btnDisplay !== null) {
  13087. node = $('<a>', {
  13088. 'class': classes.sPageButton + ' ' + btnClass,
  13089. 'aria-controls': settings.sTableId,
  13090. 'aria-label': aria[button],
  13091. 'data-dt-idx': counter,
  13092. 'tabindex': settings.iTabIndex,
  13093. 'id': idx === 0 && typeof button === 'string' ? settings.sTableId + '_' + button : null
  13094. }).html(btnDisplay).appendTo(container);
  13095. _fnBindAction(node, { action: button }, clickHandler);
  13096. counter++;
  13097. }
  13098. }
  13099. }
  13100. };
  13101. // IE9 throws an 'unknown error' if document.activeElement is used
  13102. // inside an iframe or frame. Try / catch the error. Not good for
  13103. // accessibility, but neither are frames.
  13104. var activeEl;
  13105. try {
  13106. // Because this approach is destroying and recreating the paging
  13107. // elements, focus is lost on the select button which is bad for
  13108. // accessibility. So we want to restore focus once the draw has
  13109. // completed
  13110. activeEl = $(host).find(document.activeElement).data('dt-idx');
  13111. } catch (e) {}
  13112. attach($(host).empty(), buttons);
  13113. if (activeEl !== undefined) {
  13114. $(host).find('[data-dt-idx=' + activeEl + ']').focus();
  13115. }
  13116. }
  13117. }
  13118. });
  13119. // Built in type detection. See model.ext.aTypes for information about
  13120. // what is required from this methods.
  13121. $.extend(DataTable.ext.type.detect, [
  13122. // Plain numbers - first since V8 detects some plain numbers as dates
  13123. // e.g. Date.parse('55') (but not all, e.g. Date.parse('22')...).
  13124. function (d, settings) {
  13125. var decimal = settings.oLanguage.sDecimal;
  13126. return _isNumber(d, decimal) ? 'num' + decimal : null;
  13127. },
  13128. // Dates (only those recognised by the browser's Date.parse)
  13129. function (d, settings) {
  13130. // V8 tries _very_ hard to make a string passed into `Date.parse()`
  13131. // valid, so we need to use a regex to restrict date formats. Use a
  13132. // plug-in for anything other than ISO8601 style strings
  13133. if (d && !(d instanceof Date) && !_re_date.test(d)) {
  13134. return null;
  13135. }
  13136. var parsed = Date.parse(d);
  13137. return parsed !== null && !isNaN(parsed) || _empty(d) ? 'date' : null;
  13138. },
  13139. // Formatted numbers
  13140. function (d, settings) {
  13141. var decimal = settings.oLanguage.sDecimal;
  13142. return _isNumber(d, decimal, true) ? 'num-fmt' + decimal : null;
  13143. },
  13144. // HTML numeric
  13145. function (d, settings) {
  13146. var decimal = settings.oLanguage.sDecimal;
  13147. return _htmlNumeric(d, decimal) ? 'html-num' + decimal : null;
  13148. },
  13149. // HTML numeric, formatted
  13150. function (d, settings) {
  13151. var decimal = settings.oLanguage.sDecimal;
  13152. return _htmlNumeric(d, decimal, true) ? 'html-num-fmt' + decimal : null;
  13153. },
  13154. // HTML (this is strict checking - there must be html)
  13155. function (d, settings) {
  13156. return _empty(d) || typeof d === 'string' && d.indexOf('<') !== -1 ? 'html' : null;
  13157. }]);
  13158. // Filter formatting functions. See model.ext.ofnSearch for information about
  13159. // what is required from these methods.
  13160. //
  13161. // Note that additional search methods are added for the html numbers and
  13162. // html formatted numbers by `_addNumericSort()` when we know what the decimal
  13163. // place is
  13164. $.extend(DataTable.ext.type.search, {
  13165. html: function html(data) {
  13166. return _empty(data) ? data : typeof data === 'string' ? data.replace(_re_new_lines, " ").replace(_re_html, "") : '';
  13167. },
  13168. string: function string(data) {
  13169. return _empty(data) ? data : typeof data === 'string' ? data.replace(_re_new_lines, " ") : data;
  13170. }
  13171. });
  13172. var __numericReplace = function __numericReplace(d, decimalPlace, re1, re2) {
  13173. if (d !== 0 && (!d || d === '-')) {
  13174. return -Infinity;
  13175. }
  13176. // If a decimal place other than `.` is used, it needs to be given to the
  13177. // function so we can detect it and replace with a `.` which is the only
  13178. // decimal place Javascript recognises - it is not locale aware.
  13179. if (decimalPlace) {
  13180. d = _numToDecimal(d, decimalPlace);
  13181. }
  13182. if (d.replace) {
  13183. if (re1) {
  13184. d = d.replace(re1, '');
  13185. }
  13186. if (re2) {
  13187. d = d.replace(re2, '');
  13188. }
  13189. }
  13190. return d * 1;
  13191. };
  13192. // Add the numeric 'deformatting' functions for sorting and search. This is done
  13193. // in a function to provide an easy ability for the language options to add
  13194. // additional methods if a non-period decimal place is used.
  13195. function _addNumericSort(decimalPlace) {
  13196. $.each({
  13197. // Plain numbers
  13198. "num": function num(d) {
  13199. return __numericReplace(d, decimalPlace);
  13200. },
  13201. // Formatted numbers
  13202. "num-fmt": function numFmt(d) {
  13203. return __numericReplace(d, decimalPlace, _re_formatted_numeric);
  13204. },
  13205. // HTML numeric
  13206. "html-num": function htmlNum(d) {
  13207. return __numericReplace(d, decimalPlace, _re_html);
  13208. },
  13209. // HTML numeric, formatted
  13210. "html-num-fmt": function htmlNumFmt(d) {
  13211. return __numericReplace(d, decimalPlace, _re_html, _re_formatted_numeric);
  13212. }
  13213. }, function (key, fn) {
  13214. // Add the ordering method
  13215. _ext.type.order[key + decimalPlace + '-pre'] = fn;
  13216. // For HTML types add a search formatter that will strip the HTML
  13217. if (key.match(/^html\-/)) {
  13218. _ext.type.search[key + decimalPlace] = _ext.type.search.html;
  13219. }
  13220. });
  13221. }
  13222. // Default sort methods
  13223. $.extend(_ext.type.order, {
  13224. // Dates
  13225. "date-pre": function datePre(d) {
  13226. return Date.parse(d) || -Infinity;
  13227. },
  13228. // html
  13229. "html-pre": function htmlPre(a) {
  13230. return _empty(a) ? '' : a.replace ? a.replace(/<.*?>/g, "").toLowerCase() : a + '';
  13231. },
  13232. // string
  13233. "string-pre": function stringPre(a) {
  13234. // This is a little complex, but faster than always calling toString,
  13235. // http://jsperf.com/tostring-v-check
  13236. return _empty(a) ? '' : typeof a === 'string' ? a.toLowerCase() : !a.toString ? '' : a.toString();
  13237. },
  13238. // string-asc and -desc are retained only for compatibility with the old
  13239. // sort methods
  13240. "string-asc": function stringAsc(x, y) {
  13241. return x < y ? -1 : x > y ? 1 : 0;
  13242. },
  13243. "string-desc": function stringDesc(x, y) {
  13244. return x < y ? 1 : x > y ? -1 : 0;
  13245. }
  13246. });
  13247. // Numeric sorting types - order doesn't matter here
  13248. _addNumericSort('');
  13249. $.extend(true, DataTable.ext.renderer, {
  13250. header: {
  13251. _: function _(settings, cell, column, classes) {
  13252. // No additional mark-up required
  13253. // Attach a sort listener to update on sort - note that using the
  13254. // `DT` namespace will allow the event to be removed automatically
  13255. // on destroy, while the `dt` namespaced event is the one we are
  13256. // listening for
  13257. $(settings.nTable).on('order.dt.DT', function (e, ctx, sorting, columns) {
  13258. if (settings !== ctx) {
  13259. // need to check this this is the host
  13260. return; // table, not a nested one
  13261. }
  13262. var colIdx = column.idx;
  13263. cell.removeClass(column.sSortingClass + ' ' + classes.sSortAsc + ' ' + classes.sSortDesc).addClass(columns[colIdx] == 'asc' ? classes.sSortAsc : columns[colIdx] == 'desc' ? classes.sSortDesc : column.sSortingClass);
  13264. });
  13265. },
  13266. jqueryui: function jqueryui(settings, cell, column, classes) {
  13267. $('<div/>').addClass(classes.sSortJUIWrapper).append(cell.contents()).append($('<span/>').addClass(classes.sSortIcon + ' ' + column.sSortingClassJUI)).appendTo(cell);
  13268. // Attach a sort listener to update on sort
  13269. $(settings.nTable).on('order.dt.DT', function (e, ctx, sorting, columns) {
  13270. if (settings !== ctx) {
  13271. return;
  13272. }
  13273. var colIdx = column.idx;
  13274. cell.removeClass(classes.sSortAsc + " " + classes.sSortDesc).addClass(columns[colIdx] == 'asc' ? classes.sSortAsc : columns[colIdx] == 'desc' ? classes.sSortDesc : column.sSortingClass);
  13275. cell.find('span.' + classes.sSortIcon).removeClass(classes.sSortJUIAsc + " " + classes.sSortJUIDesc + " " + classes.sSortJUI + " " + classes.sSortJUIAscAllowed + " " + classes.sSortJUIDescAllowed).addClass(columns[colIdx] == 'asc' ? classes.sSortJUIAsc : columns[colIdx] == 'desc' ? classes.sSortJUIDesc : column.sSortingClassJUI);
  13276. });
  13277. }
  13278. }
  13279. });
  13280. /*
  13281. * Public helper functions. These aren't used internally by DataTables, or
  13282. * called by any of the options passed into DataTables, but they can be used
  13283. * externally by developers working with DataTables. They are helper functions
  13284. * to make working with DataTables a little bit easier.
  13285. */
  13286. var __htmlEscapeEntities = function __htmlEscapeEntities(d) {
  13287. return typeof d === 'string' ? d.replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') : d;
  13288. };
  13289. /**
  13290. * Helpers for `columns.render`.
  13291. *
  13292. * The options defined here can be used with the `columns.render` initialisation
  13293. * option to provide a display renderer. The following functions are defined:
  13294. *
  13295. * * `number` - Will format numeric data (defined by `columns.data`) for
  13296. * display, retaining the original unformatted data for sorting and filtering.
  13297. * It takes 5 parameters:
  13298. * * `string` - Thousands grouping separator
  13299. * * `string` - Decimal point indicator
  13300. * * `integer` - Number of decimal points to show
  13301. * * `string` (optional) - Prefix.
  13302. * * `string` (optional) - Postfix (/suffix).
  13303. * * `text` - Escape HTML to help prevent XSS attacks. It has no optional
  13304. * parameters.
  13305. *
  13306. * @example
  13307. * // Column definition using the number renderer
  13308. * {
  13309. * data: "salary",
  13310. * render: $.fn.dataTable.render.number( '\'', '.', 0, '$' )
  13311. * }
  13312. *
  13313. * @namespace
  13314. */
  13315. DataTable.render = {
  13316. number: function number(thousands, decimal, precision, prefix, postfix) {
  13317. return {
  13318. display: function display(d) {
  13319. if (typeof d !== 'number' && typeof d !== 'string') {
  13320. return d;
  13321. }
  13322. var negative = d < 0 ? '-' : '';
  13323. var flo = parseFloat(d);
  13324. // If NaN then there isn't much formatting that we can do - just
  13325. // return immediately, escaping any HTML (this was supposed to
  13326. // be a number after all)
  13327. if (isNaN(flo)) {
  13328. return __htmlEscapeEntities(d);
  13329. }
  13330. flo = flo.toFixed(precision);
  13331. d = Math.abs(flo);
  13332. var intPart = parseInt(d, 10);
  13333. var floatPart = precision ? decimal + (d - intPart).toFixed(precision).substring(2) : '';
  13334. return negative + (prefix || '') + intPart.toString().replace(/\B(?=(\d{3})+(?!\d))/g, thousands) + floatPart + (postfix || '');
  13335. }
  13336. };
  13337. },
  13338. text: function text() {
  13339. return {
  13340. display: __htmlEscapeEntities
  13341. };
  13342. }
  13343. };
  13344. /*
  13345. * This is really a good bit rubbish this method of exposing the internal methods
  13346. * publicly... - To be fixed in 2.0 using methods on the prototype
  13347. */
  13348. /**
  13349. * Create a wrapper function for exporting an internal functions to an external API.
  13350. * @param {string} fn API function name
  13351. * @returns {function} wrapped function
  13352. * @memberof DataTable#internal
  13353. */
  13354. function _fnExternApiFunc(fn) {
  13355. return function () {
  13356. var args = [_fnSettingsFromNode(this[DataTable.ext.iApiIndex])].concat(Array.prototype.slice.call(arguments));
  13357. return DataTable.ext.internal[fn].apply(this, args);
  13358. };
  13359. }
  13360. /**
  13361. * Reference to internal functions for use by plug-in developers. Note that
  13362. * these methods are references to internal functions and are considered to be
  13363. * private. If you use these methods, be aware that they are liable to change
  13364. * between versions.
  13365. * @namespace
  13366. */
  13367. $.extend(DataTable.ext.internal, {
  13368. _fnExternApiFunc: _fnExternApiFunc,
  13369. _fnBuildAjax: _fnBuildAjax,
  13370. _fnAjaxUpdate: _fnAjaxUpdate,
  13371. _fnAjaxParameters: _fnAjaxParameters,
  13372. _fnAjaxUpdateDraw: _fnAjaxUpdateDraw,
  13373. _fnAjaxDataSrc: _fnAjaxDataSrc,
  13374. _fnAddColumn: _fnAddColumn,
  13375. _fnColumnOptions: _fnColumnOptions,
  13376. _fnAdjustColumnSizing: _fnAdjustColumnSizing,
  13377. _fnVisibleToColumnIndex: _fnVisibleToColumnIndex,
  13378. _fnColumnIndexToVisible: _fnColumnIndexToVisible,
  13379. _fnVisbleColumns: _fnVisbleColumns,
  13380. _fnGetColumns: _fnGetColumns,
  13381. _fnColumnTypes: _fnColumnTypes,
  13382. _fnApplyColumnDefs: _fnApplyColumnDefs,
  13383. _fnHungarianMap: _fnHungarianMap,
  13384. _fnCamelToHungarian: _fnCamelToHungarian,
  13385. _fnLanguageCompat: _fnLanguageCompat,
  13386. _fnBrowserDetect: _fnBrowserDetect,
  13387. _fnAddData: _fnAddData,
  13388. _fnAddTr: _fnAddTr,
  13389. _fnNodeToDataIndex: _fnNodeToDataIndex,
  13390. _fnNodeToColumnIndex: _fnNodeToColumnIndex,
  13391. _fnGetCellData: _fnGetCellData,
  13392. _fnSetCellData: _fnSetCellData,
  13393. _fnSplitObjNotation: _fnSplitObjNotation,
  13394. _fnGetObjectDataFn: _fnGetObjectDataFn,
  13395. _fnSetObjectDataFn: _fnSetObjectDataFn,
  13396. _fnGetDataMaster: _fnGetDataMaster,
  13397. _fnClearTable: _fnClearTable,
  13398. _fnDeleteIndex: _fnDeleteIndex,
  13399. _fnInvalidate: _fnInvalidate,
  13400. _fnGetRowElements: _fnGetRowElements,
  13401. _fnCreateTr: _fnCreateTr,
  13402. _fnBuildHead: _fnBuildHead,
  13403. _fnDrawHead: _fnDrawHead,
  13404. _fnDraw: _fnDraw,
  13405. _fnReDraw: _fnReDraw,
  13406. _fnAddOptionsHtml: _fnAddOptionsHtml,
  13407. _fnDetectHeader: _fnDetectHeader,
  13408. _fnGetUniqueThs: _fnGetUniqueThs,
  13409. _fnFeatureHtmlFilter: _fnFeatureHtmlFilter,
  13410. _fnFilterComplete: _fnFilterComplete,
  13411. _fnFilterCustom: _fnFilterCustom,
  13412. _fnFilterColumn: _fnFilterColumn,
  13413. _fnFilter: _fnFilter,
  13414. _fnFilterCreateSearch: _fnFilterCreateSearch,
  13415. _fnEscapeRegex: _fnEscapeRegex,
  13416. _fnFilterData: _fnFilterData,
  13417. _fnFeatureHtmlInfo: _fnFeatureHtmlInfo,
  13418. _fnUpdateInfo: _fnUpdateInfo,
  13419. _fnInfoMacros: _fnInfoMacros,
  13420. _fnInitialise: _fnInitialise,
  13421. _fnInitComplete: _fnInitComplete,
  13422. _fnLengthChange: _fnLengthChange,
  13423. _fnFeatureHtmlLength: _fnFeatureHtmlLength,
  13424. _fnFeatureHtmlPaginate: _fnFeatureHtmlPaginate,
  13425. _fnPageChange: _fnPageChange,
  13426. _fnFeatureHtmlProcessing: _fnFeatureHtmlProcessing,
  13427. _fnProcessingDisplay: _fnProcessingDisplay,
  13428. _fnFeatureHtmlTable: _fnFeatureHtmlTable,
  13429. _fnScrollDraw: _fnScrollDraw,
  13430. _fnApplyToChildren: _fnApplyToChildren,
  13431. _fnCalculateColumnWidths: _fnCalculateColumnWidths,
  13432. _fnThrottle: _fnThrottle,
  13433. _fnConvertToWidth: _fnConvertToWidth,
  13434. _fnGetWidestNode: _fnGetWidestNode,
  13435. _fnGetMaxLenString: _fnGetMaxLenString,
  13436. _fnStringToCss: _fnStringToCss,
  13437. _fnSortFlatten: _fnSortFlatten,
  13438. _fnSort: _fnSort,
  13439. _fnSortAria: _fnSortAria,
  13440. _fnSortListener: _fnSortListener,
  13441. _fnSortAttachListener: _fnSortAttachListener,
  13442. _fnSortingClasses: _fnSortingClasses,
  13443. _fnSortData: _fnSortData,
  13444. _fnSaveState: _fnSaveState,
  13445. _fnLoadState: _fnLoadState,
  13446. _fnSettingsFromNode: _fnSettingsFromNode,
  13447. _fnLog: _fnLog,
  13448. _fnMap: _fnMap,
  13449. _fnBindAction: _fnBindAction,
  13450. _fnCallbackReg: _fnCallbackReg,
  13451. _fnCallbackFire: _fnCallbackFire,
  13452. _fnLengthOverflow: _fnLengthOverflow,
  13453. _fnRenderer: _fnRenderer,
  13454. _fnDataSource: _fnDataSource,
  13455. _fnRowAttributes: _fnRowAttributes,
  13456. _fnCalculateEnd: function _fnCalculateEnd() {} // Used by a lot of plug-ins, but redundant
  13457. // in 1.10, so this dead-end function is
  13458. // added to prevent errors
  13459. });
  13460. // jQuery access
  13461. $.fn.dataTable = DataTable;
  13462. // Provide access to the host jQuery object (circular reference)
  13463. DataTable.$ = $;
  13464. // Legacy aliases
  13465. $.fn.dataTableSettings = DataTable.settings;
  13466. $.fn.dataTableExt = DataTable.ext;
  13467. // With a capital `D` we return a DataTables API instance rather than a
  13468. // jQuery object
  13469. $.fn.DataTable = function (opts) {
  13470. return $(this).dataTable(opts).api();
  13471. };
  13472. // All properties that are available to $.fn.dataTable should also be
  13473. // available on $.fn.DataTable
  13474. $.each(DataTable, function (prop, val) {
  13475. $.fn.DataTable[prop] = val;
  13476. });
  13477. // Information about events fired by DataTables - for documentation.
  13478. /**
  13479. * Draw event, fired whenever the table is redrawn on the page, at the same
  13480. * point as fnDrawCallback. This may be useful for binding events or
  13481. * performing calculations when the table is altered at all.
  13482. * @name DataTable#draw.dt
  13483. * @event
  13484. * @param {event} e jQuery event object
  13485. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13486. */
  13487. /**
  13488. * Search event, fired when the searching applied to the table (using the
  13489. * built-in global search, or column filters) is altered.
  13490. * @name DataTable#search.dt
  13491. * @event
  13492. * @param {event} e jQuery event object
  13493. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13494. */
  13495. /**
  13496. * Page change event, fired when the paging of the table is altered.
  13497. * @name DataTable#page.dt
  13498. * @event
  13499. * @param {event} e jQuery event object
  13500. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13501. */
  13502. /**
  13503. * Order event, fired when the ordering applied to the table is altered.
  13504. * @name DataTable#order.dt
  13505. * @event
  13506. * @param {event} e jQuery event object
  13507. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13508. */
  13509. /**
  13510. * DataTables initialisation complete event, fired when the table is fully
  13511. * drawn, including Ajax data loaded, if Ajax data is required.
  13512. * @name DataTable#init.dt
  13513. * @event
  13514. * @param {event} e jQuery event object
  13515. * @param {object} oSettings DataTables settings object
  13516. * @param {object} json The JSON object request from the server - only
  13517. * present if client-side Ajax sourced data is used</li></ol>
  13518. */
  13519. /**
  13520. * State save event, fired when the table has changed state a new state save
  13521. * is required. This event allows modification of the state saving object
  13522. * prior to actually doing the save, including addition or other state
  13523. * properties (for plug-ins) or modification of a DataTables core property.
  13524. * @name DataTable#stateSaveParams.dt
  13525. * @event
  13526. * @param {event} e jQuery event object
  13527. * @param {object} oSettings DataTables settings object
  13528. * @param {object} json The state information to be saved
  13529. */
  13530. /**
  13531. * State load event, fired when the table is loading state from the stored
  13532. * data, but prior to the settings object being modified by the saved state
  13533. * - allowing modification of the saved state is required or loading of
  13534. * state for a plug-in.
  13535. * @name DataTable#stateLoadParams.dt
  13536. * @event
  13537. * @param {event} e jQuery event object
  13538. * @param {object} oSettings DataTables settings object
  13539. * @param {object} json The saved state information
  13540. */
  13541. /**
  13542. * State loaded event, fired when state has been loaded from stored data and
  13543. * the settings object has been modified by the loaded data.
  13544. * @name DataTable#stateLoaded.dt
  13545. * @event
  13546. * @param {event} e jQuery event object
  13547. * @param {object} oSettings DataTables settings object
  13548. * @param {object} json The saved state information
  13549. */
  13550. /**
  13551. * Processing event, fired when DataTables is doing some kind of processing
  13552. * (be it, order, searcg or anything else). It can be used to indicate to
  13553. * the end user that there is something happening, or that something has
  13554. * finished.
  13555. * @name DataTable#processing.dt
  13556. * @event
  13557. * @param {event} e jQuery event object
  13558. * @param {object} oSettings DataTables settings object
  13559. * @param {boolean} bShow Flag for if DataTables is doing processing or not
  13560. */
  13561. /**
  13562. * Ajax (XHR) event, fired whenever an Ajax request is completed from a
  13563. * request to made to the server for new data. This event is called before
  13564. * DataTables processed the returned data, so it can also be used to pre-
  13565. * process the data returned from the server, if needed.
  13566. *
  13567. * Note that this trigger is called in `fnServerData`, if you override
  13568. * `fnServerData` and which to use this event, you need to trigger it in you
  13569. * success function.
  13570. * @name DataTable#xhr.dt
  13571. * @event
  13572. * @param {event} e jQuery event object
  13573. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13574. * @param {object} json JSON returned from the server
  13575. *
  13576. * @example
  13577. * // Use a custom property returned from the server in another DOM element
  13578. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  13579. * $('#status').html( json.status );
  13580. * } );
  13581. *
  13582. * @example
  13583. * // Pre-process the data returned from the server
  13584. * $('#table').dataTable().on('xhr.dt', function (e, settings, json) {
  13585. * for ( var i=0, ien=json.aaData.length ; i<ien ; i++ ) {
  13586. * json.aaData[i].sum = json.aaData[i].one + json.aaData[i].two;
  13587. * }
  13588. * // Note no return - manipulate the data directly in the JSON object.
  13589. * } );
  13590. */
  13591. /**
  13592. * Destroy event, fired when the DataTable is destroyed by calling fnDestroy
  13593. * or passing the bDestroy:true parameter in the initialisation object. This
  13594. * can be used to remove bound events, added DOM nodes, etc.
  13595. * @name DataTable#destroy.dt
  13596. * @event
  13597. * @param {event} e jQuery event object
  13598. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13599. */
  13600. /**
  13601. * Page length change event, fired when number of records to show on each
  13602. * page (the length) is changed.
  13603. * @name DataTable#length.dt
  13604. * @event
  13605. * @param {event} e jQuery event object
  13606. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13607. * @param {integer} len New length
  13608. */
  13609. /**
  13610. * Column sizing has changed.
  13611. * @name DataTable#column-sizing.dt
  13612. * @event
  13613. * @param {event} e jQuery event object
  13614. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13615. */
  13616. /**
  13617. * Column visibility has changed.
  13618. * @name DataTable#column-visibility.dt
  13619. * @event
  13620. * @param {event} e jQuery event object
  13621. * @param {object} o DataTables settings object {@link DataTable.models.oSettings}
  13622. * @param {int} column Column index
  13623. * @param {bool} vis `false` if column now hidden, or `true` if visible
  13624. */
  13625. return $.fn.dataTable;
  13626. });
  13627. /***/ }),
  13628. /***/ 40:
  13629. /***/ (function(module, exports, __webpack_require__) {
  13630. module.exports = __webpack_require__(7);
  13631. /***/ }),
  13632. /***/ 7:
  13633. /***/ (function(module, exports, __webpack_require__) {
  13634. "use strict";
  13635. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  13636. var _datatables = __webpack_require__(2);
  13637. var _datatables2 = _interopRequireDefault(_datatables);
  13638. __webpack_require__(9);
  13639. __webpack_require__(10);
  13640. var _util = __webpack_require__(0);
  13641. var _util2 = _interopRequireDefault(_util);
  13642. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13643. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  13644. var SELECTORS = {
  13645. table: '[data-data-table]',
  13646. container: '[data-table-container]',
  13647. preloader: '[data-table-preloader]',
  13648. showAll: '[data-show-all]',
  13649. showAllIcon: '[data-show-all-icon]'
  13650. };
  13651. var Default = {
  13652. activeElement: 2,
  13653. filterActiveClass: '.is-active',
  13654. transition: 'all 500ms cubic-bezier(.250, .250, .000, 1.015)',
  13655. pageLenght: 10,
  13656. domPattern: '<t><"t-c__footer table-footer"p B>',
  13657. noSortClass: 'no-sort',
  13658. hiddenClass: 'hidden'
  13659. };
  13660. var templates = {};
  13661. var DataTableInit = function () {
  13662. function DataTableInit(table, options) {
  13663. _classCallCheck(this, DataTableInit);
  13664. this.table = $(table);
  13665. this.options = options;
  13666. this.container = this.table.closest(SELECTORS.container);
  13667. this.preloader = this.container.find(SELECTORS.preloader);
  13668. this.getConfig();
  13669. this.initPlugin();
  13670. this.bindEvents();
  13671. }
  13672. _createClass(DataTableInit, [{
  13673. key: 'getConfig',
  13674. value: function getConfig() {
  13675. var dataConfig = this.table.data();
  13676. if (dataConfig.options) {
  13677. this.dataOptions = _util2.default.parseDataOptions(dataConfig.options);
  13678. } else {
  13679. this.dataOptions = {};
  13680. }
  13681. this.config = $.extend({}, Default, dataConfig, this.dataOptions, this.options);
  13682. }
  13683. }, {
  13684. key: 'bindEvents',
  13685. value: function bindEvents() {}
  13686. }, {
  13687. key: 'initPlugin',
  13688. value: function initPlugin() {
  13689. var that = this;
  13690. this.dataTable = this.table.dataTable({
  13691. "dom": this.config.domPattern,
  13692. "order": [[0, "asc"]],
  13693. "autoWidth": false,
  13694. "pageLength": this.config.pageLenght,
  13695. "responsive": {
  13696. details: {
  13697. type: 'column',
  13698. target: '[data-show-all]',
  13699. renderer: function renderer(api, rowIdx, columns) {
  13700. columns.shift();
  13701. columns.pop();
  13702. var data = $.map(columns, function (col, i) {
  13703. return col.hidden ? '\n <li>\n <strong>' + col.title + '</strong>' + col.data + '\n </li> \n ' : '';
  13704. }).join('');
  13705. data = ' \n <ul class="child-table"> \n ' + data + ' \n </ul> \n ';
  13706. return data ? data : false;
  13707. }
  13708. }
  13709. },
  13710. "language": {
  13711. "paginate": {
  13712. "previous": "",
  13713. "next": ""
  13714. }
  13715. },
  13716. "columnDefs": [{
  13717. "targets": 'no-sort',
  13718. "orderable": false
  13719. }, {
  13720. "targets": 'filter',
  13721. "name": 'filter'
  13722. }, { responsivePriority: 0, targets: -1 }],
  13723. buttons: [{
  13724. text: '10',
  13725. action: function action(e, dt, node, config) {
  13726. dt.page.len(10).draw();
  13727. $(node).parent().find('.active').removeClass('active');
  13728. $(node).addClass('active');
  13729. },
  13730. init: function init(dt, node, config) {
  13731. $(node).addClass('active');
  13732. }
  13733. }, {
  13734. text: '25',
  13735. action: function action(e, dt, node, config) {
  13736. dt.page.len(25).draw();
  13737. $(node).parent().find('.active').removeClass('active');
  13738. $(node).addClass('active');
  13739. }
  13740. }, {
  13741. text: '∞',
  13742. action: function action(e, dt, node, config) {
  13743. dt.page.len(1000).draw();
  13744. $(node).parent().find('.active').removeClass('active');
  13745. $(node).addClass('active');
  13746. }
  13747. }],
  13748. 'drawCallback': function drawCallback() {},
  13749. 'initComplete': function initComplete() {
  13750. that.togglePreloader(this.api());
  13751. window.testapi = this.api();
  13752. }
  13753. });
  13754. this.customSearch();
  13755. }
  13756. }, {
  13757. key: 'customSearch',
  13758. value: function customSearch() {
  13759. var _this = this;
  13760. if (!this.config.tableSearch) {
  13761. return;
  13762. }
  13763. var searchInput = $(this.config.tableSearch);
  13764. searchInput.on('keyup', function (event) {
  13765. _this.dataTable.search('\\b' + event.target.value, true).draw();
  13766. });
  13767. }
  13768. }, {
  13769. key: 'togglePreloader',
  13770. value: function togglePreloader(api) {
  13771. setTimeout(function () {
  13772. api.responsive.recalc();
  13773. }, 1000);
  13774. this.preloader.addClass(this.config.hiddenClass);
  13775. this.table.removeClass(this.config.hiddenClass);
  13776. }
  13777. }]);
  13778. return DataTableInit;
  13779. }();
  13780. function initDataSelectors() {
  13781. $(SELECTORS.table).each(function () {
  13782. new DataTableInit($(this));
  13783. });
  13784. }
  13785. function initJqueryPlugin() {
  13786. $.fn.luDataTable = function (options) {
  13787. return this.each(function () {
  13788. new DataTableInit($(this), options);
  13789. });
  13790. };
  13791. }
  13792. var init = {
  13793. initDataSelectors: initDataSelectors,
  13794. initJqueryPlugin: initJqueryPlugin
  13795. };
  13796. $(document).ready(function () {
  13797. init.initDataSelectors();
  13798. init.initJqueryPlugin();
  13799. });
  13800. /***/ }),
  13801. /***/ 9:
  13802. /***/ (function(module, exports, __webpack_require__) {
  13803. "use strict";
  13804. var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;
  13805. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  13806. /*! Buttons for DataTables 1.4.2
  13807. * ©2016-2017 SpryMedia Ltd - datatables.net/license
  13808. */
  13809. (function (factory) {
  13810. if (true) {
  13811. // AMD
  13812. !(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1), __webpack_require__(2)], __WEBPACK_AMD_DEFINE_RESULT__ = function ($) {
  13813. return factory($, window, document);
  13814. }.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__),
  13815. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  13816. } else if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object') {
  13817. // CommonJS
  13818. module.exports = function (root, $) {
  13819. if (!root) {
  13820. root = window;
  13821. }
  13822. if (!$ || !$.fn.dataTable) {
  13823. $ = require('datatables.net')(root, $).$;
  13824. }
  13825. return factory($, root, root.document);
  13826. };
  13827. } else {
  13828. // Browser
  13829. factory(jQuery, window, document);
  13830. }
  13831. })(function ($, window, document, undefined) {
  13832. 'use strict';
  13833. var DataTable = $.fn.dataTable;
  13834. // Used for namespacing events added to the document by each instance, so they
  13835. // can be removed on destroy
  13836. var _instCounter = 0;
  13837. // Button namespacing counter for namespacing events on individual buttons
  13838. var _buttonCounter = 0;
  13839. var _dtButtons = DataTable.ext.buttons;
  13840. /**
  13841. * [Buttons description]
  13842. * @param {[type]}
  13843. * @param {[type]}
  13844. */
  13845. var Buttons = function Buttons(dt, config) {
  13846. // If there is no config set it to an empty object
  13847. if (typeof config === 'undefined') {
  13848. config = {};
  13849. }
  13850. // Allow a boolean true for defaults
  13851. if (config === true) {
  13852. config = {};
  13853. }
  13854. // For easy configuration of buttons an array can be given
  13855. if ($.isArray(config)) {
  13856. config = { buttons: config };
  13857. }
  13858. this.c = $.extend(true, {}, Buttons.defaults, config);
  13859. // Don't want a deep copy for the buttons
  13860. if (config.buttons) {
  13861. this.c.buttons = config.buttons;
  13862. }
  13863. this.s = {
  13864. dt: new DataTable.Api(dt),
  13865. buttons: [],
  13866. listenKeys: '',
  13867. namespace: 'dtb' + _instCounter++
  13868. };
  13869. this.dom = {
  13870. container: $('<' + this.c.dom.container.tag + '/>').addClass(this.c.dom.container.className)
  13871. };
  13872. this._constructor();
  13873. };
  13874. $.extend(Buttons.prototype, {
  13875. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  13876. * Public methods
  13877. */
  13878. /**
  13879. * Get the action of a button
  13880. * @param {int|string} Button index
  13881. * @return {function}
  13882. */ /**
  13883. * Set the action of a button
  13884. * @param {node} node Button element
  13885. * @param {function} action Function to set
  13886. * @return {Buttons} Self for chaining
  13887. */
  13888. action: function action(node, _action) {
  13889. var button = this._nodeToButton(node);
  13890. if (_action === undefined) {
  13891. return button.conf.action;
  13892. }
  13893. button.conf.action = _action;
  13894. return this;
  13895. },
  13896. /**
  13897. * Add an active class to the button to make to look active or get current
  13898. * active state.
  13899. * @param {node} node Button element
  13900. * @param {boolean} [flag] Enable / disable flag
  13901. * @return {Buttons} Self for chaining or boolean for getter
  13902. */
  13903. active: function active(node, flag) {
  13904. var button = this._nodeToButton(node);
  13905. var klass = this.c.dom.button.active;
  13906. var jqNode = $(button.node);
  13907. if (flag === undefined) {
  13908. return jqNode.hasClass(klass);
  13909. }
  13910. jqNode.toggleClass(klass, flag === undefined ? true : flag);
  13911. return this;
  13912. },
  13913. /**
  13914. * Add a new button
  13915. * @param {object} config Button configuration object, base string name or function
  13916. * @param {int|string} [idx] Button index for where to insert the button
  13917. * @return {Buttons} Self for chaining
  13918. */
  13919. add: function add(config, idx) {
  13920. var buttons = this.s.buttons;
  13921. if (typeof idx === 'string') {
  13922. var split = idx.split('-');
  13923. var base = this.s;
  13924. for (var i = 0, ien = split.length - 1; i < ien; i++) {
  13925. base = base.buttons[split[i] * 1];
  13926. }
  13927. buttons = base.buttons;
  13928. idx = split[split.length - 1] * 1;
  13929. }
  13930. this._expandButton(buttons, config, false, idx);
  13931. this._draw();
  13932. return this;
  13933. },
  13934. /**
  13935. * Get the container node for the buttons
  13936. * @return {jQuery} Buttons node
  13937. */
  13938. container: function container() {
  13939. return this.dom.container;
  13940. },
  13941. /**
  13942. * Disable a button
  13943. * @param {node} node Button node
  13944. * @return {Buttons} Self for chaining
  13945. */
  13946. disable: function disable(node) {
  13947. var button = this._nodeToButton(node);
  13948. $(button.node).addClass(this.c.dom.button.disabled);
  13949. return this;
  13950. },
  13951. /**
  13952. * Destroy the instance, cleaning up event handlers and removing DOM
  13953. * elements
  13954. * @return {Buttons} Self for chaining
  13955. */
  13956. destroy: function destroy() {
  13957. // Key event listener
  13958. $('body').off('keyup.' + this.s.namespace);
  13959. // Individual button destroy (so they can remove their own events if
  13960. // needed). Take a copy as the array is modified by `remove`
  13961. var buttons = this.s.buttons.slice();
  13962. var i, ien;
  13963. for (i = 0, ien = buttons.length; i < ien; i++) {
  13964. this.remove(buttons[i].node);
  13965. }
  13966. // Container
  13967. this.dom.container.remove();
  13968. // Remove from the settings object collection
  13969. var buttonInsts = this.s.dt.settings()[0];
  13970. for (i = 0, ien = buttonInsts.length; i < ien; i++) {
  13971. if (buttonInsts.inst === this) {
  13972. buttonInsts.splice(i, 1);
  13973. break;
  13974. }
  13975. }
  13976. return this;
  13977. },
  13978. /**
  13979. * Enable / disable a button
  13980. * @param {node} node Button node
  13981. * @param {boolean} [flag=true] Enable / disable flag
  13982. * @return {Buttons} Self for chaining
  13983. */
  13984. enable: function enable(node, flag) {
  13985. if (flag === false) {
  13986. return this.disable(node);
  13987. }
  13988. var button = this._nodeToButton(node);
  13989. $(button.node).removeClass(this.c.dom.button.disabled);
  13990. return this;
  13991. },
  13992. /**
  13993. * Get the instance name for the button set selector
  13994. * @return {string} Instance name
  13995. */
  13996. name: function name() {
  13997. return this.c.name;
  13998. },
  13999. /**
  14000. * Get a button's node
  14001. * @param {node} node Button node
  14002. * @return {jQuery} Button element
  14003. */
  14004. node: function node(_node) {
  14005. var button = this._nodeToButton(_node);
  14006. return $(button.node);
  14007. },
  14008. /**
  14009. * Set / get a processing class on the selected button
  14010. * @param {boolean} flag true to add, false to remove, undefined to get
  14011. * @return {boolean|Buttons} Getter value or this if a setter.
  14012. */
  14013. processing: function processing(node, flag) {
  14014. var button = this._nodeToButton(node);
  14015. if (flag === undefined) {
  14016. return $(button.node).hasClass('processing');
  14017. }
  14018. $(button.node).toggleClass('processing', flag);
  14019. return this;
  14020. },
  14021. /**
  14022. * Remove a button.
  14023. * @param {node} node Button node
  14024. * @return {Buttons} Self for chaining
  14025. */
  14026. remove: function remove(node) {
  14027. var button = this._nodeToButton(node);
  14028. var host = this._nodeToHost(node);
  14029. var dt = this.s.dt;
  14030. // Remove any child buttons first
  14031. if (button.buttons.length) {
  14032. for (var i = button.buttons.length - 1; i >= 0; i--) {
  14033. this.remove(button.buttons[i].node);
  14034. }
  14035. }
  14036. // Allow the button to remove event handlers, etc
  14037. if (button.conf.destroy) {
  14038. button.conf.destroy.call(dt.button(node), dt, $(node), button.conf);
  14039. }
  14040. this._removeKey(button.conf);
  14041. $(button.node).remove();
  14042. var idx = $.inArray(button, host);
  14043. host.splice(idx, 1);
  14044. return this;
  14045. },
  14046. /**
  14047. * Get the text for a button
  14048. * @param {int|string} node Button index
  14049. * @return {string} Button text
  14050. */ /**
  14051. * Set the text for a button
  14052. * @param {int|string|function} node Button index
  14053. * @param {string} label Text
  14054. * @return {Buttons} Self for chaining
  14055. */
  14056. text: function text(node, label) {
  14057. var button = this._nodeToButton(node);
  14058. var buttonLiner = this.c.dom.collection.buttonLiner;
  14059. var linerTag = button.inCollection && buttonLiner && buttonLiner.tag ? buttonLiner.tag : this.c.dom.buttonLiner.tag;
  14060. var dt = this.s.dt;
  14061. var jqNode = $(button.node);
  14062. var text = function text(opt) {
  14063. return typeof opt === 'function' ? opt(dt, jqNode, button.conf) : opt;
  14064. };
  14065. if (label === undefined) {
  14066. return text(button.conf.text);
  14067. }
  14068. button.conf.text = label;
  14069. if (linerTag) {
  14070. jqNode.children(linerTag).html(text(label));
  14071. } else {
  14072. jqNode.html(text(label));
  14073. }
  14074. return this;
  14075. },
  14076. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14077. * Constructor
  14078. */
  14079. /**
  14080. * Buttons constructor
  14081. * @private
  14082. */
  14083. _constructor: function _constructor() {
  14084. var that = this;
  14085. var dt = this.s.dt;
  14086. var dtSettings = dt.settings()[0];
  14087. var buttons = this.c.buttons;
  14088. if (!dtSettings._buttons) {
  14089. dtSettings._buttons = [];
  14090. }
  14091. dtSettings._buttons.push({
  14092. inst: this,
  14093. name: this.c.name
  14094. });
  14095. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14096. this.add(buttons[i]);
  14097. }
  14098. dt.on('destroy', function () {
  14099. that.destroy();
  14100. });
  14101. // Global key event binding to listen for button keys
  14102. $('body').on('keyup.' + this.s.namespace, function (e) {
  14103. if (!document.activeElement || document.activeElement === document.body) {
  14104. // SUse a string of characters for fast lookup of if we need to
  14105. // handle this
  14106. var character = String.fromCharCode(e.keyCode).toLowerCase();
  14107. if (that.s.listenKeys.toLowerCase().indexOf(character) !== -1) {
  14108. that._keypress(character, e);
  14109. }
  14110. }
  14111. });
  14112. },
  14113. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14114. * Private methods
  14115. */
  14116. /**
  14117. * Add a new button to the key press listener
  14118. * @param {object} conf Resolved button configuration object
  14119. * @private
  14120. */
  14121. _addKey: function _addKey(conf) {
  14122. if (conf.key) {
  14123. this.s.listenKeys += $.isPlainObject(conf.key) ? conf.key.key : conf.key;
  14124. }
  14125. },
  14126. /**
  14127. * Insert the buttons into the container. Call without parameters!
  14128. * @param {node} [container] Recursive only - Insert point
  14129. * @param {array} [buttons] Recursive only - Buttons array
  14130. * @private
  14131. */
  14132. _draw: function _draw(container, buttons) {
  14133. if (!container) {
  14134. container = this.dom.container;
  14135. buttons = this.s.buttons;
  14136. }
  14137. container.children().detach();
  14138. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14139. container.append(buttons[i].inserter);
  14140. container.append(' ');
  14141. if (buttons[i].buttons && buttons[i].buttons.length) {
  14142. this._draw(buttons[i].collection, buttons[i].buttons);
  14143. }
  14144. }
  14145. },
  14146. /**
  14147. * Create buttons from an array of buttons
  14148. * @param {array} attachTo Buttons array to attach to
  14149. * @param {object} button Button definition
  14150. * @param {boolean} inCollection true if the button is in a collection
  14151. * @private
  14152. */
  14153. _expandButton: function _expandButton(attachTo, button, inCollection, attachPoint) {
  14154. var dt = this.s.dt;
  14155. var buttonCounter = 0;
  14156. var buttons = !$.isArray(button) ? [button] : button;
  14157. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14158. var conf = this._resolveExtends(buttons[i]);
  14159. if (!conf) {
  14160. continue;
  14161. }
  14162. // If the configuration is an array, then expand the buttons at this
  14163. // point
  14164. if ($.isArray(conf)) {
  14165. this._expandButton(attachTo, conf, inCollection, attachPoint);
  14166. continue;
  14167. }
  14168. var built = this._buildButton(conf, inCollection);
  14169. if (!built) {
  14170. continue;
  14171. }
  14172. if (attachPoint !== undefined) {
  14173. attachTo.splice(attachPoint, 0, built);
  14174. attachPoint++;
  14175. } else {
  14176. attachTo.push(built);
  14177. }
  14178. if (built.conf.buttons) {
  14179. var collectionDom = this.c.dom.collection;
  14180. built.collection = $('<' + collectionDom.tag + '/>').addClass(collectionDom.className).attr('role', 'menu');
  14181. built.conf._collection = built.collection;
  14182. this._expandButton(built.buttons, built.conf.buttons, true, attachPoint);
  14183. }
  14184. // init call is made here, rather than buildButton as it needs to
  14185. // be selectable, and for that it needs to be in the buttons array
  14186. if (conf.init) {
  14187. conf.init.call(dt.button(built.node), dt, $(built.node), conf);
  14188. }
  14189. buttonCounter++;
  14190. }
  14191. },
  14192. /**
  14193. * Create an individual button
  14194. * @param {object} config Resolved button configuration
  14195. * @param {boolean} inCollection `true` if a collection button
  14196. * @return {jQuery} Created button node (jQuery)
  14197. * @private
  14198. */
  14199. _buildButton: function _buildButton(config, inCollection) {
  14200. var buttonDom = this.c.dom.button;
  14201. var linerDom = this.c.dom.buttonLiner;
  14202. var collectionDom = this.c.dom.collection;
  14203. var dt = this.s.dt;
  14204. var text = function text(opt) {
  14205. return typeof opt === 'function' ? opt(dt, button, config) : opt;
  14206. };
  14207. if (inCollection && collectionDom.button) {
  14208. buttonDom = collectionDom.button;
  14209. }
  14210. if (inCollection && collectionDom.buttonLiner) {
  14211. linerDom = collectionDom.buttonLiner;
  14212. }
  14213. // Make sure that the button is available based on whatever requirements
  14214. // it has. For example, Flash buttons require Flash
  14215. if (config.available && !config.available(dt, config)) {
  14216. return false;
  14217. }
  14218. var action = function action(e, dt, button, config) {
  14219. config.action.call(dt.button(button), e, dt, button, config);
  14220. $(dt.table().node()).triggerHandler('buttons-action.dt', [dt.button(button), dt, button, config]);
  14221. };
  14222. var button = $('<' + buttonDom.tag + '/>').addClass(buttonDom.className).attr('tabindex', this.s.dt.settings()[0].iTabIndex).attr('aria-controls', this.s.dt.table().node().id).on('click.dtb', function (e) {
  14223. e.preventDefault();
  14224. if (!button.hasClass(buttonDom.disabled) && config.action) {
  14225. action(e, dt, button, config);
  14226. }
  14227. button.blur();
  14228. }).on('keyup.dtb', function (e) {
  14229. if (e.keyCode === 13) {
  14230. if (!button.hasClass(buttonDom.disabled) && config.action) {
  14231. action(e, dt, button, config);
  14232. }
  14233. }
  14234. });
  14235. // Make `a` tags act like a link
  14236. if (buttonDom.tag.toLowerCase() === 'a') {
  14237. button.attr('href', '#');
  14238. }
  14239. if (linerDom.tag) {
  14240. var liner = $('<' + linerDom.tag + '/>').html(text(config.text)).addClass(linerDom.className);
  14241. if (linerDom.tag.toLowerCase() === 'a') {
  14242. liner.attr('href', '#');
  14243. }
  14244. button.append(liner);
  14245. } else {
  14246. button.html(text(config.text));
  14247. }
  14248. if (config.enabled === false) {
  14249. button.addClass(buttonDom.disabled);
  14250. }
  14251. if (config.className) {
  14252. button.addClass(config.className);
  14253. }
  14254. if (config.titleAttr) {
  14255. button.attr('title', text(config.titleAttr));
  14256. }
  14257. if (!config.namespace) {
  14258. config.namespace = '.dt-button-' + _buttonCounter++;
  14259. }
  14260. var buttonContainer = this.c.dom.buttonContainer;
  14261. var inserter;
  14262. if (buttonContainer && buttonContainer.tag) {
  14263. inserter = $('<' + buttonContainer.tag + '/>').addClass(buttonContainer.className).append(button);
  14264. } else {
  14265. inserter = button;
  14266. }
  14267. this._addKey(config);
  14268. return {
  14269. conf: config,
  14270. node: button.get(0),
  14271. inserter: inserter,
  14272. buttons: [],
  14273. inCollection: inCollection,
  14274. collection: null
  14275. };
  14276. },
  14277. /**
  14278. * Get the button object from a node (recursive)
  14279. * @param {node} node Button node
  14280. * @param {array} [buttons] Button array, uses base if not defined
  14281. * @return {object} Button object
  14282. * @private
  14283. */
  14284. _nodeToButton: function _nodeToButton(node, buttons) {
  14285. if (!buttons) {
  14286. buttons = this.s.buttons;
  14287. }
  14288. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14289. if (buttons[i].node === node) {
  14290. return buttons[i];
  14291. }
  14292. if (buttons[i].buttons.length) {
  14293. var ret = this._nodeToButton(node, buttons[i].buttons);
  14294. if (ret) {
  14295. return ret;
  14296. }
  14297. }
  14298. }
  14299. },
  14300. /**
  14301. * Get container array for a button from a button node (recursive)
  14302. * @param {node} node Button node
  14303. * @param {array} [buttons] Button array, uses base if not defined
  14304. * @return {array} Button's host array
  14305. * @private
  14306. */
  14307. _nodeToHost: function _nodeToHost(node, buttons) {
  14308. if (!buttons) {
  14309. buttons = this.s.buttons;
  14310. }
  14311. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14312. if (buttons[i].node === node) {
  14313. return buttons;
  14314. }
  14315. if (buttons[i].buttons.length) {
  14316. var ret = this._nodeToHost(node, buttons[i].buttons);
  14317. if (ret) {
  14318. return ret;
  14319. }
  14320. }
  14321. }
  14322. },
  14323. /**
  14324. * Handle a key press - determine if any button's key configured matches
  14325. * what was typed and trigger the action if so.
  14326. * @param {string} character The character pressed
  14327. * @param {object} e Key event that triggered this call
  14328. * @private
  14329. */
  14330. _keypress: function _keypress(character, e) {
  14331. var run = function run(conf, node) {
  14332. if (!conf.key) {
  14333. return;
  14334. }
  14335. if (conf.key === character) {
  14336. $(node).click();
  14337. } else if ($.isPlainObject(conf.key)) {
  14338. if (conf.key.key !== character) {
  14339. return;
  14340. }
  14341. if (conf.key.shiftKey && !e.shiftKey) {
  14342. return;
  14343. }
  14344. if (conf.key.altKey && !e.altKey) {
  14345. return;
  14346. }
  14347. if (conf.key.ctrlKey && !e.ctrlKey) {
  14348. return;
  14349. }
  14350. if (conf.key.metaKey && !e.metaKey) {
  14351. return;
  14352. }
  14353. // Made it this far - it is good
  14354. $(node).click();
  14355. }
  14356. };
  14357. var recurse = function recurse(a) {
  14358. for (var i = 0, ien = a.length; i < ien; i++) {
  14359. run(a[i].conf, a[i].node);
  14360. if (a[i].buttons.length) {
  14361. recurse(a[i].buttons);
  14362. }
  14363. }
  14364. };
  14365. recurse(this.s.buttons);
  14366. },
  14367. /**
  14368. * Remove a key from the key listener for this instance (to be used when a
  14369. * button is removed)
  14370. * @param {object} conf Button configuration
  14371. * @private
  14372. */
  14373. _removeKey: function _removeKey(conf) {
  14374. if (conf.key) {
  14375. var character = $.isPlainObject(conf.key) ? conf.key.key : conf.key;
  14376. // Remove only one character, as multiple buttons could have the
  14377. // same listening key
  14378. var a = this.s.listenKeys.split('');
  14379. var idx = $.inArray(character, a);
  14380. a.splice(idx, 1);
  14381. this.s.listenKeys = a.join('');
  14382. }
  14383. },
  14384. /**
  14385. * Resolve a button configuration
  14386. * @param {string|function|object} conf Button config to resolve
  14387. * @return {object} Button configuration
  14388. * @private
  14389. */
  14390. _resolveExtends: function _resolveExtends(conf) {
  14391. var dt = this.s.dt;
  14392. var i, ien;
  14393. var toConfObject = function toConfObject(base) {
  14394. var loop = 0;
  14395. // Loop until we have resolved to a button configuration, or an
  14396. // array of button configurations (which will be iterated
  14397. // separately)
  14398. while (!$.isPlainObject(base) && !$.isArray(base)) {
  14399. if (base === undefined) {
  14400. return;
  14401. }
  14402. if (typeof base === 'function') {
  14403. base = base(dt, conf);
  14404. if (!base) {
  14405. return false;
  14406. }
  14407. } else if (typeof base === 'string') {
  14408. if (!_dtButtons[base]) {
  14409. throw 'Unknown button type: ' + base;
  14410. }
  14411. base = _dtButtons[base];
  14412. }
  14413. loop++;
  14414. if (loop > 30) {
  14415. // Protect against misconfiguration killing the browser
  14416. throw 'Buttons: Too many iterations';
  14417. }
  14418. }
  14419. return $.isArray(base) ? base : $.extend({}, base);
  14420. };
  14421. conf = toConfObject(conf);
  14422. while (conf && conf.extend) {
  14423. // Use `toConfObject` in case the button definition being extended
  14424. // is itself a string or a function
  14425. if (!_dtButtons[conf.extend]) {
  14426. throw 'Cannot extend unknown button type: ' + conf.extend;
  14427. }
  14428. var objArray = toConfObject(_dtButtons[conf.extend]);
  14429. if ($.isArray(objArray)) {
  14430. return objArray;
  14431. } else if (!objArray) {
  14432. // This is a little brutal as it might be possible to have a
  14433. // valid button without the extend, but if there is no extend
  14434. // then the host button would be acting in an undefined state
  14435. return false;
  14436. }
  14437. // Stash the current class name
  14438. var originalClassName = objArray.className;
  14439. conf = $.extend({}, objArray, conf);
  14440. // The extend will have overwritten the original class name if the
  14441. // `conf` object also assigned a class, but we want to concatenate
  14442. // them so they are list that is combined from all extended buttons
  14443. if (originalClassName && conf.className !== originalClassName) {
  14444. conf.className = originalClassName + ' ' + conf.className;
  14445. }
  14446. // Buttons to be added to a collection -gives the ability to define
  14447. // if buttons should be added to the start or end of a collection
  14448. var postfixButtons = conf.postfixButtons;
  14449. if (postfixButtons) {
  14450. if (!conf.buttons) {
  14451. conf.buttons = [];
  14452. }
  14453. for (i = 0, ien = postfixButtons.length; i < ien; i++) {
  14454. conf.buttons.push(postfixButtons[i]);
  14455. }
  14456. conf.postfixButtons = null;
  14457. }
  14458. var prefixButtons = conf.prefixButtons;
  14459. if (prefixButtons) {
  14460. if (!conf.buttons) {
  14461. conf.buttons = [];
  14462. }
  14463. for (i = 0, ien = prefixButtons.length; i < ien; i++) {
  14464. conf.buttons.splice(i, 0, prefixButtons[i]);
  14465. }
  14466. conf.prefixButtons = null;
  14467. }
  14468. // Although we want the `conf` object to overwrite almost all of
  14469. // the properties of the object being extended, the `extend`
  14470. // property should come from the object being extended
  14471. conf.extend = objArray.extend;
  14472. }
  14473. return conf;
  14474. }
  14475. });
  14476. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14477. * Statics
  14478. */
  14479. /**
  14480. * Show / hide a background layer behind a collection
  14481. * @param {boolean} Flag to indicate if the background should be shown or
  14482. * hidden
  14483. * @param {string} Class to assign to the background
  14484. * @static
  14485. */
  14486. Buttons.background = function (show, className, fade) {
  14487. if (fade === undefined) {
  14488. fade = 400;
  14489. }
  14490. if (show) {
  14491. $('<div/>').addClass(className).css('display', 'none').appendTo('body').fadeIn(fade);
  14492. } else {
  14493. $('body > div.' + className).fadeOut(fade, function () {
  14494. $(this).removeClass(className).remove();
  14495. });
  14496. }
  14497. };
  14498. /**
  14499. * Instance selector - select Buttons instances based on an instance selector
  14500. * value from the buttons assigned to a DataTable. This is only useful if
  14501. * multiple instances are attached to a DataTable.
  14502. * @param {string|int|array} Instance selector - see `instance-selector`
  14503. * documentation on the DataTables site
  14504. * @param {array} Button instance array that was attached to the DataTables
  14505. * settings object
  14506. * @return {array} Buttons instances
  14507. * @static
  14508. */
  14509. Buttons.instanceSelector = function (group, buttons) {
  14510. if (!group) {
  14511. return $.map(buttons, function (v) {
  14512. return v.inst;
  14513. });
  14514. }
  14515. var ret = [];
  14516. var names = $.map(buttons, function (v) {
  14517. return v.name;
  14518. });
  14519. // Flatten the group selector into an array of single options
  14520. var process = function process(input) {
  14521. if ($.isArray(input)) {
  14522. for (var i = 0, ien = input.length; i < ien; i++) {
  14523. process(input[i]);
  14524. }
  14525. return;
  14526. }
  14527. if (typeof input === 'string') {
  14528. if (input.indexOf(',') !== -1) {
  14529. // String selector, list of names
  14530. process(input.split(','));
  14531. } else {
  14532. // String selector individual name
  14533. var idx = $.inArray($.trim(input), names);
  14534. if (idx !== -1) {
  14535. ret.push(buttons[idx].inst);
  14536. }
  14537. }
  14538. } else if (typeof input === 'number') {
  14539. // Index selector
  14540. ret.push(buttons[input].inst);
  14541. }
  14542. };
  14543. process(group);
  14544. return ret;
  14545. };
  14546. /**
  14547. * Button selector - select one or more buttons from a selector input so some
  14548. * operation can be performed on them.
  14549. * @param {array} Button instances array that the selector should operate on
  14550. * @param {string|int|node|jQuery|array} Button selector - see
  14551. * `button-selector` documentation on the DataTables site
  14552. * @return {array} Array of objects containing `inst` and `idx` properties of
  14553. * the selected buttons so you know which instance each button belongs to.
  14554. * @static
  14555. */
  14556. Buttons.buttonSelector = function (insts, selector) {
  14557. var ret = [];
  14558. var nodeBuilder = function nodeBuilder(a, buttons, baseIdx) {
  14559. var button;
  14560. var idx;
  14561. for (var i = 0, ien = buttons.length; i < ien; i++) {
  14562. button = buttons[i];
  14563. if (button) {
  14564. idx = baseIdx !== undefined ? baseIdx + i : i + '';
  14565. a.push({
  14566. node: button.node,
  14567. name: button.conf.name,
  14568. idx: idx
  14569. });
  14570. if (button.buttons) {
  14571. nodeBuilder(a, button.buttons, idx + '-');
  14572. }
  14573. }
  14574. }
  14575. };
  14576. var run = function run(selector, inst) {
  14577. var i, ien;
  14578. var buttons = [];
  14579. nodeBuilder(buttons, inst.s.buttons);
  14580. var nodes = $.map(buttons, function (v) {
  14581. return v.node;
  14582. });
  14583. if ($.isArray(selector) || selector instanceof $) {
  14584. for (i = 0, ien = selector.length; i < ien; i++) {
  14585. run(selector[i], inst);
  14586. }
  14587. return;
  14588. }
  14589. if (selector === null || selector === undefined || selector === '*') {
  14590. // Select all
  14591. for (i = 0, ien = buttons.length; i < ien; i++) {
  14592. ret.push({
  14593. inst: inst,
  14594. node: buttons[i].node
  14595. });
  14596. }
  14597. } else if (typeof selector === 'number') {
  14598. // Main button index selector
  14599. ret.push({
  14600. inst: inst,
  14601. node: inst.s.buttons[selector].node
  14602. });
  14603. } else if (typeof selector === 'string') {
  14604. if (selector.indexOf(',') !== -1) {
  14605. // Split
  14606. var a = selector.split(',');
  14607. for (i = 0, ien = a.length; i < ien; i++) {
  14608. run($.trim(a[i]), inst);
  14609. }
  14610. } else if (selector.match(/^\d+(\-\d+)*$/)) {
  14611. // Sub-button index selector
  14612. var indexes = $.map(buttons, function (v) {
  14613. return v.idx;
  14614. });
  14615. ret.push({
  14616. inst: inst,
  14617. node: buttons[$.inArray(selector, indexes)].node
  14618. });
  14619. } else if (selector.indexOf(':name') !== -1) {
  14620. // Button name selector
  14621. var name = selector.replace(':name', '');
  14622. for (i = 0, ien = buttons.length; i < ien; i++) {
  14623. if (buttons[i].name === name) {
  14624. ret.push({
  14625. inst: inst,
  14626. node: buttons[i].node
  14627. });
  14628. }
  14629. }
  14630. } else {
  14631. // jQuery selector on the nodes
  14632. $(nodes).filter(selector).each(function () {
  14633. ret.push({
  14634. inst: inst,
  14635. node: this
  14636. });
  14637. });
  14638. }
  14639. } else if ((typeof selector === 'undefined' ? 'undefined' : _typeof(selector)) === 'object' && selector.nodeName) {
  14640. // Node selector
  14641. var idx = $.inArray(selector, nodes);
  14642. if (idx !== -1) {
  14643. ret.push({
  14644. inst: inst,
  14645. node: nodes[idx]
  14646. });
  14647. }
  14648. }
  14649. };
  14650. for (var i = 0, ien = insts.length; i < ien; i++) {
  14651. var inst = insts[i];
  14652. run(selector, inst);
  14653. }
  14654. return ret;
  14655. };
  14656. /**
  14657. * Buttons defaults. For full documentation, please refer to the docs/option
  14658. * directory or the DataTables site.
  14659. * @type {Object}
  14660. * @static
  14661. */
  14662. Buttons.defaults = {
  14663. buttons: ['copy', 'excel', 'csv', 'pdf', 'print'],
  14664. name: 'main',
  14665. tabIndex: 0,
  14666. dom: {
  14667. container: {
  14668. tag: 'div',
  14669. className: 'dt-buttons'
  14670. },
  14671. collection: {
  14672. tag: 'div',
  14673. className: 'dt-button-collection'
  14674. },
  14675. button: {
  14676. tag: 'a',
  14677. className: 'dt-button',
  14678. active: 'active',
  14679. disabled: 'disabled'
  14680. },
  14681. buttonLiner: {
  14682. tag: 'span',
  14683. className: ''
  14684. }
  14685. }
  14686. };
  14687. /**
  14688. * Version information
  14689. * @type {string}
  14690. * @static
  14691. */
  14692. Buttons.version = '1.4.2';
  14693. $.extend(_dtButtons, {
  14694. collection: {
  14695. text: function text(dt) {
  14696. return dt.i18n('buttons.collection', 'Collection');
  14697. },
  14698. className: 'buttons-collection',
  14699. action: function action(e, dt, button, config) {
  14700. var host = button;
  14701. var hostOffset = host.offset();
  14702. var tableContainer = $(dt.table().container());
  14703. var multiLevel = false;
  14704. // Remove any old collection
  14705. if ($('div.dt-button-background').length) {
  14706. multiLevel = $('.dt-button-collection').offset();
  14707. $('body').trigger('click.dtb-collection');
  14708. }
  14709. config._collection.addClass(config.collectionLayout).css('display', 'none').appendTo('body').fadeIn(config.fade);
  14710. var position = config._collection.css('position');
  14711. if (multiLevel && position === 'absolute') {
  14712. config._collection.css({
  14713. top: multiLevel.top,
  14714. left: multiLevel.left
  14715. });
  14716. } else if (position === 'absolute') {
  14717. config._collection.css({
  14718. top: hostOffset.top + host.outerHeight(),
  14719. left: hostOffset.left
  14720. });
  14721. // calculate overflow when positioned beneath
  14722. var tableBottom = tableContainer.offset().top + tableContainer.height();
  14723. var listBottom = hostOffset.top + host.outerHeight() + config._collection.outerHeight();
  14724. var bottomOverflow = listBottom - tableBottom;
  14725. // calculate overflow when positioned above
  14726. var listTop = hostOffset.top - config._collection.outerHeight();
  14727. var tableTop = tableContainer.offset().top;
  14728. var topOverflow = tableTop - listTop;
  14729. // if bottom overflow is larger, move to the top because it fits better
  14730. if (bottomOverflow > topOverflow) {
  14731. config._collection.css('top', hostOffset.top - config._collection.outerHeight() - 5);
  14732. }
  14733. var listRight = hostOffset.left + config._collection.outerWidth();
  14734. var tableRight = tableContainer.offset().left + tableContainer.width();
  14735. if (listRight > tableRight) {
  14736. config._collection.css('left', hostOffset.left - (listRight - tableRight));
  14737. }
  14738. } else {
  14739. // Fix position - centre on screen
  14740. var top = config._collection.height() / 2;
  14741. if (top > $(window).height() / 2) {
  14742. top = $(window).height() / 2;
  14743. }
  14744. config._collection.css('marginTop', top * -1);
  14745. }
  14746. if (config.background) {
  14747. Buttons.background(true, config.backgroundClassName, config.fade);
  14748. }
  14749. // Need to break the 'thread' for the collection button being
  14750. // activated by a click - it would also trigger this event
  14751. setTimeout(function () {
  14752. // This is bonkers, but if we don't have a click listener on the
  14753. // background element, iOS Safari will ignore the body click
  14754. // listener below. An empty function here is all that is
  14755. // required to make it work...
  14756. $('div.dt-button-background').on('click.dtb-collection', function () {});
  14757. $('body').on('click.dtb-collection', function (e) {
  14758. // andSelf is deprecated in jQ1.8, but we want 1.7 compat
  14759. var back = $.fn.addBack ? 'addBack' : 'andSelf';
  14760. if (!$(e.target).parents()[back]().filter(config._collection).length) {
  14761. config._collection.fadeOut(config.fade, function () {
  14762. config._collection.detach();
  14763. });
  14764. $('div.dt-button-background').off('click.dtb-collection');
  14765. Buttons.background(false, config.backgroundClassName, config.fade);
  14766. $('body').off('click.dtb-collection');
  14767. dt.off('buttons-action.b-internal');
  14768. }
  14769. });
  14770. }, 10);
  14771. if (config.autoClose) {
  14772. dt.on('buttons-action.b-internal', function () {
  14773. $('div.dt-button-background').click();
  14774. });
  14775. }
  14776. },
  14777. background: true,
  14778. collectionLayout: '',
  14779. backgroundClassName: 'dt-button-background',
  14780. autoClose: false,
  14781. fade: 400
  14782. },
  14783. copy: function copy(dt, conf) {
  14784. if (_dtButtons.copyHtml5) {
  14785. return 'copyHtml5';
  14786. }
  14787. if (_dtButtons.copyFlash && _dtButtons.copyFlash.available(dt, conf)) {
  14788. return 'copyFlash';
  14789. }
  14790. },
  14791. csv: function csv(dt, conf) {
  14792. // Common option that will use the HTML5 or Flash export buttons
  14793. if (_dtButtons.csvHtml5 && _dtButtons.csvHtml5.available(dt, conf)) {
  14794. return 'csvHtml5';
  14795. }
  14796. if (_dtButtons.csvFlash && _dtButtons.csvFlash.available(dt, conf)) {
  14797. return 'csvFlash';
  14798. }
  14799. },
  14800. excel: function excel(dt, conf) {
  14801. // Common option that will use the HTML5 or Flash export buttons
  14802. if (_dtButtons.excelHtml5 && _dtButtons.excelHtml5.available(dt, conf)) {
  14803. return 'excelHtml5';
  14804. }
  14805. if (_dtButtons.excelFlash && _dtButtons.excelFlash.available(dt, conf)) {
  14806. return 'excelFlash';
  14807. }
  14808. },
  14809. pdf: function pdf(dt, conf) {
  14810. // Common option that will use the HTML5 or Flash export buttons
  14811. if (_dtButtons.pdfHtml5 && _dtButtons.pdfHtml5.available(dt, conf)) {
  14812. return 'pdfHtml5';
  14813. }
  14814. if (_dtButtons.pdfFlash && _dtButtons.pdfFlash.available(dt, conf)) {
  14815. return 'pdfFlash';
  14816. }
  14817. },
  14818. pageLength: function pageLength(dt) {
  14819. var lengthMenu = dt.settings()[0].aLengthMenu;
  14820. var vals = $.isArray(lengthMenu[0]) ? lengthMenu[0] : lengthMenu;
  14821. var lang = $.isArray(lengthMenu[0]) ? lengthMenu[1] : lengthMenu;
  14822. var text = function text(dt) {
  14823. return dt.i18n('buttons.pageLength', {
  14824. "-1": 'Show all rows',
  14825. _: 'Show %d rows'
  14826. }, dt.page.len());
  14827. };
  14828. return {
  14829. extend: 'collection',
  14830. text: text,
  14831. className: 'buttons-page-length',
  14832. autoClose: true,
  14833. buttons: $.map(vals, function (val, i) {
  14834. return {
  14835. text: lang[i],
  14836. className: 'button-page-length',
  14837. action: function action(e, dt) {
  14838. dt.page.len(val).draw();
  14839. },
  14840. init: function init(dt, node, conf) {
  14841. var that = this;
  14842. var fn = function fn() {
  14843. that.active(dt.page.len() === val);
  14844. };
  14845. dt.on('length.dt' + conf.namespace, fn);
  14846. fn();
  14847. },
  14848. destroy: function destroy(dt, node, conf) {
  14849. dt.off('length.dt' + conf.namespace);
  14850. }
  14851. };
  14852. }),
  14853. init: function init(dt, node, conf) {
  14854. var that = this;
  14855. dt.on('length.dt' + conf.namespace, function () {
  14856. that.text(text(dt));
  14857. });
  14858. },
  14859. destroy: function destroy(dt, node, conf) {
  14860. dt.off('length.dt' + conf.namespace);
  14861. }
  14862. };
  14863. }
  14864. });
  14865. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14866. * DataTables API
  14867. *
  14868. * For complete documentation, please refer to the docs/api directory or the
  14869. * DataTables site
  14870. */
  14871. // Buttons group and individual button selector
  14872. DataTable.Api.register('buttons()', function (group, selector) {
  14873. // Argument shifting
  14874. if (selector === undefined) {
  14875. selector = group;
  14876. group = undefined;
  14877. }
  14878. this.selector.buttonGroup = group;
  14879. var res = this.iterator(true, 'table', function (ctx) {
  14880. if (ctx._buttons) {
  14881. return Buttons.buttonSelector(Buttons.instanceSelector(group, ctx._buttons), selector);
  14882. }
  14883. }, true);
  14884. res._groupSelector = group;
  14885. return res;
  14886. });
  14887. // Individual button selector
  14888. DataTable.Api.register('button()', function (group, selector) {
  14889. // just run buttons() and truncate
  14890. var buttons = this.buttons(group, selector);
  14891. if (buttons.length > 1) {
  14892. buttons.splice(1, buttons.length);
  14893. }
  14894. return buttons;
  14895. });
  14896. // Active buttons
  14897. DataTable.Api.registerPlural('buttons().active()', 'button().active()', function (flag) {
  14898. if (flag === undefined) {
  14899. return this.map(function (set) {
  14900. return set.inst.active(set.node);
  14901. });
  14902. }
  14903. return this.each(function (set) {
  14904. set.inst.active(set.node, flag);
  14905. });
  14906. });
  14907. // Get / set button action
  14908. DataTable.Api.registerPlural('buttons().action()', 'button().action()', function (action) {
  14909. if (action === undefined) {
  14910. return this.map(function (set) {
  14911. return set.inst.action(set.node);
  14912. });
  14913. }
  14914. return this.each(function (set) {
  14915. set.inst.action(set.node, action);
  14916. });
  14917. });
  14918. // Enable / disable buttons
  14919. DataTable.Api.register(['buttons().enable()', 'button().enable()'], function (flag) {
  14920. return this.each(function (set) {
  14921. set.inst.enable(set.node, flag);
  14922. });
  14923. });
  14924. // Disable buttons
  14925. DataTable.Api.register(['buttons().disable()', 'button().disable()'], function () {
  14926. return this.each(function (set) {
  14927. set.inst.disable(set.node);
  14928. });
  14929. });
  14930. // Get button nodes
  14931. DataTable.Api.registerPlural('buttons().nodes()', 'button().node()', function () {
  14932. var jq = $();
  14933. // jQuery will automatically reduce duplicates to a single entry
  14934. $(this.each(function (set) {
  14935. jq = jq.add(set.inst.node(set.node));
  14936. }));
  14937. return jq;
  14938. });
  14939. // Get / set button processing state
  14940. DataTable.Api.registerPlural('buttons().processing()', 'button().processing()', function (flag) {
  14941. if (flag === undefined) {
  14942. return this.map(function (set) {
  14943. return set.inst.processing(set.node);
  14944. });
  14945. }
  14946. return this.each(function (set) {
  14947. set.inst.processing(set.node, flag);
  14948. });
  14949. });
  14950. // Get / set button text (i.e. the button labels)
  14951. DataTable.Api.registerPlural('buttons().text()', 'button().text()', function (label) {
  14952. if (label === undefined) {
  14953. return this.map(function (set) {
  14954. return set.inst.text(set.node);
  14955. });
  14956. }
  14957. return this.each(function (set) {
  14958. set.inst.text(set.node, label);
  14959. });
  14960. });
  14961. // Trigger a button's action
  14962. DataTable.Api.registerPlural('buttons().trigger()', 'button().trigger()', function () {
  14963. return this.each(function (set) {
  14964. set.inst.node(set.node).trigger('click');
  14965. });
  14966. });
  14967. // Get the container elements
  14968. DataTable.Api.registerPlural('buttons().containers()', 'buttons().container()', function () {
  14969. var jq = $();
  14970. var groupSelector = this._groupSelector;
  14971. // We need to use the group selector directly, since if there are no buttons
  14972. // the result set will be empty
  14973. this.iterator(true, 'table', function (ctx) {
  14974. if (ctx._buttons) {
  14975. var insts = Buttons.instanceSelector(groupSelector, ctx._buttons);
  14976. for (var i = 0, ien = insts.length; i < ien; i++) {
  14977. jq = jq.add(insts[i].container());
  14978. }
  14979. }
  14980. });
  14981. return jq;
  14982. });
  14983. // Add a new button
  14984. DataTable.Api.register('button().add()', function (idx, conf) {
  14985. var ctx = this.context;
  14986. // Don't use `this` as it could be empty - select the instances directly
  14987. if (ctx.length) {
  14988. var inst = Buttons.instanceSelector(this._groupSelector, ctx[0]._buttons);
  14989. if (inst.length) {
  14990. inst[0].add(conf, idx);
  14991. }
  14992. }
  14993. return this.button(this._groupSelector, idx);
  14994. });
  14995. // Destroy the button sets selected
  14996. DataTable.Api.register('buttons().destroy()', function () {
  14997. this.pluck('inst').unique().each(function (inst) {
  14998. inst.destroy();
  14999. });
  15000. return this;
  15001. });
  15002. // Remove a button
  15003. DataTable.Api.registerPlural('buttons().remove()', 'buttons().remove()', function () {
  15004. this.each(function (set) {
  15005. set.inst.remove(set.node);
  15006. });
  15007. return this;
  15008. });
  15009. // Information box that can be used by buttons
  15010. var _infoTimer;
  15011. DataTable.Api.register('buttons.info()', function (title, message, time) {
  15012. var that = this;
  15013. if (title === false) {
  15014. $('#datatables_buttons_info').fadeOut(function () {
  15015. $(this).remove();
  15016. });
  15017. clearTimeout(_infoTimer);
  15018. _infoTimer = null;
  15019. return this;
  15020. }
  15021. if (_infoTimer) {
  15022. clearTimeout(_infoTimer);
  15023. }
  15024. if ($('#datatables_buttons_info').length) {
  15025. $('#datatables_buttons_info').remove();
  15026. }
  15027. title = title ? '<h2>' + title + '</h2>' : '';
  15028. $('<div id="datatables_buttons_info" class="dt-button-info"/>').html(title).append($('<div/>')[typeof message === 'string' ? 'html' : 'append'](message)).css('display', 'none').appendTo('body').fadeIn();
  15029. if (time !== undefined && time !== 0) {
  15030. _infoTimer = setTimeout(function () {
  15031. that.buttons.info(false);
  15032. }, time);
  15033. }
  15034. return this;
  15035. });
  15036. // Get data from the table for export - this is common to a number of plug-in
  15037. // buttons so it is included in the Buttons core library
  15038. DataTable.Api.register('buttons.exportData()', function (options) {
  15039. if (this.context.length) {
  15040. return _exportData(new DataTable.Api(this.context[0]), options);
  15041. }
  15042. });
  15043. // Get information about the export that is common to many of the export data
  15044. // types (DRY)
  15045. DataTable.Api.register('buttons.exportInfo()', function (conf) {
  15046. if (!conf) {
  15047. conf = {};
  15048. }
  15049. return {
  15050. filename: _filename(conf),
  15051. title: _title(conf),
  15052. messageTop: _message(this, conf.messageTop || conf.message, 'top'),
  15053. messageBottom: _message(this, conf.messageBottom, 'bottom')
  15054. };
  15055. });
  15056. /**
  15057. * Get the file name for an exported file.
  15058. *
  15059. * @param {object} config Button configuration
  15060. * @param {boolean} incExtension Include the file name extension
  15061. */
  15062. var _filename = function _filename(config) {
  15063. // Backwards compatibility
  15064. var filename = config.filename === '*' && config.title !== '*' && config.title !== undefined ? config.title : config.filename;
  15065. if (typeof filename === 'function') {
  15066. filename = filename();
  15067. }
  15068. if (filename === undefined || filename === null) {
  15069. return null;
  15070. }
  15071. if (filename.indexOf('*') !== -1) {
  15072. filename = $.trim(filename.replace('*', $('title').text()));
  15073. }
  15074. // Strip characters which the OS will object to
  15075. filename = filename.replace(/[^a-zA-Z0-9_\u00A1-\uFFFF\.,\-_ !\(\)]/g, "");
  15076. var extension = _stringOrFunction(config.extension);
  15077. if (!extension) {
  15078. extension = '';
  15079. }
  15080. return filename + extension;
  15081. };
  15082. /**
  15083. * Simply utility method to allow parameters to be given as a function
  15084. *
  15085. * @param {undefined|string|function} option Option
  15086. * @return {null|string} Resolved value
  15087. */
  15088. var _stringOrFunction = function _stringOrFunction(option) {
  15089. if (option === null || option === undefined) {
  15090. return null;
  15091. } else if (typeof option === 'function') {
  15092. return option();
  15093. }
  15094. return option;
  15095. };
  15096. /**
  15097. * Get the title for an exported file.
  15098. *
  15099. * @param {object} config Button configuration
  15100. */
  15101. var _title = function _title(config) {
  15102. var title = _stringOrFunction(config.title);
  15103. return title === null ? null : title.indexOf('*') !== -1 ? title.replace('*', $('title').text() || 'Exported data') : title;
  15104. };
  15105. var _message = function _message(dt, option, position) {
  15106. var message = _stringOrFunction(option);
  15107. if (message === null) {
  15108. return null;
  15109. }
  15110. var caption = $('caption', dt.table().container()).eq(0);
  15111. if (message === '*') {
  15112. var side = caption.css('caption-side');
  15113. if (side !== position) {
  15114. return null;
  15115. }
  15116. return caption.length ? caption.text() : '';
  15117. }
  15118. return message;
  15119. };
  15120. var _exportTextarea = $('<textarea/>')[0];
  15121. var _exportData = function _exportData(dt, inOpts) {
  15122. var config = $.extend(true, {}, {
  15123. rows: null,
  15124. columns: '',
  15125. modifier: {
  15126. search: 'applied',
  15127. order: 'applied'
  15128. },
  15129. orthogonal: 'display',
  15130. stripHtml: true,
  15131. stripNewlines: true,
  15132. decodeEntities: true,
  15133. trim: true,
  15134. format: {
  15135. header: function header(d) {
  15136. return strip(d);
  15137. },
  15138. footer: function footer(d) {
  15139. return strip(d);
  15140. },
  15141. body: function body(d) {
  15142. return strip(d);
  15143. }
  15144. }
  15145. }, inOpts);
  15146. var strip = function strip(str) {
  15147. if (typeof str !== 'string') {
  15148. return str;
  15149. }
  15150. // Always remove script tags
  15151. str = str.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
  15152. if (config.stripHtml) {
  15153. str = str.replace(/<[^>]*>/g, '');
  15154. }
  15155. if (config.trim) {
  15156. str = str.replace(/^\s+|\s+$/g, '');
  15157. }
  15158. if (config.stripNewlines) {
  15159. str = str.replace(/\n/g, ' ');
  15160. }
  15161. if (config.decodeEntities) {
  15162. _exportTextarea.innerHTML = str;
  15163. str = _exportTextarea.value;
  15164. }
  15165. return str;
  15166. };
  15167. var header = dt.columns(config.columns).indexes().map(function (idx) {
  15168. var el = dt.column(idx).header();
  15169. return config.format.header(el.innerHTML, idx, el);
  15170. }).toArray();
  15171. var footer = dt.table().footer() ? dt.columns(config.columns).indexes().map(function (idx) {
  15172. var el = dt.column(idx).footer();
  15173. return config.format.footer(el ? el.innerHTML : '', idx, el);
  15174. }).toArray() : null;
  15175. var rowIndexes = dt.rows(config.rows, config.modifier).indexes().toArray();
  15176. var selectedCells = dt.cells(rowIndexes, config.columns);
  15177. var cells = selectedCells.render(config.orthogonal).toArray();
  15178. var cellNodes = selectedCells.nodes().toArray();
  15179. var columns = header.length;
  15180. var rows = columns > 0 ? cells.length / columns : 0;
  15181. var body = new Array(rows);
  15182. var cellCounter = 0;
  15183. for (var i = 0, ien = rows; i < ien; i++) {
  15184. var row = new Array(columns);
  15185. for (var j = 0; j < columns; j++) {
  15186. row[j] = config.format.body(cells[cellCounter], i, j, cellNodes[cellCounter]);
  15187. cellCounter++;
  15188. }
  15189. body[i] = row;
  15190. }
  15191. return {
  15192. header: header,
  15193. footer: footer,
  15194. body: body
  15195. };
  15196. };
  15197. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  15198. * DataTables interface
  15199. */
  15200. // Attach to DataTables objects for global access
  15201. $.fn.dataTable.Buttons = Buttons;
  15202. $.fn.DataTable.Buttons = Buttons;
  15203. // DataTables creation - check if the buttons have been defined for this table,
  15204. // they will have been if the `B` option was used in `dom`, otherwise we should
  15205. // create the buttons instance here so they can be inserted into the document
  15206. // using the API. Listen for `init` for compatibility with pre 1.10.10, but to
  15207. // be removed in future.
  15208. $(document).on('init.dt plugin-init.dt', function (e, settings) {
  15209. if (e.namespace !== 'dt') {
  15210. return;
  15211. }
  15212. var opts = settings.oInit.buttons || DataTable.defaults.buttons;
  15213. if (opts && !settings._buttons) {
  15214. new Buttons(settings, opts).container();
  15215. }
  15216. });
  15217. // DataTables `dom` feature option
  15218. DataTable.ext.feature.push({
  15219. fnInit: function fnInit(settings) {
  15220. var api = new DataTable.Api(settings);
  15221. var opts = api.init().buttons || DataTable.defaults.buttons;
  15222. return new Buttons(api, opts).container();
  15223. },
  15224. cFeature: "B"
  15225. });
  15226. return Buttons;
  15227. });
  15228. /***/ })
  15229. /******/ });