bootstrap-table-all.js 178 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * version: 1.8.1
  4. * https://github.com/wenzhixin/bootstrap-table/
  5. */
  6. ! function ($) {
  7. 'use strict';
  8. // TOOLS DEFINITION
  9. // ======================
  10. var cachedWidth = null;
  11. // it only does '%s', and return '' when arguments are undefined
  12. var sprintf = function (str) {
  13. var args = arguments,
  14. flag = true,
  15. i = 1;
  16. str = str.replace(/%s/g, function () {
  17. var arg = args[i++];
  18. if (typeof arg === 'undefined') {
  19. flag = false;
  20. return '';
  21. }
  22. return arg;
  23. });
  24. return flag ? str : '';
  25. };
  26. var getPropertyFromOther = function (list, from, to, value) {
  27. var result = '';
  28. $.each(list, function (i, item) {
  29. if (item[from] === value) {
  30. result = item[to];
  31. return false;
  32. }
  33. return true;
  34. });
  35. return result;
  36. };
  37. var getFieldIndex = function (columns, field) {
  38. var index = -1;
  39. $.each(columns, function (i, column) {
  40. if (column.field === field) {
  41. index = i;
  42. return false;
  43. }
  44. return true;
  45. });
  46. return index;
  47. };
  48. // http://jsfiddle.net/wenyi/47nz7ez9/3/
  49. var setFieldIndex = function (columns) {
  50. var i, j, k,
  51. totalCol = 0,
  52. flag = [];
  53. for (i = 0; i < columns[0].length; i++) {
  54. totalCol += columns[0][i].colspan || 1;
  55. }
  56. for (i = 0; i < columns.length; i++) {
  57. flag[i] = [];
  58. for (j = 0; j < totalCol; j++) {
  59. flag[i][j] = false;
  60. }
  61. }
  62. for (i = 0; i < columns.length; i++) {
  63. for (j = 0; j < columns[i].length; j++) {
  64. var r = columns[i][j],
  65. rowspan = r.rowspan || 1,
  66. colspan = r.colspan || 1,
  67. index = $.inArray(false, flag[i]);
  68. if (colspan === 1) {
  69. r.fieldIndex = index;
  70. // when field is undefined, use index instead
  71. if (typeof r.field === 'undefined') {
  72. r.field = index;
  73. }
  74. }
  75. for (k = 0; k < rowspan; k++) {
  76. flag[i + k][index] = true;
  77. }
  78. for (k = 0; k < colspan; k++) {
  79. flag[i][index + k] = true;
  80. }
  81. }
  82. }
  83. }
  84. var getScrollBarWidth = function () {
  85. if (cachedWidth === null) {
  86. var inner = $('<p/>').addClass('fixed-table-scroll-inner'),
  87. outer = $('<div/>').addClass('fixed-table-scroll-outer'),
  88. w1, w2;
  89. outer.append(inner);
  90. $('body').append(outer);
  91. w1 = inner[0].offsetWidth;
  92. outer.css('overflow', 'scroll');
  93. w2 = inner[0].offsetWidth;
  94. if (w1 === w2) {
  95. w2 = outer[0].clientWidth;
  96. }
  97. outer.remove();
  98. cachedWidth = w1 - w2;
  99. }
  100. return cachedWidth;
  101. };
  102. var calculateObjectValue = function (self, name, args, defaultValue) {
  103. var func = name;
  104. if (typeof name === 'string') {
  105. // support obj.func1.func2
  106. var names = name.split('.');
  107. if (names.length > 1) {
  108. func = window;
  109. $.each(names, function (i, f) {
  110. func = func[f];
  111. });
  112. } else {
  113. func = window[name];
  114. }
  115. }
  116. if (typeof func === 'object') {
  117. return func;
  118. }
  119. if (typeof func === 'function') {
  120. return func.apply(self, args);
  121. }
  122. if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) {
  123. return sprintf.apply(this, [name].concat(args));
  124. }
  125. return defaultValue;
  126. };
  127. var compareObjects = function (objectA, objectB, compareLength) {
  128. // Create arrays of property names
  129. var objectAProperties = Object.getOwnPropertyNames(objectA),
  130. objectBProperties = Object.getOwnPropertyNames(objectB),
  131. propName = '';
  132. if (compareLength) {
  133. // If number of properties is different, objects are not equivalent
  134. if (objectAProperties.length != objectBProperties.length) {
  135. return false;
  136. }
  137. }
  138. for (var i = 0; i < objectAProperties.length; i++) {
  139. propName = objectAProperties[i];
  140. // If the property is not in the object B properties, continue with the next property
  141. if ($.inArray(propName, objectBProperties) > -1) {
  142. // If values of same property are not equal, objects are not equivalent
  143. if (objectA[propName] !== objectB[propName]) {
  144. return false;
  145. }
  146. }
  147. }
  148. // If we made it this far, objects are considered equivalent
  149. return true;
  150. };
  151. var escapeHTML = function (text) {
  152. if (typeof text === 'string') {
  153. return text
  154. .replace(/&/g, "&amp;")
  155. .replace(/</g, "&lt;")
  156. .replace(/>/g, "&gt;")
  157. .replace(/"/g, "&quot;")
  158. .replace(/'/g, "&#039;");
  159. }
  160. return text;
  161. };
  162. var getRealHeight = function ($el) {
  163. var height = 0;
  164. $el.children().each(function () {
  165. if (height < $(this).outerHeight(true)) {
  166. height = $(this).outerHeight(true);
  167. }
  168. });
  169. return height;
  170. };
  171. var getRealDataAttr = function (dataAttr) {
  172. for (var attr in dataAttr) {
  173. var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
  174. if (auxAttr !== attr) {
  175. dataAttr[auxAttr] = dataAttr[attr];
  176. delete dataAttr[attr];
  177. }
  178. }
  179. return dataAttr;
  180. };
  181. // BOOTSTRAP TABLE CLASS DEFINITION
  182. // ======================
  183. var BootstrapTable = function (el, options) {
  184. this.options = options;
  185. this.$el = $(el);
  186. this.$el_ = this.$el.clone();
  187. this.timeoutId_ = 0;
  188. this.timeoutFooter_ = 0;
  189. this.init();
  190. };
  191. BootstrapTable.DEFAULTS = {
  192. classes: 'table table-hover',
  193. locale: undefined,
  194. height: undefined,
  195. undefinedText: '-',
  196. sortName: undefined,
  197. sortOrder: 'asc',
  198. striped: false,
  199. columns: [[]],
  200. data: [],
  201. method: 'get',
  202. url: undefined,
  203. ajax: undefined,
  204. cache: true,
  205. contentType: 'application/json',
  206. dataType: 'json',
  207. ajaxOptions: {},
  208. queryParams: function (params) {
  209. return params;
  210. },
  211. queryParamsType: 'limit', // undefined
  212. responseHandler: function (res) {
  213. return res;
  214. },
  215. pagination: false,
  216. sidePagination: 'client', // client or server
  217. totalRows: 0, // server side need to set
  218. pageNumber: 1,
  219. pageSize: 10,
  220. pageList: [10, 25, 50, 100],
  221. paginationHAlign: 'right', //right, left
  222. paginationVAlign: 'bottom', //bottom, top, both
  223. paginationDetailHAlign: 'left', //right, left
  224. paginationFirstText: '&laquo;',
  225. paginationPreText: '&lsaquo;',
  226. paginationNextText: '&rsaquo;',
  227. paginationLastText: '&raquo;',
  228. search: false,
  229. strictSearch: false,
  230. searchAlign: 'right',
  231. selectItemName: 'btSelectItem',
  232. showHeader: true,
  233. showFooter: false,
  234. showColumns: false,
  235. showPaginationSwitch: false,
  236. showRefresh: false,
  237. showToggle: false,
  238. buttonsAlign: 'right',
  239. smartDisplay: true,
  240. minimumCountColumns: 1,
  241. idField: undefined,
  242. uniqueId: undefined,
  243. cardView: false,
  244. detailView: false,
  245. detailFormatter: function (index, row) {
  246. return '';
  247. },
  248. trimOnSearch: true,
  249. clickToSelect: false,
  250. singleSelect: false,
  251. toolbar: undefined,
  252. toolbarAlign: 'left',
  253. checkboxHeader: true,
  254. sortable: true,
  255. silentSort: true,
  256. maintainSelected: false,
  257. searchTimeOut: 500,
  258. searchText: '',
  259. iconSize: undefined,
  260. iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
  261. icons: {
  262. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  263. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  264. refresh: 'glyphicon-refresh icon-refresh',
  265. toggle: 'glyphicon-list-alt icon-list-alt',
  266. columns: 'glyphicon-th icon-th',
  267. detailOpen: 'glyphicon-plus icon-plus',
  268. detailClose: 'glyphicon-minus icon-minus'
  269. },
  270. rowStyle: function (row, index) {
  271. return {};
  272. },
  273. rowAttributes: function (row, index) {
  274. return {};
  275. },
  276. onAll: function (name, args) {
  277. return false;
  278. },
  279. onClickCell: function (field, value, row, $element) {
  280. return false;
  281. },
  282. onDblClickCell: function (field, value, row, $element) {
  283. return false;
  284. },
  285. onClickRow: function (item, $element) {
  286. return false;
  287. },
  288. onDblClickRow: function (item, $element) {
  289. return false;
  290. },
  291. onSort: function (name, order) {
  292. return false;
  293. },
  294. onCheck: function (row) {
  295. return false;
  296. },
  297. onUncheck: function (row) {
  298. return false;
  299. },
  300. onCheckAll: function (rows) {
  301. return false;
  302. },
  303. onUncheckAll: function (rows) {
  304. return false;
  305. },
  306. onCheckSome: function (rows) {
  307. return false;
  308. },
  309. onUncheckSome: function (rows) {
  310. return false;
  311. },
  312. onLoadSuccess: function (data) {
  313. return false;
  314. },
  315. onLoadError: function (status) {
  316. return false;
  317. },
  318. onColumnSwitch: function (field, checked) {
  319. return false;
  320. },
  321. onPageChange: function (number, size) {
  322. return false;
  323. },
  324. onSearch: function (text) {
  325. return false;
  326. },
  327. onToggle: function (cardView) {
  328. return false;
  329. },
  330. onPreBody: function (data) {
  331. return false;
  332. },
  333. onPostBody: function () {
  334. return false;
  335. },
  336. onPostHeader: function () {
  337. return false;
  338. },
  339. onExpandRow: function (index, row, $detail) {
  340. return false;
  341. },
  342. onCollapseRow: function (index, row) {
  343. return false;
  344. },
  345. onRefreshOptions: function (options) {
  346. return false;
  347. },
  348. onResetView: function () {
  349. return false;
  350. }
  351. };
  352. BootstrapTable.LOCALES = [];
  353. BootstrapTable.LOCALES['en-US'] = BootstrapTable.LOCALES['en'] = {
  354. formatLoadingMessage: function () {
  355. return 'Loading, please wait...';
  356. },
  357. formatRecordsPerPage: function (pageNumber) {
  358. return sprintf('%s records per page', pageNumber);
  359. },
  360. formatShowingRows: function (pageFrom, pageTo, totalRows) {
  361. return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
  362. },
  363. formatSearch: function () {
  364. return 'Search';
  365. },
  366. formatNoMatches: function () {
  367. return 'No matching records found';
  368. },
  369. formatPaginationSwitch: function () {
  370. return 'Hide/Show pagination';
  371. },
  372. formatRefresh: function () {
  373. return 'Refresh';
  374. },
  375. formatToggle: function () {
  376. return 'Toggle';
  377. },
  378. formatColumns: function () {
  379. return 'Columns';
  380. },
  381. formatAllRows: function () {
  382. return 'All';
  383. }
  384. };
  385. $.extend(BootstrapTable.DEFAULTS, BootstrapTable.LOCALES['en-US']);
  386. BootstrapTable.COLUMN_DEFAULTS = {
  387. radio: false,
  388. checkbox: false,
  389. checkboxEnabled: true,
  390. field: undefined,
  391. title: undefined,
  392. titleTooltip: undefined,
  393. 'class': undefined,
  394. align: undefined, // left, right, center
  395. halign: undefined, // left, right, center
  396. falign: undefined, // left, right, center
  397. valign: undefined, // top, middle, bottom
  398. width: undefined,
  399. sortable: false,
  400. order: 'asc', // asc, desc
  401. visible: true,
  402. switchable: true,
  403. clickToSelect: true,
  404. formatter: undefined,
  405. footerFormatter: undefined,
  406. events: undefined,
  407. sorter: undefined,
  408. sortName: undefined,
  409. cellStyle: undefined,
  410. searchable: true,
  411. searchFormatter: true,
  412. cardVisible: true
  413. };
  414. BootstrapTable.EVENTS = {
  415. 'all.bs.table': 'onAll',
  416. 'click-cell.bs.table': 'onClickCell',
  417. 'dbl-click-cell.bs.table': 'onDblClickCell',
  418. 'click-row.bs.table': 'onClickRow',
  419. 'dbl-click-row.bs.table': 'onDblClickRow',
  420. 'sort.bs.table': 'onSort',
  421. 'check.bs.table': 'onCheck',
  422. 'uncheck.bs.table': 'onUncheck',
  423. 'check-all.bs.table': 'onCheckAll',
  424. 'uncheck-all.bs.table': 'onUncheckAll',
  425. 'check-some.bs.table': 'onCheckSome',
  426. 'uncheck-some.bs.table': 'onUncheckSome',
  427. 'load-success.bs.table': 'onLoadSuccess',
  428. 'load-error.bs.table': 'onLoadError',
  429. 'column-switch.bs.table': 'onColumnSwitch',
  430. 'page-change.bs.table': 'onPageChange',
  431. 'search.bs.table': 'onSearch',
  432. 'toggle.bs.table': 'onToggle',
  433. 'pre-body.bs.table': 'onPreBody',
  434. 'post-body.bs.table': 'onPostBody',
  435. 'post-header.bs.table': 'onPostHeader',
  436. 'expand-row.bs.table': 'onExpandRow',
  437. 'collapse-row.bs.table': 'onCollapseRow',
  438. 'refresh-options.bs.table': 'onRefreshOptions',
  439. 'reset-view.bs.table': 'onResetView'
  440. };
  441. BootstrapTable.prototype.init = function () {
  442. this.initLocale();
  443. this.initContainer();
  444. this.initTable();
  445. this.initHeader();
  446. this.initData();
  447. this.initFooter();
  448. this.initToolbar();
  449. this.initPagination();
  450. this.initBody();
  451. this.initServer();
  452. };
  453. BootstrapTable.prototype.initLocale = function () {
  454. if (this.options.locale) {
  455. var parts = this.options.locale.split(/-|_/);
  456. parts[0].toLowerCase();
  457. parts[1] && parts[1].toUpperCase();
  458. if ($.fn.bootstrapTable.locales[this.options.locale]) {
  459. // locale as requested
  460. $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
  461. } else if ($.fn.bootstrapTable.locales[parts.join('-')]) {
  462. // locale with sep set to - (in case original was specified with _)
  463. $.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]);
  464. } else if ($.fn.bootstrapTable.locales[parts[0]]) {
  465. // short locale language code (i.e. 'en')
  466. $.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]);
  467. }
  468. }
  469. };
  470. BootstrapTable.prototype.initContainer = function () {
  471. this.$container = $([
  472. '<div class="bootstrap-table">',
  473. '<div class="fixed-table-toolbar"></div>',
  474. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  475. '<div class="fixed-table-pagination" style="clear: both;"></div>' :
  476. '',
  477. '<div class="fixed-table-container">',
  478. '<div class="fixed-table-header"><table></table></div>',
  479. '<div class="fixed-table-body">',
  480. '<div class="fixed-table-loading">',
  481. this.options.formatLoadingMessage(),
  482. '</div>',
  483. '</div>',
  484. '<div class="fixed-table-footer"><table><tr></tr></table></div>',
  485. this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
  486. '<div class="fixed-table-pagination"></div>' :
  487. '',
  488. '</div>',
  489. '</div>'
  490. ].join(''));
  491. this.$container.insertAfter(this.$el);
  492. this.$tableContainer = this.$container.find('.fixed-table-container');
  493. this.$tableHeader = this.$container.find('.fixed-table-header');
  494. this.$tableBody = this.$container.find('.fixed-table-body');
  495. this.$tableLoading = this.$container.find('.fixed-table-loading');
  496. this.$tableFooter = this.$container.find('.fixed-table-footer');
  497. this.$toolbar = this.$container.find('.fixed-table-toolbar');
  498. this.$pagination = this.$container.find('.fixed-table-pagination');
  499. this.$tableBody.append(this.$el);
  500. this.$container.after('<div class="clearfix"></div>');
  501. this.$el.addClass(this.options.classes);
  502. if (this.options.striped) {
  503. this.$el.addClass('table-striped');
  504. }
  505. if ($.inArray('table-no-bordered', this.options.classes.split(' ')) !== -1) {
  506. this.$tableContainer.addClass('table-no-bordered');
  507. }
  508. };
  509. BootstrapTable.prototype.initTable = function () {
  510. var that = this,
  511. columns = [],
  512. data = [];
  513. this.$header = this.$el.find('thead');
  514. if (!this.$header.length) {
  515. this.$header = $('<thead></thead>').appendTo(this.$el);
  516. }
  517. this.$header.find('tr').each(function () {
  518. var column = [];
  519. $(this).find('th').each(function () {
  520. column.push($.extend({}, {
  521. title: $(this).html(),
  522. 'class': $(this).attr('class'),
  523. titleTooltip: $(this).attr('title'),
  524. rowspan: $(this).attr('rowspan') ? +$(this).attr('rowspan') : undefined,
  525. colspan: $(this).attr('colspan') ? +$(this).attr('colspan') : undefined
  526. }, $(this).data()));
  527. });
  528. columns.push(column);
  529. });
  530. if (!$.isArray(this.options.columns[0])) {
  531. this.options.columns = [this.options.columns];
  532. }
  533. this.options.columns = $.extend(true, [], columns, this.options.columns);
  534. this.columns = [];
  535. setFieldIndex(this.options.columns);
  536. $.each(this.options.columns, function (i, columns) {
  537. $.each(columns, function (j, column) {
  538. column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, column);
  539. if (typeof column.fieldIndex !== 'undefined') {
  540. that.columns[column.fieldIndex] = column;
  541. }
  542. that.options.columns[i][j] = column;
  543. });
  544. });
  545. // if options.data is setting, do not process tbody data
  546. if (this.options.data.length) {
  547. return;
  548. }
  549. this.$el.find('tbody tr').each(function () {
  550. var row = {};
  551. // save tr's id, class and data-* attributes
  552. row._id = $(this).attr('id');
  553. row._class = $(this).attr('class');
  554. row._data = getRealDataAttr($(this).data());
  555. $(this).find('td').each(function (i) {
  556. var field = that.columns[i].field;
  557. row[field] = $(this).html();
  558. // save td's id, class and data-* attributes
  559. row['_' + field + '_id'] = $(this).attr('id');
  560. row['_' + field + '_class'] = $(this).attr('class');
  561. row['_' + field + '_rowspan'] = $(this).attr('rowspan');
  562. row['_' + field + '_title'] = $(this).attr('title');
  563. row['_' + field + '_data'] = getRealDataAttr($(this).data());
  564. });
  565. data.push(row);
  566. });
  567. this.options.data = data;
  568. };
  569. BootstrapTable.prototype.initHeader = function () {
  570. var that = this,
  571. visibleColumns = {},
  572. html = [];
  573. this.header = {
  574. fields: [],
  575. styles: [],
  576. classes: [],
  577. formatters: [],
  578. events: [],
  579. sorters: [],
  580. sortNames: [],
  581. cellStyles: [],
  582. searchables: []
  583. };
  584. $.each(this.options.columns, function (i, columns) {
  585. html.push('<tr>');
  586. if (i == 0 && !that.options.cardView && that.options.detailView) {
  587. html.push(sprintf('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>',
  588. that.options.columns.length));
  589. }
  590. $.each(columns, function (j, column) {
  591. var text = '',
  592. halign = '', // header align style
  593. align = '', // body align style
  594. style = '',
  595. class_ = sprintf(' class="%s"', column['class']),
  596. order = that.options.sortOrder || column.order,
  597. unitWidth = 'px',
  598. width = column.width;
  599. if (column.width !== undefined && (!that.options.cardView)) {
  600. if (typeof column.width === 'string') {
  601. if (column.width.indexOf('%') !== -1) {
  602. unitWidth = '%';
  603. }
  604. }
  605. }
  606. if (column.width && typeof column.width === 'string') {
  607. width = column.width.replace('%', '').replace('px', '');
  608. }
  609. halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  610. align = sprintf('text-align: %s; ', column.align);
  611. style = sprintf('vertical-align: %s; ', column.valign);
  612. style += sprintf('width: %s%s; ', column.checkbox || column.radio ? 36 : width, unitWidth);
  613. if (typeof column.fieldIndex !== 'undefined') {
  614. that.header.fields[column.fieldIndex] = column.field;
  615. that.header.styles[column.fieldIndex] = align + style;
  616. that.header.classes[column.fieldIndex] = class_;
  617. that.header.formatters[column.fieldIndex] = column.formatter;
  618. that.header.events[column.fieldIndex] = column.events;
  619. that.header.sorters[column.fieldIndex] = column.sorter;
  620. that.header.sortNames[column.fieldIndex] = column.sortName;
  621. that.header.cellStyles[column.fieldIndex] = column.cellStyle;
  622. that.header.searchables[column.fieldIndex] = column.searchable;
  623. if (!column.visible) {
  624. return;
  625. }
  626. if (that.options.cardView && (!column.cardVisible)) {
  627. return;
  628. }
  629. visibleColumns[column.field] = column;
  630. }
  631. html.push('<th' + sprintf(' title="%s"', column.titleTooltip),
  632. column.checkbox || column.radio ?
  633. sprintf(' class="bs-checkbox %s"', column['class'] || '') :
  634. class_,
  635. sprintf(' style="%s"', halign + style),
  636. sprintf(' rowspan="%s"', column.rowspan),
  637. sprintf(' colspan="%s"', column.colspan),
  638. sprintf(' data-field="%s"', column.field),
  639. '>');
  640. html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
  641. 'sortable both' : ''));
  642. text = column.title;
  643. if (column.checkbox) {
  644. if (!that.options.singleSelect && that.options.checkboxHeader) {
  645. text = '<input name="btSelectAll" type="checkbox" />';
  646. }
  647. that.header.stateField = column.field;
  648. }
  649. if (column.radio) {
  650. text = '';
  651. that.header.stateField = column.field;
  652. that.options.singleSelect = true;
  653. }
  654. html.push(text);
  655. html.push('</div>');
  656. html.push('<div class="fht-cell"></div>');
  657. html.push('</div>');
  658. html.push('</th>');
  659. });
  660. html.push('</tr>');
  661. });
  662. this.$header.html(html.join(''));
  663. this.$header.find('th[data-field]').each(function (i) {
  664. $(this).data(visibleColumns[$(this).data('field')]);
  665. });
  666. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
  667. if (that.options.sortable && $(this).parent().data().sortable) {
  668. that.onSort(event);
  669. }
  670. });
  671. if (!this.options.showHeader || this.options.cardView) {
  672. this.$header.hide();
  673. this.$tableHeader.hide();
  674. this.$tableLoading.css('top', 0);
  675. } else {
  676. this.$header.show();
  677. this.$tableHeader.show();
  678. this.$tableLoading.css('top', this.$header.outerHeight() + 1);
  679. // Assign the correct sortable arrow
  680. this.getCaret();
  681. }
  682. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  683. this.$container.off('click', '[name="btSelectAll"]')
  684. .on('click', '[name="btSelectAll"]', function () {
  685. var checked = $(this).prop('checked');
  686. that[checked ? 'checkAll' : 'uncheckAll']();
  687. });
  688. };
  689. BootstrapTable.prototype.initFooter = function () {
  690. if (!this.options.showFooter || this.options.cardView) {
  691. this.$tableFooter.hide();
  692. } else {
  693. this.$tableFooter.show();
  694. }
  695. };
  696. /**
  697. * @param data
  698. * @param type: append / prepend
  699. */
  700. BootstrapTable.prototype.initData = function (data, type) {
  701. if (type === 'append') {
  702. this.data = this.data.concat(data);
  703. } else if (type === 'prepend') {
  704. this.data = [].concat(data).concat(this.data);
  705. } else {
  706. this.data = data || this.options.data;
  707. }
  708. // Fix #839 Records deleted when adding new row on filtered table
  709. if (type === 'append') {
  710. this.options.data = this.options.data.concat(data);
  711. } else if (type === 'prepend') {
  712. this.options.data = [].concat(data).concat(this.options.data);
  713. } else {
  714. this.options.data = this.data;
  715. }
  716. if (this.options.sidePagination === 'server') {
  717. return;
  718. }
  719. this.initSort();
  720. };
  721. BootstrapTable.prototype.initSort = function () {
  722. var that = this,
  723. name = this.options.sortName,
  724. order = this.options.sortOrder === 'desc' ? -1 : 1,
  725. index = $.inArray(this.options.sortName, this.header.fields);
  726. if (index !== -1) {
  727. this.data.sort(function (a, b) {
  728. if (that.header.sortNames[index]) {
  729. name = that.header.sortNames[index];
  730. }
  731. var aa = a[name],
  732. bb = b[name],
  733. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
  734. if (value !== undefined) {
  735. return order * value;
  736. }
  737. // Fix #161: undefined or null string sort bug.
  738. if (aa === undefined || aa === null) {
  739. aa = '';
  740. }
  741. if (bb === undefined || bb === null) {
  742. bb = '';
  743. }
  744. // IF both values are numeric, do a numeric comparison
  745. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  746. // Convert numerical values form string to float.
  747. aa = parseFloat(aa);
  748. bb = parseFloat(bb);
  749. if (aa < bb) {
  750. return order * -1;
  751. }
  752. return order;
  753. }
  754. if (aa === bb) {
  755. return 0;
  756. }
  757. // If value is not a string, convert to string
  758. if (typeof aa !== 'string') {
  759. aa = aa.toString();
  760. }
  761. if (aa.localeCompare(bb) === -1) {
  762. return order * -1;
  763. }
  764. return order;
  765. });
  766. }
  767. };
  768. BootstrapTable.prototype.onSort = function (event) {
  769. var $this = $(event.currentTarget).parent(),
  770. $this_ = this.$header.find('th').eq($this.index());
  771. this.$header.add(this.$header_).find('span.order').remove();
  772. if (this.options.sortName === $this.data('field')) {
  773. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  774. } else {
  775. this.options.sortName = $this.data('field');
  776. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  777. }
  778. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  779. $this.add($this_).data('order', this.options.sortOrder);
  780. // Assign the correct sortable arrow
  781. this.getCaret();
  782. if (this.options.sidePagination === 'server') {
  783. this.initServer(this.options.silentSort);
  784. return;
  785. }
  786. this.initSort();
  787. this.initBody();
  788. };
  789. BootstrapTable.prototype.initToolbar = function () {
  790. var that = this,
  791. html = [],
  792. timeoutId = 0,
  793. $keepOpen,
  794. $search,
  795. switchableCount = 0;
  796. this.$toolbar.html('');
  797. if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
  798. $(sprintf('<div class="bars pull-%s"></div>', this.options.toolbarAlign))
  799. .appendTo(this.$toolbar)
  800. .append($(this.options.toolbar));
  801. }
  802. // showColumns, showToggle, showRefresh
  803. html = [sprintf('<div class="columns columns-%s btn-group pull-%s">',
  804. this.options.buttonsAlign, this.options.buttonsAlign)];
  805. if (typeof this.options.icons === 'string') {
  806. this.options.icons = calculateObjectValue(null, this.options.icons);
  807. }
  808. if (this.options.showPaginationSwitch) {
  809. html.push(sprintf('<button class="btn btn-default" type="button" name="paginationSwitch" title="%s">',
  810. this.options.formatPaginationSwitch()),
  811. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
  812. '</button>');
  813. }
  814. if (this.options.showRefresh) {
  815. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="refresh" title="%s">',
  816. this.options.formatRefresh()),
  817. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
  818. '</button>');
  819. }
  820. if (this.options.showToggle) {
  821. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="toggle" title="%s">',
  822. this.options.formatToggle()),
  823. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
  824. '</button>');
  825. }
  826. if (this.options.showColumns) {
  827. html.push(sprintf('<div class="keep-open btn-group" title="%s">',
  828. this.options.formatColumns()),
  829. '<button type="button" class="btn btn-default' + (this.options.iconSize == undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
  830. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
  831. ' <span class="caret"></span>',
  832. '</button>',
  833. '<ul class="dropdown-menu" role="menu">');
  834. $.each(this.columns, function (i, column) {
  835. if (column.radio || column.checkbox) {
  836. return;
  837. }
  838. if (that.options.cardView && (!column.cardVisible)) {
  839. return;
  840. }
  841. var checked = column.visible ? ' checked="checked"' : '';
  842. if (column.switchable) {
  843. html.push(sprintf('<li>' +
  844. '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
  845. '</li>', column.field, i, checked, column.title));
  846. switchableCount++;
  847. }
  848. });
  849. html.push('</ul>',
  850. '</div>');
  851. }
  852. html.push('</div>');
  853. // Fix #188: this.showToolbar is for extentions
  854. if (this.showToolbar || html.length > 2) {
  855. this.$toolbar.append(html.join(''));
  856. }
  857. if (this.options.showPaginationSwitch) {
  858. this.$toolbar.find('button[name="paginationSwitch"]')
  859. .off('click').on('click', $.proxy(this.togglePagination, this));
  860. }
  861. if (this.options.showRefresh) {
  862. this.$toolbar.find('button[name="refresh"]')
  863. .off('click').on('click', $.proxy(this.refresh, this));
  864. }
  865. if (this.options.showToggle) {
  866. this.$toolbar.find('button[name="toggle"]')
  867. .off('click').on('click', function () {
  868. that.toggleView();
  869. });
  870. }
  871. if (this.options.showColumns) {
  872. $keepOpen = this.$toolbar.find('.keep-open');
  873. if (switchableCount <= this.options.minimumCountColumns) {
  874. $keepOpen.find('input').prop('disabled', true);
  875. }
  876. $keepOpen.find('li').off('click').on('click', function (event) {
  877. event.stopImmediatePropagation();
  878. });
  879. $keepOpen.find('input').off('click').on('click', function () {
  880. var $this = $(this);
  881. that.toggleColumn(getFieldIndex(that.columns,
  882. $(this).data('field')), $this.prop('checked'), false);
  883. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  884. });
  885. }
  886. if (this.options.search) {
  887. html = [];
  888. html.push(
  889. '<div class="pull-' + this.options.searchAlign + ' search">',
  890. sprintf('<input class="form-control' + (this.options.iconSize === undefined ? '' : ' input-' + this.options.iconSize) + '" type="text" placeholder="%s">',
  891. this.options.formatSearch()),
  892. '</div>');
  893. this.$toolbar.append(html.join(''));
  894. $search = this.$toolbar.find('.search input');
  895. $search.off('keyup drop').on('keyup drop', function (event) {
  896. clearTimeout(timeoutId); // doesn't matter if it's 0
  897. timeoutId = setTimeout(function () {
  898. that.onSearch(event);
  899. }, that.options.searchTimeOut);
  900. });
  901. if (this.options.searchText !== '') {
  902. $search.val(this.options.searchText);
  903. that.onSearch({currentTarget: $search});
  904. }
  905. }
  906. };
  907. BootstrapTable.prototype.onSearch = function (event) {
  908. var text = $.trim($(event.currentTarget).val());
  909. // trim search input
  910. if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
  911. $(event.currentTarget).val(text);
  912. }
  913. if (text === this.searchText) {
  914. return;
  915. }
  916. this.searchText = text;
  917. this.options.pageNumber = 1;
  918. this.initSearch();
  919. this.updatePagination();
  920. this.trigger('search', text);
  921. };
  922. BootstrapTable.prototype.initSearch = function () {
  923. var that = this;
  924. if (this.options.sidePagination !== 'server') {
  925. var s = this.searchText && this.searchText.toLowerCase();
  926. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  927. // Check filter
  928. this.data = f ? $.grep(this.options.data, function (item, i) {
  929. for (var key in f) {
  930. if (item[key] !== f[key]) {
  931. return false;
  932. }
  933. }
  934. return true;
  935. }) : this.options.data;
  936. this.data = s ? $.grep(this.data, function (item, i) {
  937. for (var key in item) {
  938. key = $.isNumeric(key) ? parseInt(key, 10) : key;
  939. var value = item[key],
  940. column = that.columns[getFieldIndex(that.columns, key)],
  941. j = $.inArray(key, that.header.fields);
  942. // Fix #142: search use formated data
  943. if (column && column.searchFormatter) {
  944. value = calculateObjectValue(column,
  945. that.header.formatters[j], [value, item, i], value);
  946. }
  947. var index = $.inArray(key, that.header.fields);
  948. if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
  949. if (that.options.strictSearch) {
  950. if ((value + '').toLowerCase() === s) {
  951. return true;
  952. }
  953. } else {
  954. if ((value + '').toLowerCase().indexOf(s) !== -1) {
  955. return true;
  956. }
  957. }
  958. }
  959. }
  960. return false;
  961. }) : this.data;
  962. }
  963. };
  964. BootstrapTable.prototype.initPagination = function () {
  965. if (!this.options.pagination) {
  966. this.$pagination.hide();
  967. return;
  968. } else {
  969. this.$pagination.show();
  970. }
  971. var that = this,
  972. html = [],
  973. $allSelected = false,
  974. i, from, to,
  975. $pageList,
  976. $first, $pre,
  977. $next, $last,
  978. $number,
  979. data = this.getData();
  980. if (this.options.sidePagination !== 'server') {
  981. this.options.totalRows = data.length;
  982. }
  983. this.totalPages = 0;
  984. if (this.options.totalRows) {
  985. if (this.options.pageSize === this.options.formatAllRows()) {
  986. this.options.pageSize = this.options.totalRows;
  987. $allSelected = true;
  988. } else if (this.options.pageSize === this.options.totalRows) {
  989. // Fix #667 Table with pagination,
  990. // multiple pages and a search that matches to one page throws exception
  991. var pageLst = typeof this.options.pageList === 'string' ?
  992. this.options.pageList.replace('[', '').replace(']', '')
  993. .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
  994. if (pageLst.indexOf(this.options.formatAllRows().toLowerCase()) > -1) {
  995. $allSelected = true;
  996. }
  997. }
  998. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  999. this.options.totalPages = this.totalPages;
  1000. }
  1001. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  1002. this.options.pageNumber = this.totalPages;
  1003. }
  1004. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  1005. this.pageTo = this.options.pageNumber * this.options.pageSize;
  1006. if (this.pageTo > this.options.totalRows) {
  1007. this.pageTo = this.options.totalRows;
  1008. }
  1009. html.push(
  1010. '<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
  1011. '<span class="pagination-info">',
  1012. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  1013. '</span>');
  1014. html.push('<span class="page-list">');
  1015. var pageNumber = [
  1016. sprintf('<span class="btn-group %s">',
  1017. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  1018. 'dropdown' : 'dropup'),
  1019. '<button type="button" class="btn btn-default ' +
  1020. (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
  1021. ' dropdown-toggle" data-toggle="dropdown">',
  1022. '<span class="page-size">',
  1023. $allSelected ? this.options.formatAllRows() : this.options.pageSize,
  1024. '</span>',
  1025. ' <span class="caret"></span>',
  1026. '</button>',
  1027. '<ul class="dropdown-menu" role="menu">'
  1028. ],
  1029. pageList = this.options.pageList;
  1030. if (typeof this.options.pageList === 'string') {
  1031. var list = this.options.pageList.replace('[', '').replace(']', '')
  1032. .replace(/ /g, '').split(',');
  1033. pageList = [];
  1034. $.each(list, function (i, value) {
  1035. pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
  1036. that.options.formatAllRows() : +value);
  1037. });
  1038. }
  1039. $.each(pageList, function (i, page) {
  1040. if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
  1041. var active;
  1042. if ($allSelected) {
  1043. active = page === that.options.formatAllRows() ? ' class="active"' : '';
  1044. } else {
  1045. active = page === that.options.pageSize ? ' class="active"' : '';
  1046. }
  1047. pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
  1048. }
  1049. });
  1050. pageNumber.push('</ul></span>');
  1051. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  1052. html.push('</span>');
  1053. html.push('</div>',
  1054. '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
  1055. '<ul class="pagination' + (this.options.iconSize === undefined ? '' : ' pagination-' + this.options.iconSize) + '">',
  1056. '<li class="page-first"><a href="javascript:void(0)">' + this.options.paginationFirstText + '</a></li>',
  1057. '<li class="page-pre"><a href="javascript:void(0)">' + this.options.paginationPreText + '</a></li>');
  1058. if (this.totalPages < 5) {
  1059. from = 1;
  1060. to = this.totalPages;
  1061. } else {
  1062. from = this.options.pageNumber - 2;
  1063. to = from + 4;
  1064. if (from < 1) {
  1065. from = 1;
  1066. to = 5;
  1067. }
  1068. if (to > this.totalPages) {
  1069. to = this.totalPages;
  1070. from = to - 4;
  1071. }
  1072. }
  1073. for (i = from; i <= to; i++) {
  1074. html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
  1075. '<a href="javascript:void(0)">', i, '</a>',
  1076. '</li>');
  1077. }
  1078. html.push(
  1079. '<li class="page-next"><a href="javascript:void(0)">' + this.options.paginationNextText + '</a></li>',
  1080. '<li class="page-last"><a href="javascript:void(0)">' + this.options.paginationLastText + '</a></li>',
  1081. '</ul>',
  1082. '</div>');
  1083. this.$pagination.html(html.join(''));
  1084. $pageList = this.$pagination.find('.page-list a');
  1085. $first = this.$pagination.find('.page-first');
  1086. $pre = this.$pagination.find('.page-pre');
  1087. $next = this.$pagination.find('.page-next');
  1088. $last = this.$pagination.find('.page-last');
  1089. $number = this.$pagination.find('.page-number');
  1090. if (this.options.pageNumber <= 1) {
  1091. $first.addClass('disabled');
  1092. $pre.addClass('disabled');
  1093. }
  1094. if (this.options.pageNumber >= this.totalPages) {
  1095. $next.addClass('disabled');
  1096. $last.addClass('disabled');
  1097. }
  1098. if (this.options.smartDisplay) {
  1099. if (this.totalPages <= 1) {
  1100. this.$pagination.find('div.pagination').hide();
  1101. }
  1102. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  1103. this.$pagination.find('span.page-list').hide();
  1104. }
  1105. // when data is empty, hide the pagination
  1106. this.$pagination[this.getData().length ? 'show' : 'hide']();
  1107. }
  1108. if ($allSelected) {
  1109. this.options.pageSize = this.options.formatAllRows();
  1110. }
  1111. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  1112. $first.off('click').on('click', $.proxy(this.onPageFirst, this));
  1113. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1114. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1115. $last.off('click').on('click', $.proxy(this.onPageLast, this));
  1116. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1117. };
  1118. BootstrapTable.prototype.updatePagination = function (event) {
  1119. // Fix #171: IE disabled button can be clicked bug.
  1120. if (event && $(event.currentTarget).hasClass('disabled')) {
  1121. return;
  1122. }
  1123. if (!this.options.maintainSelected) {
  1124. this.resetRows();
  1125. }
  1126. this.initPagination();
  1127. if (this.options.sidePagination === 'server') {
  1128. this.initServer();
  1129. } else {
  1130. this.initBody();
  1131. }
  1132. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1133. };
  1134. BootstrapTable.prototype.onPageListChange = function (event) {
  1135. var $this = $(event.currentTarget);
  1136. $this.parent().addClass('active').siblings().removeClass('active');
  1137. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
  1138. this.options.formatAllRows() : +$this.text();
  1139. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1140. this.updatePagination(event);
  1141. };
  1142. BootstrapTable.prototype.onPageFirst = function (event) {
  1143. this.options.pageNumber = 1;
  1144. this.updatePagination(event);
  1145. };
  1146. BootstrapTable.prototype.onPagePre = function (event) {
  1147. this.options.pageNumber--;
  1148. this.updatePagination(event);
  1149. };
  1150. BootstrapTable.prototype.onPageNext = function (event) {
  1151. this.options.pageNumber++;
  1152. this.updatePagination(event);
  1153. };
  1154. BootstrapTable.prototype.onPageLast = function (event) {
  1155. this.options.pageNumber = this.totalPages;
  1156. this.updatePagination(event);
  1157. };
  1158. BootstrapTable.prototype.onPageNumber = function (event) {
  1159. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1160. return;
  1161. }
  1162. this.options.pageNumber = +$(event.currentTarget).text();
  1163. this.updatePagination(event);
  1164. };
  1165. BootstrapTable.prototype.initBody = function (fixedScroll) {
  1166. var that = this,
  1167. html = [],
  1168. data = this.getData();
  1169. this.trigger('pre-body', data);
  1170. this.$body = this.$el.find('tbody');
  1171. if (!this.$body.length) {
  1172. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1173. }
  1174. //Fix #389 Bootstrap-table-flatJSON is not working
  1175. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1176. this.pageFrom = 1;
  1177. this.pageTo = data.length;
  1178. }
  1179. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1180. var key,
  1181. item = data[i],
  1182. style = {},
  1183. csses = [],
  1184. data_ = '',
  1185. attributes = {},
  1186. htmlAttributes = [];
  1187. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1188. if (style && style.css) {
  1189. for (key in style.css) {
  1190. csses.push(key + ': ' + style.css[key]);
  1191. }
  1192. }
  1193. attributes = calculateObjectValue(this.options,
  1194. this.options.rowAttributes, [item, i], attributes);
  1195. if (attributes) {
  1196. for (key in attributes) {
  1197. htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
  1198. }
  1199. }
  1200. if (item._data && !$.isEmptyObject(item._data)) {
  1201. $.each(item._data, function (k, v) {
  1202. // ignore data-index
  1203. if (k === 'index') {
  1204. return;
  1205. }
  1206. data_ += sprintf(' data-%s="%s"', k, v);
  1207. });
  1208. }
  1209. html.push('<tr',
  1210. sprintf(' %s', htmlAttributes.join(' ')),
  1211. sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
  1212. sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
  1213. sprintf(' data-index="%s"', i),
  1214. sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
  1215. sprintf('%s', data_),
  1216. '>'
  1217. );
  1218. if (this.options.cardView) {
  1219. html.push(sprintf('<td colspan="%s">', this.header.fields.length));
  1220. }
  1221. if (!this.options.cardView && this.options.detailView) {
  1222. html.push('<td>',
  1223. '<a class="detail-icon" href="javascript:">',
  1224. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
  1225. '</a>',
  1226. '</td>');
  1227. }
  1228. $.each(this.header.fields, function (j, field) {
  1229. var text = '',
  1230. value = item[field],
  1231. type = '',
  1232. cellStyle = {},
  1233. id_ = '',
  1234. class_ = that.header.classes[j],
  1235. data_ = '',
  1236. rowspan_ = '',
  1237. title_ = '',
  1238. column = that.columns[getFieldIndex(that.columns, field)];
  1239. if (!column.visible) {
  1240. return;
  1241. }
  1242. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  1243. value = calculateObjectValue(column,
  1244. that.header.formatters[j], [value, item, i], value);
  1245. // handle td's id and class
  1246. if (item['_' + field + '_id']) {
  1247. id_ = sprintf(' id="%s"', item['_' + field + '_id']);
  1248. }
  1249. if (item['_' + field + '_class']) {
  1250. class_ = sprintf(' class="%s"', item['_' + field + '_class']);
  1251. }
  1252. if (item['_' + field + '_rowspan']) {
  1253. rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1254. }
  1255. if (item['_' + field + '_title']) {
  1256. title_ = sprintf(' title="%s"', item['_' + field + '_title']);
  1257. }
  1258. cellStyle = calculateObjectValue(that.header,
  1259. that.header.cellStyles[j], [value, item, i], cellStyle);
  1260. if (cellStyle.classes) {
  1261. class_ = sprintf(' class="%s"', cellStyle.classes);
  1262. }
  1263. if (cellStyle.css) {
  1264. var csses_ = [];
  1265. for (var key in cellStyle.css) {
  1266. csses_.push(key + ': ' + cellStyle.css[key]);
  1267. }
  1268. style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
  1269. }
  1270. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1271. $.each(item['_' + field + '_data'], function (k, v) {
  1272. // ignore data-index
  1273. if (k === 'index') {
  1274. return;
  1275. }
  1276. data_ += sprintf(' data-%s="%s"', k, v);
  1277. });
  1278. }
  1279. if (column.checkbox || column.radio) {
  1280. type = column.checkbox ? 'checkbox' : type;
  1281. type = column.radio ? 'radio' : type;
  1282. text = [that.options.cardView ?
  1283. '<div class="card-view">' : '<td class="bs-checkbox">',
  1284. '<input' +
  1285. sprintf(' data-index="%s"', i) +
  1286. sprintf(' name="%s"', that.options.selectItemName) +
  1287. sprintf(' type="%s"', type) +
  1288. sprintf(' value="%s"', item[that.options.idField]) +
  1289. sprintf(' checked="%s"', value === true ||
  1290. (value && value.checked) ? 'checked' : undefined) +
  1291. sprintf(' disabled="%s"', !column.checkboxEnabled ||
  1292. (value && value.disabled) ? 'disabled' : undefined) +
  1293. ' />',
  1294. that.options.cardView ? '</div>' : '</td>'
  1295. ].join('');
  1296. item[that.header.stateField] = value === true || (value && value.checked);
  1297. } else {
  1298. value = typeof value === 'undefined' || value === null ?
  1299. that.options.undefinedText : value;
  1300. text = that.options.cardView ? ['<div class="card-view">',
  1301. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  1302. getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
  1303. sprintf('<span class="value">%s</span>', value),
  1304. '</div>'
  1305. ].join('') : [sprintf('<td%s %s %s %s %s %s>', id_, class_, style, data_, rowspan_, title_),
  1306. value,
  1307. '</td>'
  1308. ].join('');
  1309. // Hide empty data on Card view when smartDisplay is set to true.
  1310. if (that.options.cardView && that.options.smartDisplay && value === '') {
  1311. text = '';
  1312. }
  1313. }
  1314. html.push(text);
  1315. });
  1316. if (this.options.cardView) {
  1317. html.push('</td>');
  1318. }
  1319. html.push('</tr>');
  1320. }
  1321. // show no records
  1322. if (!html.length) {
  1323. html.push('<tr class="no-records-found">',
  1324. sprintf('<td colspan="%s">%s</td>',
  1325. this.$header.find('th').length, this.options.formatNoMatches()),
  1326. '</tr>');
  1327. }
  1328. this.$body.html(html.join(''));
  1329. if (!fixedScroll) {
  1330. this.scrollTo(0);
  1331. }
  1332. // click to select by column
  1333. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
  1334. var $td = $(this),
  1335. $tr = $td.parent(),
  1336. item = that.data[$tr.data('index')],
  1337. index = $td[0].cellIndex,
  1338. field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
  1339. colomn = that.columns[getFieldIndex(that.columns, field)],
  1340. value = item[field];
  1341. if ($td.find('.detail-icon').length) {
  1342. return;
  1343. }
  1344. that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  1345. that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr);
  1346. // if click to select - then trigger the checkbox/radio click
  1347. if (e.type === 'click' && that.options.clickToSelect && colomn.clickToSelect) {
  1348. var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
  1349. if ($selectItem.length) {
  1350. $selectItem[0].click(); // #144: .trigger('click') bug
  1351. }
  1352. }
  1353. });
  1354. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function () {
  1355. var $this = $(this),
  1356. $tr = $this.parent().parent(),
  1357. index = $tr.data('index'),
  1358. row = data[index]; // Fix #980 Detail view, when searching, returns wrong row
  1359. // remove and update
  1360. if ($tr.next().is('tr.detail-view')) {
  1361. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailOpen));
  1362. $tr.next().remove();
  1363. that.trigger('collapse-row', index, row);
  1364. } else {
  1365. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
  1366. $tr.after(sprintf('<tr class="detail-view"><td colspan="%s">%s</td></tr>',
  1367. $tr.find('td').length, calculateObjectValue(that.options,
  1368. that.options.detailFormatter, [index, row], '')));
  1369. that.trigger('expand-row', index, row, $tr.next().find('td'));
  1370. }
  1371. that.resetView();
  1372. });
  1373. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  1374. this.$selectItem.off('click').on('click', function (event) {
  1375. event.stopImmediatePropagation();
  1376. var checked = $(this).prop('checked'),
  1377. row = that.data[$(this).data('index')];
  1378. row[that.header.stateField] = checked;
  1379. if (that.options.singleSelect) {
  1380. that.$selectItem.not(this).each(function () {
  1381. that.data[$(this).data('index')][that.header.stateField] = false;
  1382. });
  1383. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  1384. }
  1385. that.updateSelected();
  1386. that.trigger(checked ? 'check' : 'uncheck', row);
  1387. });
  1388. $.each(this.header.events, function (i, events) {
  1389. if (!events) {
  1390. return;
  1391. }
  1392. // fix bug, if events is defined with namespace
  1393. if (typeof events === 'string') {
  1394. events = calculateObjectValue(null, events);
  1395. }
  1396. var field = that.header.fields[i],
  1397. fieldIndex = $.inArray(field, that.getVisibleFields());
  1398. if (that.options.detailView && !that.options.cardView) {
  1399. fieldIndex += 1;
  1400. }
  1401. for (var key in events) {
  1402. that.$body.find('tr').each(function () {
  1403. var $tr = $(this),
  1404. $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
  1405. index = key.indexOf(' '),
  1406. name = key.substring(0, index),
  1407. el = key.substring(index + 1),
  1408. func = events[key];
  1409. $td.find(el).off(name).on(name, function (e) {
  1410. var index = $tr.data('index'),
  1411. row = that.data[index],
  1412. value = row[field];
  1413. func.apply(this, [e, value, row, index]);
  1414. });
  1415. });
  1416. }
  1417. });
  1418. this.updateSelected();
  1419. this.resetView();
  1420. this.trigger('post-body');
  1421. };
  1422. BootstrapTable.prototype.initServer = function (silent, query) {
  1423. var that = this,
  1424. data = {},
  1425. params = {
  1426. pageSize: this.options.pageSize === this.options.formatAllRows() ?
  1427. this.options.totalRows : this.options.pageSize,
  1428. pageNumber: this.options.pageNumber,
  1429. searchText: this.searchText,
  1430. sortName: this.options.sortName,
  1431. sortOrder: this.options.sortOrder
  1432. },
  1433. request;
  1434. if (!this.options.url && !this.options.ajax) {
  1435. return;
  1436. }
  1437. if (this.options.queryParamsType === 'limit') {
  1438. params = {
  1439. search: params.searchText,
  1440. sort: params.sortName,
  1441. order: params.sortOrder
  1442. };
  1443. if (this.options.pagination) {
  1444. params.limit = this.options.pageSize === this.options.formatAllRows() ?
  1445. this.options.totalRows : this.options.pageSize;
  1446. params.offset = this.options.pageSize === this.options.formatAllRows() ?
  1447. 0 : this.options.pageSize * (this.options.pageNumber - 1);
  1448. }
  1449. }
  1450. if (!($.isEmptyObject(this.filterColumnsPartial))) {
  1451. params['filter'] = JSON.stringify(this.filterColumnsPartial, null);
  1452. }
  1453. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  1454. $.extend(data, query || {});
  1455. // false to stop request
  1456. if (data === false) {
  1457. return;
  1458. }
  1459. if (!silent) {
  1460. this.$tableLoading.show();
  1461. }
  1462. request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
  1463. type: this.options.method,
  1464. url: this.options.url,
  1465. data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
  1466. JSON.stringify(data) : data,
  1467. cache: this.options.cache,
  1468. contentType: this.options.contentType,
  1469. dataType: this.options.dataType,
  1470. success: function (res) {
  1471. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  1472. that.load(res);
  1473. that.trigger('load-success', res);
  1474. },
  1475. error: function (res) {
  1476. that.trigger('load-error', res.status);
  1477. },
  1478. complete: function () {
  1479. if (!silent) {
  1480. that.$tableLoading.hide();
  1481. }
  1482. }
  1483. });
  1484. if (this.options.ajax) {
  1485. calculateObjectValue(this, this.options.ajax, [request], null);
  1486. } else {
  1487. $.ajax(request);
  1488. }
  1489. };
  1490. BootstrapTable.prototype.getCaret = function () {
  1491. var that = this;
  1492. $.each(this.$header.find('th'), function (i, th) {
  1493. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === that.options.sortName ? that.options.sortOrder : 'both');
  1494. });
  1495. };
  1496. BootstrapTable.prototype.updateSelected = function () {
  1497. var checkAll = this.$selectItem.filter(':enabled').length ===
  1498. this.$selectItem.filter(':enabled').filter(':checked').length;
  1499. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  1500. this.$selectItem.each(function () {
  1501. $(this).closest('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  1502. });
  1503. };
  1504. BootstrapTable.prototype.updateRows = function () {
  1505. var that = this;
  1506. this.$selectItem.each(function () {
  1507. that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
  1508. });
  1509. };
  1510. BootstrapTable.prototype.resetRows = function () {
  1511. var that = this;
  1512. $.each(this.data, function (i, row) {
  1513. that.$selectAll.prop('checked', false);
  1514. that.$selectItem.prop('checked', false);
  1515. if (that.header.stateField) {
  1516. row[that.header.stateField] = false;
  1517. }
  1518. });
  1519. };
  1520. BootstrapTable.prototype.trigger = function (name) {
  1521. var args = Array.prototype.slice.call(arguments, 1);
  1522. name += '.bs.table';
  1523. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  1524. this.$el.trigger($.Event(name), args);
  1525. this.options.onAll(name, args);
  1526. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  1527. };
  1528. BootstrapTable.prototype.resetHeader = function () {
  1529. // fix #61: the hidden table reset header bug.
  1530. // fix bug: get $el.css('width') error sometime (height = 500)
  1531. clearTimeout(this.timeoutId_);
  1532. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  1533. };
  1534. BootstrapTable.prototype.fitHeader = function () {
  1535. var that = this,
  1536. fixedBody,
  1537. scrollWidth;
  1538. if (that.$el.is(':hidden')) {
  1539. that.timeoutId_ = setTimeout($.proxy(that.fitHeader, that), 100);
  1540. return;
  1541. }
  1542. fixedBody = this.$tableBody.get(0);
  1543. scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
  1544. fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
  1545. getScrollBarWidth() : 0;
  1546. this.$el.css('margin-top', -this.$header.outerHeight());
  1547. this.$header_ = this.$header.clone(true, true);
  1548. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  1549. this.$tableHeader.css({
  1550. 'margin-right': scrollWidth
  1551. }).find('table').css('width', this.$el.outerWidth())
  1552. .html('').attr('class', this.$el.attr('class'))
  1553. .append(this.$header_);
  1554. // fix bug: $.data() is not working as expected after $.append()
  1555. this.$header.find('th[data-field]').each(function (i) {
  1556. that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
  1557. });
  1558. var visibleFields = this.getVisibleFields();
  1559. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  1560. var $this = $(this),
  1561. index = i;
  1562. if (that.options.detailView && !that.options.cardView) {
  1563. if (i === 0) {
  1564. that.$header_.find('th.detail').find('.fht-cell').width($this.innerWidth());
  1565. }
  1566. index = i - 1;
  1567. }
  1568. that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]))
  1569. .find('.fht-cell').width($this.innerWidth());
  1570. });
  1571. // horizontal scroll event
  1572. // TODO: it's probably better improving the layout than binding to scroll event
  1573. this.$tableBody.off('scroll').on('scroll', function () {
  1574. that.$tableHeader.scrollLeft($(this).scrollLeft());
  1575. if (that.options.showFooter && !that.options.cardView) {
  1576. that.$tableFooter.scrollLeft($(this).scrollLeft());
  1577. }
  1578. });
  1579. that.trigger('post-header');
  1580. };
  1581. BootstrapTable.prototype.resetFooter = function () {
  1582. var that = this,
  1583. data = that.getData(),
  1584. html = [];
  1585. if (!this.options.showFooter || this.options.cardView) { //do nothing
  1586. return;
  1587. }
  1588. if (!this.options.cardView && this.options.detailView) {
  1589. html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
  1590. }
  1591. $.each(this.columns, function (i, column) {
  1592. var falign = '', // footer align style
  1593. style = '',
  1594. class_ = sprintf(' class="%s"', column['class']);
  1595. if (!column.visible) {
  1596. return;
  1597. }
  1598. if (that.options.cardView && (!column.cardVisible)) {
  1599. return;
  1600. }
  1601. falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  1602. style = sprintf('vertical-align: %s; ', column.valign);
  1603. html.push('<td', class_, sprintf(' style="%s"', falign + style), '>');
  1604. html.push('<div class="th-inner">');
  1605. html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  1606. html.push('</div>');
  1607. html.push('<div class="fht-cell"></div>');
  1608. html.push('</div>');
  1609. html.push('</td>');
  1610. });
  1611. this.$tableFooter.find('tr').html(html.join(''));
  1612. clearTimeout(this.timeoutFooter_);
  1613. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
  1614. this.$el.is(':hidden') ? 100 : 0);
  1615. };
  1616. BootstrapTable.prototype.fitFooter = function () {
  1617. var that = this,
  1618. $footerTd,
  1619. elWidth,
  1620. scrollWidth;
  1621. clearTimeout(this.timeoutFooter_);
  1622. if (this.$el.is(':hidden')) {
  1623. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  1624. return;
  1625. }
  1626. elWidth = this.$el.css('width');
  1627. scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
  1628. this.$tableFooter.css({
  1629. 'margin-right': scrollWidth
  1630. }).find('table').css('width', elWidth)
  1631. .attr('class', this.$el.attr('class'));
  1632. $footerTd = this.$tableFooter.find('td');
  1633. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  1634. var $this = $(this);
  1635. $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
  1636. });
  1637. };
  1638. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  1639. if (index === -1) {
  1640. return;
  1641. }
  1642. this.columns[index].visible = checked;
  1643. this.initHeader();
  1644. this.initSearch();
  1645. this.initPagination();
  1646. this.initBody();
  1647. if (this.options.showColumns) {
  1648. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  1649. if (needUpdate) {
  1650. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  1651. }
  1652. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  1653. $items.filter(':checked').prop('disabled', true);
  1654. }
  1655. }
  1656. };
  1657. BootstrapTable.prototype.toggleRow = function (index, isIdField, visible) {
  1658. if (index === -1) {
  1659. return;
  1660. }
  1661. $(this.$body[0]).children().filter(sprintf(isIdField ? '[data-uniqueid="%s"]' : '[data-index="%s"]', index))[visible ? 'show' : 'hide']();
  1662. };
  1663. BootstrapTable.prototype.getVisibleFields = function () {
  1664. var that = this,
  1665. visibleFields = [];
  1666. $.each(this.header.fields, function (j, field) {
  1667. var column = that.columns[getFieldIndex(that.columns, field)];
  1668. if (!column.visible) {
  1669. return;
  1670. }
  1671. visibleFields.push(field);
  1672. });
  1673. return visibleFields;
  1674. };
  1675. // PUBLIC FUNCTION DEFINITION
  1676. // =======================
  1677. BootstrapTable.prototype.resetView = function (params) {
  1678. var padding = 0;
  1679. if (params && params.height) {
  1680. this.options.height = params.height;
  1681. }
  1682. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  1683. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  1684. if (this.options.height) {
  1685. var toolbarHeight = getRealHeight(this.$toolbar),
  1686. paginationHeight = getRealHeight(this.$pagination),
  1687. height = this.options.height - toolbarHeight - paginationHeight;
  1688. this.$tableContainer.css('height', height + 'px');
  1689. }
  1690. if (this.options.cardView) {
  1691. // remove the element css
  1692. this.$el.css('margin-top', '0');
  1693. this.$tableContainer.css('padding-bottom', '0');
  1694. return;
  1695. }
  1696. if (this.options.showHeader && this.options.height) {
  1697. this.$tableHeader.show();
  1698. this.resetHeader();
  1699. padding += this.$header.outerHeight();
  1700. } else {
  1701. this.$tableHeader.hide();
  1702. this.trigger('post-header');
  1703. }
  1704. if (this.options.showFooter) {
  1705. this.resetFooter();
  1706. if (this.options.height) {
  1707. padding += this.$tableFooter.outerHeight() + 1;
  1708. }
  1709. }
  1710. // Assign the correct sortable arrow
  1711. this.getCaret();
  1712. this.$tableContainer.css('padding-bottom', padding + 'px');
  1713. this.trigger('reset-view');
  1714. };
  1715. BootstrapTable.prototype.getData = function (useCurrentPage) {
  1716. return (this.searchText || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) ?
  1717. (useCurrentPage ? this.data.slice(this.pageFrom - 1, this.pageTo) : this.data) :
  1718. (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo) : this.options.data);
  1719. };
  1720. BootstrapTable.prototype.load = function (data) {
  1721. var fixedScroll = false;
  1722. // #431: support pagination
  1723. if (this.options.sidePagination === 'server') {
  1724. this.options.totalRows = data.total;
  1725. fixedScroll = data.fixedScroll;
  1726. data = data.rows;
  1727. } else if (!$.isArray(data)) { // support fixedScroll
  1728. fixedScroll = data.fixedScroll;
  1729. data = data.data;
  1730. }
  1731. this.initData(data);
  1732. this.initSearch();
  1733. this.initPagination();
  1734. this.initBody(fixedScroll);
  1735. };
  1736. BootstrapTable.prototype.append = function (data) {
  1737. this.initData(data, 'append');
  1738. this.initSearch();
  1739. this.initPagination();
  1740. this.initBody(true);
  1741. };
  1742. BootstrapTable.prototype.prepend = function (data) {
  1743. this.initData(data, 'prepend');
  1744. this.initSearch();
  1745. this.initPagination();
  1746. this.initBody(true);
  1747. };
  1748. BootstrapTable.prototype.remove = function (params) {
  1749. var len = this.options.data.length,
  1750. i, row;
  1751. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  1752. return;
  1753. }
  1754. for (i = len - 1; i >= 0; i--) {
  1755. row = this.options.data[i];
  1756. if (!row.hasOwnProperty(params.field)) {
  1757. continue;
  1758. }
  1759. if ($.inArray(row[params.field], params.values) !== -1) {
  1760. this.options.data.splice(i, 1);
  1761. }
  1762. }
  1763. if (len === this.options.data.length) {
  1764. return;
  1765. }
  1766. this.initSearch();
  1767. this.initPagination();
  1768. this.initBody(true);
  1769. };
  1770. BootstrapTable.prototype.removeAll = function () {
  1771. if (this.options.data.length > 0) {
  1772. this.options.data.splice(0, this.options.data.length);
  1773. this.initSearch();
  1774. this.initPagination();
  1775. this.initBody(true);
  1776. }
  1777. };
  1778. BootstrapTable.prototype.getRowByUniqueId = function (id) {
  1779. var uniqueId = this.options.uniqueId,
  1780. len = this.options.data.length,
  1781. dataRow = null,
  1782. i, row;
  1783. for (i = len - 1; i >= 0; i--) {
  1784. row = this.options.data[i];
  1785. if (!row.hasOwnProperty(uniqueId)) {
  1786. continue;
  1787. }
  1788. if (typeof row[uniqueId] === 'string') {
  1789. id = id.toString();
  1790. } else if (typeof row[uniqueId] === 'number') {
  1791. if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
  1792. id = parseInt(id);
  1793. } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
  1794. id = parseFloat(id);
  1795. }
  1796. }
  1797. if (row[uniqueId] === id) {
  1798. dataRow = row;
  1799. break;
  1800. }
  1801. }
  1802. return dataRow;
  1803. };
  1804. BootstrapTable.prototype.removeByUniqueId = function (id) {
  1805. var len = this.options.data.length,
  1806. row = this.getRowByUniqueId(id);
  1807. if (row) {
  1808. this.options.data.splice(this.options.data.indexOf(row), 1);
  1809. }
  1810. if (len === this.options.data.length) {
  1811. return;
  1812. }
  1813. this.initSearch();
  1814. this.initPagination();
  1815. this.initBody(true);
  1816. };
  1817. BootstrapTable.prototype.insertRow = function (params) {
  1818. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1819. return;
  1820. }
  1821. this.data.splice(params.index, 0, params.row);
  1822. this.initSearch();
  1823. this.initPagination();
  1824. this.initSort();
  1825. this.initBody(true);
  1826. };
  1827. BootstrapTable.prototype.updateRow = function (params) {
  1828. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1829. return;
  1830. }
  1831. $.extend(this.data[params.index], params.row);
  1832. this.initSort();
  1833. this.initBody(true);
  1834. };
  1835. BootstrapTable.prototype.showRow = function (params) {
  1836. if (!params.hasOwnProperty('index')) {
  1837. return;
  1838. }
  1839. this.toggleRow(params.index, params.isIdField === undefined ? false : true, true);
  1840. };
  1841. BootstrapTable.prototype.hideRow = function (params) {
  1842. if (!params.hasOwnProperty('index')) {
  1843. return;
  1844. }
  1845. this.toggleRow(params.index, params.isIdField === undefined ? false : true, false);
  1846. };
  1847. BootstrapTable.prototype.getRowsHidden = function (show) {
  1848. var rows = $(this.$body[0]).children().filter(':hidden'),
  1849. i = 0;
  1850. if (show) {
  1851. for (; i < rows.length; i++) {
  1852. $(rows[i]).show();
  1853. }
  1854. }
  1855. return rows;
  1856. };
  1857. BootstrapTable.prototype.mergeCells = function (options) {
  1858. var row = options.index,
  1859. col = $.inArray(options.field, this.getVisibleFields()),
  1860. rowspan = options.rowspan || 1,
  1861. colspan = options.colspan || 1,
  1862. i, j,
  1863. $tr = this.$body.find('tr'),
  1864. $td;
  1865. if (this.options.detailView && !this.options.cardView) {
  1866. col += 1;
  1867. }
  1868. $td = $tr.eq(row).find('td').eq(col);
  1869. if (row < 0 || col < 0 || row >= this.data.length) {
  1870. return;
  1871. }
  1872. for (i = row; i < row + rowspan; i++) {
  1873. for (j = col; j < col + colspan; j++) {
  1874. $tr.eq(i).find('td').eq(j).hide();
  1875. }
  1876. }
  1877. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  1878. };
  1879. BootstrapTable.prototype.updateCell = function (params) {
  1880. if (!params.hasOwnProperty('rowIndex') || !params.hasOwnProperty('fieldName') || !params.hasOwnProperty('fieldValue')) {
  1881. return;
  1882. }
  1883. this.data[params.rowIndex][params.fieldName] = params.fieldValue;
  1884. this.initSort();
  1885. this.initBody(true);
  1886. };
  1887. BootstrapTable.prototype.getOptions = function () {
  1888. return this.options;
  1889. };
  1890. BootstrapTable.prototype.getSelections = function () {
  1891. var that = this;
  1892. return $.grep(this.data, function (row) {
  1893. return row[that.header.stateField];
  1894. });
  1895. };
  1896. BootstrapTable.prototype.getAllSelections = function () {
  1897. var that = this;
  1898. return $.grep(this.options.data, function (row) {
  1899. return row[that.header.stateField];
  1900. });
  1901. };
  1902. BootstrapTable.prototype.checkAll = function () {
  1903. this.checkAll_(true);
  1904. };
  1905. BootstrapTable.prototype.uncheckAll = function () {
  1906. this.checkAll_(false);
  1907. };
  1908. BootstrapTable.prototype.checkAll_ = function (checked) {
  1909. var rows;
  1910. if (!checked) {
  1911. rows = this.getSelections();
  1912. }
  1913. this.$selectItem.filter(':enabled').prop('checked', checked);
  1914. this.updateRows();
  1915. this.updateSelected();
  1916. if (checked) {
  1917. rows = this.getSelections();
  1918. }
  1919. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  1920. };
  1921. BootstrapTable.prototype.check = function (index) {
  1922. this.check_(true, index);
  1923. };
  1924. BootstrapTable.prototype.uncheck = function (index) {
  1925. this.check_(false, index);
  1926. };
  1927. BootstrapTable.prototype.check_ = function (checked, index) {
  1928. this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1929. this.data[index][this.header.stateField] = checked;
  1930. this.updateSelected();
  1931. this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
  1932. };
  1933. BootstrapTable.prototype.checkBy = function (obj) {
  1934. this.checkBy_(true, obj);
  1935. };
  1936. BootstrapTable.prototype.uncheckBy = function (obj) {
  1937. this.checkBy_(false, obj);
  1938. };
  1939. BootstrapTable.prototype.checkBy_ = function (checked, obj) {
  1940. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  1941. return;
  1942. }
  1943. var that = this,
  1944. rows = [];
  1945. $.each(this.options.data, function (index, row) {
  1946. if (!row.hasOwnProperty(obj.field)) {
  1947. return false;
  1948. }
  1949. if ($.inArray(row[obj.field], obj.values) !== -1) {
  1950. that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1951. row[that.header.stateField] = checked;
  1952. rows.push(row);
  1953. that.trigger(checked ? 'check' : 'uncheck', row);
  1954. }
  1955. });
  1956. this.updateSelected();
  1957. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  1958. };
  1959. BootstrapTable.prototype.destroy = function () {
  1960. this.$el.insertBefore(this.$container);
  1961. $(this.options.toolbar).insertBefore(this.$el);
  1962. this.$container.next().remove();
  1963. this.$container.remove();
  1964. this.$el.html(this.$el_.html())
  1965. .css('margin-top', '0')
  1966. .attr('class', this.$el_.attr('class') || ''); // reset the class
  1967. };
  1968. BootstrapTable.prototype.showLoading = function () {
  1969. this.$tableLoading.show();
  1970. };
  1971. BootstrapTable.prototype.hideLoading = function () {
  1972. this.$tableLoading.hide();
  1973. };
  1974. BootstrapTable.prototype.togglePagination = function () {
  1975. this.options.pagination = !this.options.pagination;
  1976. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  1977. if (this.options.pagination) {
  1978. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
  1979. } else {
  1980. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
  1981. }
  1982. this.updatePagination();
  1983. };
  1984. BootstrapTable.prototype.refresh = function (params) {
  1985. if (params && params.url) {
  1986. this.options.url = params.url;
  1987. this.options.pageNumber = 1;
  1988. }
  1989. this.initServer(params && params.silent, params && params.query);
  1990. };
  1991. BootstrapTable.prototype.resetWidth = function () {
  1992. if (this.options.showHeader && this.options.height) {
  1993. this.fitHeader();
  1994. }
  1995. if (this.options.showFooter) {
  1996. this.fitFooter();
  1997. }
  1998. };
  1999. BootstrapTable.prototype.showColumn = function (field) {
  2000. this.toggleColumn(getFieldIndex(this.columns, field), true, true);
  2001. };
  2002. BootstrapTable.prototype.hideColumn = function (field) {
  2003. this.toggleColumn(getFieldIndex(this.columns, field), false, true);
  2004. };
  2005. BootstrapTable.prototype.getHiddenColumns = function () {
  2006. return $.grep(this.columns, function( column ) {
  2007. return !column.visible;
  2008. });
  2009. };
  2010. BootstrapTable.prototype.filterBy = function (columns) {
  2011. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  2012. this.options.pageNumber = 1;
  2013. this.initSearch();
  2014. this.updatePagination();
  2015. };
  2016. BootstrapTable.prototype.scrollTo = function (value) {
  2017. if (typeof value === 'string') {
  2018. value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
  2019. }
  2020. if (typeof value === 'number') {
  2021. this.$tableBody.scrollTop(value);
  2022. }
  2023. if (typeof value === 'undefined') {
  2024. return this.$tableBody.scrollTop();
  2025. }
  2026. };
  2027. BootstrapTable.prototype.getScrollPosition = function () {
  2028. return this.scrollTo();
  2029. };
  2030. BootstrapTable.prototype.selectPage = function (page) {
  2031. if (page > 0 && page <= this.options.totalPages) {
  2032. this.options.pageNumber = page;
  2033. this.updatePagination();
  2034. }
  2035. };
  2036. BootstrapTable.prototype.prevPage = function () {
  2037. if (this.options.pageNumber > 1) {
  2038. this.options.pageNumber--;
  2039. this.updatePagination();
  2040. }
  2041. };
  2042. BootstrapTable.prototype.nextPage = function () {
  2043. if (this.options.pageNumber < this.options.totalPages) {
  2044. this.options.pageNumber++;
  2045. this.updatePagination();
  2046. }
  2047. };
  2048. BootstrapTable.prototype.toggleView = function () {
  2049. this.options.cardView = !this.options.cardView;
  2050. this.initHeader();
  2051. // Fixed remove toolbar when click cardView button.
  2052. //that.initToolbar();
  2053. this.initBody();
  2054. this.trigger('toggle', this.options.cardView);
  2055. };
  2056. BootstrapTable.prototype.refreshOptions = function (options) {
  2057. //If the objects are equivalent then avoid the call of destroy / init methods
  2058. if (compareObjects(this.options, options, false)) {
  2059. return;
  2060. }
  2061. this.options = $.extend(this.options, options);
  2062. this.trigger('refresh-options', this.options);
  2063. this.destroy();
  2064. this.init();
  2065. };
  2066. BootstrapTable.prototype.resetSearch = function (text) {
  2067. var $search = this.$toolbar.find('.search input');
  2068. $search.val(text || '');
  2069. this.onSearch({currentTarget: $search});
  2070. };
  2071. // BOOTSTRAP TABLE PLUGIN DEFINITION
  2072. // =======================
  2073. var allowedMethods = [
  2074. 'getOptions',
  2075. 'getSelections', 'getAllSelections', 'getData',
  2076. 'load', 'append', 'prepend', 'remove', 'removeAll',
  2077. 'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
  2078. 'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
  2079. 'mergeCells',
  2080. 'checkAll', 'uncheckAll',
  2081. 'check', 'uncheck',
  2082. 'checkBy', 'uncheckBy',
  2083. 'refresh',
  2084. 'resetView',
  2085. 'resetWidth',
  2086. 'destroy',
  2087. 'showLoading', 'hideLoading',
  2088. 'showColumn', 'hideColumn', 'getHiddenColumns',
  2089. 'filterBy',
  2090. 'scrollTo',
  2091. 'getScrollPosition',
  2092. 'selectPage', 'prevPage', 'nextPage',
  2093. 'togglePagination',
  2094. 'toggleView',
  2095. 'refreshOptions',
  2096. 'resetSearch'
  2097. ];
  2098. $.fn.bootstrapTable = function (option) {
  2099. var value,
  2100. args = Array.prototype.slice.call(arguments, 1);
  2101. this.each(function () {
  2102. var $this = $(this),
  2103. data = $this.data('bootstrap.table'),
  2104. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  2105. typeof option === 'object' && option);
  2106. if (typeof option === 'string') {
  2107. if ($.inArray(option, allowedMethods) < 0) {
  2108. throw new Error("Unknown method: " + option);
  2109. }
  2110. if (!data) {
  2111. return;
  2112. }
  2113. value = data[option].apply(data, args);
  2114. if (option === 'destroy') {
  2115. $this.removeData('bootstrap.table');
  2116. }
  2117. }
  2118. if (!data) {
  2119. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  2120. }
  2121. });
  2122. return typeof value === 'undefined' ? this : value;
  2123. };
  2124. $.fn.bootstrapTable.Constructor = BootstrapTable;
  2125. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  2126. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  2127. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  2128. $.fn.bootstrapTable.methods = allowedMethods;
  2129. // BOOTSTRAP TABLE INIT
  2130. // =======================
  2131. $(function () {
  2132. $('[data-toggle="table"]').bootstrapTable();
  2133. });
  2134. }(jQuery);
  2135. // JavaScript source code
  2136. (function () {
  2137. if (typeof angular === 'undefined') {
  2138. return;
  2139. }
  2140. angular.module('bsTable', []).directive('bsTableControl', function () {
  2141. var CONTAINER_SELECTOR = '.bootstrap-table';
  2142. var SCROLLABLE_SELECTOR = '.fixed-table-body';
  2143. var SEARCH_SELECTOR = '.search input';
  2144. var bsTables = {};
  2145. function getBsTable (el) {
  2146. var result;
  2147. $.each(bsTables, function (id, bsTable) {
  2148. if (!bsTable.$el.closest(CONTAINER_SELECTOR).has(el).length) return;
  2149. result = bsTable;
  2150. return true;
  2151. });
  2152. return result;
  2153. }
  2154. $(window).resize(function () {
  2155. $.each(bsTables, function (id, bsTable) {
  2156. bsTable.$el.bootstrapTable('resetView');
  2157. });
  2158. });
  2159. function onScroll () {
  2160. var bsTable = this;
  2161. var state = bsTable.$s.bsTableControl.state;
  2162. bsTable.$s.$applyAsync(function () {
  2163. state.scroll = bsTable.$el.bootstrapTable('getScrollPosition');
  2164. });
  2165. }
  2166. $(document)
  2167. .on('post-header.bs.table', CONTAINER_SELECTOR+' table', function (evt) { // bootstrap-table calls .off('scroll') in initHeader so reattach here
  2168. var bsTable = getBsTable(evt.target);
  2169. if (!bsTable) return;
  2170. bsTable.$el
  2171. .closest(CONTAINER_SELECTOR)
  2172. .find(SCROLLABLE_SELECTOR)
  2173. .on('scroll', onScroll.bind(bsTable));
  2174. })
  2175. .on('sort.bs.table', CONTAINER_SELECTOR+' table', function (evt, sortName, sortOrder) {
  2176. var bsTable = getBsTable(evt.target);
  2177. if (!bsTable) return;
  2178. var state = bsTable.$s.bsTableControl.state;
  2179. bsTable.$s.$applyAsync(function () {
  2180. state.sortName = sortName;
  2181. state.sortOrder = sortOrder;
  2182. });
  2183. })
  2184. .on('page-change.bs.table', CONTAINER_SELECTOR+' table', function (evt, pageNumber, pageSize) {
  2185. var bsTable = getBsTable(evt.target);
  2186. if (!bsTable) return;
  2187. var state = bsTable.$s.bsTableControl.state;
  2188. bsTable.$s.$applyAsync(function () {
  2189. state.pageNumber = pageNumber;
  2190. state.pageSize = pageSize;
  2191. });
  2192. })
  2193. .on('search.bs.table', CONTAINER_SELECTOR+' table', function (evt, searchText) {
  2194. var bsTable = getBsTable(evt.target);
  2195. if (!bsTable) return;
  2196. var state = bsTable.$s.bsTableControl.state;
  2197. bsTable.$s.$applyAsync(function () {
  2198. state.searchText = searchText;
  2199. });
  2200. })
  2201. .on('focus blur', CONTAINER_SELECTOR+' '+SEARCH_SELECTOR, function (evt) {
  2202. var bsTable = getBsTable(evt.target);
  2203. if (!bsTable) return;
  2204. var state = bsTable.$s.bsTableControl.state;
  2205. bsTable.$s.$applyAsync(function () {
  2206. state.searchHasFocus = $(evt.target).is(':focus');
  2207. });
  2208. });
  2209. return {
  2210. restrict: 'EA',
  2211. scope: {bsTableControl: '='},
  2212. link: function ($s, $el) {
  2213. var bsTable = bsTables[$s.$id] = {$s: $s, $el: $el};
  2214. $s.instantiated = false;
  2215. $s.$watch('bsTableControl.options', function (options) {
  2216. if (!options) options = $s.bsTableControl.options = {};
  2217. var state = $s.bsTableControl.state || {};
  2218. if ($s.instantiated) $el.bootstrapTable('destroy');
  2219. $el.bootstrapTable(angular.extend(angular.copy(options), state));
  2220. $s.instantiated = true;
  2221. // Update the UI for state that isn't settable via options
  2222. if ('scroll' in state) $el.bootstrapTable('scrollTo', state.scroll);
  2223. if ('searchHasFocus' in state) $el.closest(CONTAINER_SELECTOR).find(SEARCH_SELECTOR).focus(); // $el gets detached so have to recompute whole chain
  2224. }, true);
  2225. $s.$watch('bsTableControl.state', function (state) {
  2226. if (!state) state = $s.bsTableControl.state = {};
  2227. $el.trigger('directive-updated.bs.table', [state]);
  2228. }, true);
  2229. $s.$on('$destroy', function () {
  2230. delete bsTables[$s.$id];
  2231. });
  2232. }
  2233. };
  2234. })
  2235. })();
  2236. /**
  2237. * @author: Dennis Hernández
  2238. * @webSite: http://djhvscf.github.io/Blog
  2239. * @version: v1.2.0
  2240. *
  2241. * @update zhixin wen <wenzhixin2010@gmail.com>
  2242. */
  2243. (function ($) {
  2244. 'use strict';
  2245. var cookieIds = {
  2246. sortOrder: 'bs.table.sortOrder',
  2247. sortName: 'bs.table.sortName',
  2248. pageNumber: 'bs.table.pageNumber',
  2249. pageList: 'bs.table.pageList',
  2250. columns: 'bs.table.columns',
  2251. searchText: 'bs.table.searchText',
  2252. filterControl: 'bs.table.filterControl'
  2253. };
  2254. var getCurrentHeader = function (that) {
  2255. var header = that.$header;
  2256. if (that.options.height) {
  2257. header = that.$tableHeader;
  2258. }
  2259. return header;
  2260. };
  2261. var getCurrentSearchControls = function (that) {
  2262. var searchControls = 'select, input';
  2263. if (that.options.height) {
  2264. searchControls = 'table select, table input';
  2265. }
  2266. return searchControls;
  2267. };
  2268. var cookieEnabled = function () {
  2269. return !!(navigator.cookieEnabled);
  2270. };
  2271. var setCookie = function (that, cookieName, cookieValue) {
  2272. if ((!that.options.cookie) || (!cookieEnabled()) || (that.options.cookieIdTable === '')) {
  2273. return;
  2274. }
  2275. if ($.inArray(cookieName.toLowerCase(), that.options.cookiesEnabled) === -1) {
  2276. return;
  2277. }
  2278. cookieName = that.options.cookieIdTable + '.' + cookieName;
  2279. if (!cookieName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cookieName)) {
  2280. return false;
  2281. }
  2282. document.cookie = encodeURIComponent(cookieName) + '=' + encodeURIComponent(cookieValue) + calculateExpiration(that.options.cookieExpire) + (that.options.cookieDomain ? '; domain=' + that.options.cookieDomain : '') + (that.options.cookiePath ? '; path=' + that.options.cookiePath : '') + (that.cookieSecure ? '; secure' : '');
  2283. return true;
  2284. };
  2285. var getCookie = function (that, tableName, cookieName) {
  2286. if (!cookieName) {
  2287. return null;
  2288. }
  2289. if ($.inArray(cookieName.toLowerCase(), that.options.cookiesEnabled) === -1) {
  2290. return null;
  2291. }
  2292. cookieName = tableName + '.' + cookieName;
  2293. return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
  2294. };
  2295. var hasCookie = function (cookieName) {
  2296. if (!cookieName) {
  2297. return false;
  2298. }
  2299. return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
  2300. };
  2301. var deleteCookie = function (tableName, cookieName, sPath, sDomain) {
  2302. cookieName = tableName + '.' + cookieName;
  2303. if (!hasCookie(cookieName)) {
  2304. return false;
  2305. }
  2306. document.cookie = encodeURIComponent(cookieName) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
  2307. return true;
  2308. };
  2309. var calculateExpiration = function(cookieExpire) {
  2310. var time = cookieExpire.replace(/[0-9]*/, ''); //s,mi,h,d,m,y
  2311. cookieExpire = cookieExpire.replace(/[A-Za-z]/, ''); //number
  2312. switch (time.toLowerCase()) {
  2313. case 's':
  2314. cookieExpire = +cookieExpire;
  2315. break;
  2316. case 'mi':
  2317. cookieExpire = cookieExpire * 60;
  2318. break;
  2319. case 'h':
  2320. cookieExpire = cookieExpire * 60 * 60;
  2321. break;
  2322. case 'd':
  2323. cookieExpire = cookieExpire * 24 * 60 * 60;
  2324. break;
  2325. case 'm':
  2326. cookieExpire = cookieExpire * 30 * 24 * 60 * 60;
  2327. break;
  2328. case 'y':
  2329. cookieExpire = cookieExpire * 365 * 30 * 24 * 60 * 60;
  2330. break;
  2331. default:
  2332. cookieExpire = undefined;
  2333. break;
  2334. }
  2335. return cookieExpire === undefined ? '' : '; max-age=' + cookieExpire;
  2336. };
  2337. $.extend($.fn.bootstrapTable.defaults, {
  2338. cookie: false,
  2339. cookieExpire: '2h',
  2340. cookiePath: null,
  2341. cookieDomain: null,
  2342. cookieSecure: null,
  2343. cookieIdTable: '',
  2344. cookiesEnabled: ['bs.table.sortOrder', 'bs.table.sortName', 'bs.table.pageNumber', 'bs.table.pageList', 'bs.table.columns', 'bs.table.searchText', 'bs.table.filterControl'],
  2345. //internal variable
  2346. filterControls: [],
  2347. filterControlValuesLoaded: false
  2348. });
  2349. $.fn.bootstrapTable.methods.push('deleteCookie');
  2350. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2351. _init = BootstrapTable.prototype.init,
  2352. _initTable = BootstrapTable.prototype.initTable,
  2353. _onSort = BootstrapTable.prototype.onSort,
  2354. _onPageNumber = BootstrapTable.prototype.onPageNumber,
  2355. _onPageListChange = BootstrapTable.prototype.onPageListChange,
  2356. _onPageFirst = BootstrapTable.prototype.onPageFirst,
  2357. _onPagePre = BootstrapTable.prototype.onPagePre,
  2358. _onPageNext = BootstrapTable.prototype.onPageNext,
  2359. _onPageLast = BootstrapTable.prototype.onPageLast,
  2360. _toggleColumn = BootstrapTable.prototype.toggleColumn,
  2361. _selectPage = BootstrapTable.prototype.selectPage,
  2362. _onSearch = BootstrapTable.prototype.onSearch;
  2363. BootstrapTable.prototype.init = function () {
  2364. var timeoutId = 0;
  2365. this.options.filterControls = [];
  2366. this.options.filterControlValuesLoaded = false;
  2367. this.options.cookiesEnabled = typeof this.options.cookiesEnabled === 'string' ?
  2368. this.options.cookiesEnabled.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') : this.options.cookiesEnabled;
  2369. if (this.options.filterControl) {
  2370. var that = this;
  2371. this.$el.on('column-search.bs.table', function (e, field, text) {
  2372. var isNewField = true;
  2373. for (var i = 0; i < that.options.filterControls.length; i++) {
  2374. if (that.options.filterControls[i].field === field) {
  2375. that.options.filterControls[i].text = text;
  2376. isNewField = false;
  2377. break;
  2378. }
  2379. }
  2380. if (isNewField) {
  2381. that.options.filterControls.push({
  2382. field: field,
  2383. text: text
  2384. });
  2385. }
  2386. setCookie(that, cookieIds.filterControl, JSON.stringify(that.options.filterControls));
  2387. }).on('post-body.bs.table', function () {
  2388. setTimeout(function () {
  2389. if (!that.options.filterControlValuesLoaded) {
  2390. that.options.filterControlValuesLoaded = true;
  2391. var filterControl = JSON.parse(getCookie(that, that.options.cookieIdTable, cookieIds.filterControl));
  2392. if (filterControl) {
  2393. var field = null,
  2394. result = [],
  2395. header = getCurrentHeader(that),
  2396. searchControls = getCurrentSearchControls(that);
  2397. header.find(searchControls).each(function (index, ele) {
  2398. field = $(this).parent().parent().parent().data('field');
  2399. result = $.grep(filterControl, function (valueObj) {
  2400. return valueObj.field === field;
  2401. });
  2402. if (result.length > 0) {
  2403. $(this).val(result[0].text);
  2404. that.onColumnSearch({currentTarget: $(this)});
  2405. }
  2406. });
  2407. }
  2408. }
  2409. }, 250);
  2410. });
  2411. }
  2412. _init.apply(this, Array.prototype.slice.apply(arguments));
  2413. };
  2414. BootstrapTable.prototype.initTable = function () {
  2415. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  2416. this.initCookie();
  2417. };
  2418. BootstrapTable.prototype.initCookie = function () {
  2419. if (!this.options.cookie) {
  2420. return;
  2421. }
  2422. if ((this.options.cookieIdTable === '') || (this.options.cookieExpire === '') || (!cookieEnabled())) {
  2423. throw new Error("Configuration error. Please review the cookieIdTable, cookieExpire properties, if those properties are ok, then this browser does not support the cookies");
  2424. return;
  2425. }
  2426. var sortOrderCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortOrder),
  2427. sortOrderNameCookie = getCookie(this, this.options.cookieIdTable, cookieIds.sortName),
  2428. pageNumberCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageNumber),
  2429. pageListCookie = getCookie(this, this.options.cookieIdTable, cookieIds.pageList),
  2430. columnsCookie = JSON.parse(getCookie(this, this.options.cookieIdTable, cookieIds.columns)),
  2431. searchTextCookie = getCookie(this, this.options.cookieIdTable, cookieIds.searchText);
  2432. //sortOrder
  2433. this.options.sortOrder = sortOrderCookie ? sortOrderCookie : 'asc';
  2434. //sortName
  2435. this.options.sortName = sortOrderNameCookie ? sortOrderNameCookie : undefined;
  2436. //pageNumber
  2437. this.options.pageNumber = pageNumberCookie ? +pageNumberCookie : this.options.pageNumber;
  2438. //pageSize
  2439. this.options.pageSize = pageListCookie ? pageListCookie === this.options.formatAllRows() ? pageListCookie : +pageListCookie : this.options.pageSize;
  2440. //searchText
  2441. this.options.searchText = searchTextCookie ? searchTextCookie : '';
  2442. if (columnsCookie) {
  2443. $.each(this.columns, function (i, column) {
  2444. column.visible = columnsCookie.indexOf(column.field) !== -1;
  2445. });
  2446. }
  2447. };
  2448. BootstrapTable.prototype.onSort = function () {
  2449. _onSort.apply(this, Array.prototype.slice.apply(arguments));
  2450. setCookie(this, cookieIds.sortOrder, this.options.sortOrder);
  2451. setCookie(this, cookieIds.sortName, this.options.sortName);
  2452. };
  2453. BootstrapTable.prototype.onPageNumber = function () {
  2454. _onPageNumber.apply(this, Array.prototype.slice.apply(arguments));
  2455. setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
  2456. };
  2457. BootstrapTable.prototype.onPageListChange = function () {
  2458. _onPageListChange.apply(this, Array.prototype.slice.apply(arguments));
  2459. setCookie(this, cookieIds.pageList, this.options.pageSize);
  2460. };
  2461. BootstrapTable.prototype.onPageFirst = function () {
  2462. _onPageFirst.apply(this, Array.prototype.slice.apply(arguments));
  2463. setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
  2464. };
  2465. BootstrapTable.prototype.onPagePre = function () {
  2466. _onPagePre.apply(this, Array.prototype.slice.apply(arguments));
  2467. setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
  2468. };
  2469. BootstrapTable.prototype.onPageNext = function () {
  2470. _onPageNext.apply(this, Array.prototype.slice.apply(arguments));
  2471. setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
  2472. };
  2473. BootstrapTable.prototype.onPageLast = function () {
  2474. _onPageLast.apply(this, Array.prototype.slice.apply(arguments));
  2475. setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
  2476. };
  2477. BootstrapTable.prototype.toggleColumn = function () {
  2478. _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
  2479. var visibleColumns = [];
  2480. $.each(this.columns, function (i, column) {
  2481. if (column.visible) {
  2482. visibleColumns.push(column.field);
  2483. }
  2484. });
  2485. setCookie(this, cookieIds.columns, JSON.stringify(visibleColumns));
  2486. };
  2487. BootstrapTable.prototype.selectPage = function (page) {
  2488. _selectPage.apply(this, Array.prototype.slice.apply(arguments));
  2489. setCookie(this, idsStateSaveList.pageNumber, page);
  2490. };
  2491. BootstrapTable.prototype.onSearch = function () {
  2492. _onSearch.apply(this, Array.prototype.slice.apply(arguments));
  2493. setCookie(this, cookieIds.searchText, this.searchText);
  2494. };
  2495. BootstrapTable.prototype.deleteCookie = function (cookieName) {
  2496. if ((cookieName === '') || (!cookieEnabled())) {
  2497. return;
  2498. }
  2499. deleteCookie(this.options.cookieIdTable, cookieIds[cookieName], this.options.cookiePath, this.options.cookieDomain);
  2500. };
  2501. })(jQuery);
  2502. /**
  2503. * @author zhixin wen <wenzhixin2010@gmail.com>
  2504. * extensions: https://github.com/vitalets/x-editable
  2505. */
  2506. !function ($) {
  2507. 'use strict';
  2508. $.extend($.fn.bootstrapTable.defaults, {
  2509. editable: true,
  2510. onEditableInit: function () {
  2511. return false;
  2512. },
  2513. onEditableSave: function (field, row, oldValue, $el) {
  2514. return false;
  2515. },
  2516. onEditableShown: function (field, row, $el, editable) {
  2517. return false;
  2518. },
  2519. onEditableHidden: function (field, row, $el) {
  2520. return false;
  2521. }
  2522. });
  2523. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2524. 'editable-init.bs.table': 'onEditableInit',
  2525. 'editable-save.bs.table': 'onEditableSave',
  2526. 'editable-shown.bs.table': 'onEditableShown',
  2527. 'editable-hidden.bs.table': 'onEditableHidden'
  2528. });
  2529. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2530. _initTable = BootstrapTable.prototype.initTable,
  2531. _initBody = BootstrapTable.prototype.initBody;
  2532. BootstrapTable.prototype.initTable = function () {
  2533. var that = this;
  2534. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  2535. if (!this.options.editable) {
  2536. return;
  2537. }
  2538. $.each(this.columns, function (i, column) {
  2539. if (!column.editable) {
  2540. return;
  2541. }
  2542. var _formatter = column.formatter;
  2543. column.formatter = function (value, row, index) {
  2544. var result = _formatter ? _formatter(value, row, index) : value;
  2545. return ['<a href="javascript:void(0)"',
  2546. ' data-name="' + column.field + '"',
  2547. ' data-pk="' + row[that.options.idField] + '"',
  2548. ' data-value="' + result + '"',
  2549. '>' + '</a>'
  2550. ].join('');
  2551. };
  2552. });
  2553. };
  2554. BootstrapTable.prototype.initBody = function () {
  2555. var that = this;
  2556. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  2557. if (!this.options.editable) {
  2558. return;
  2559. }
  2560. $.each(this.columns, function (i, column) {
  2561. if (!column.editable) {
  2562. return;
  2563. }
  2564. that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
  2565. .off('save').on('save', function (e, params) {
  2566. var data = that.getData(),
  2567. index = $(this).parents('tr[data-index]').data('index'),
  2568. row = data[index],
  2569. oldValue = row[column.field];
  2570. row[column.field] = params.submitValue;
  2571. that.trigger('editable-save', column.field, row, oldValue, $(this));
  2572. });
  2573. that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
  2574. .off('shown').on('shown', function (e) {
  2575. var data = that.getData(),
  2576. index = $(this).parents('tr[data-index]').data('index'),
  2577. row = data[index];
  2578. that.trigger('editable-shown', column.field, row, $(this));
  2579. });
  2580. that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
  2581. .off('hidden').on('hidden', function (e, editable) {
  2582. var data = that.getData(),
  2583. index = $(this).parents('tr[data-index]').data('index'),
  2584. row = data[index];
  2585. that.trigger('editable-hidden', column.field, row, $(this), editable);
  2586. });
  2587. });
  2588. this.trigger('editable-init');
  2589. };
  2590. }(jQuery);
  2591. /**
  2592. * @author zhixin wen <wenzhixin2010@gmail.com>
  2593. * extensions: https://github.com/kayalshri/tableExport.jquery.plugin
  2594. */
  2595. (function ($) {
  2596. 'use strict';
  2597. var TYPE_NAME = {
  2598. json: 'JSON',
  2599. xml: 'XML',
  2600. png: 'PNG',
  2601. csv: 'CSV',
  2602. txt: 'TXT',
  2603. sql: 'SQL',
  2604. doc: 'MS-Word',
  2605. excel: 'Ms-Excel',
  2606. powerpoint: 'Ms-Powerpoint',
  2607. pdf: 'PDF'
  2608. };
  2609. $.extend($.fn.bootstrapTable.defaults, {
  2610. showExport: false,
  2611. exportDataType: 'basic', // basic, all, selected
  2612. // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
  2613. exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
  2614. exportOptions: {}
  2615. });
  2616. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2617. _initToolbar = BootstrapTable.prototype.initToolbar;
  2618. BootstrapTable.prototype.initToolbar = function () {
  2619. this.showToolbar = this.options.showExport;
  2620. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  2621. if (this.options.showExport) {
  2622. var that = this,
  2623. $btnGroup = this.$toolbar.find('>.btn-group'),
  2624. $export = $btnGroup.find('div.export');
  2625. if (!$export.length) {
  2626. $export = $([
  2627. '<div class="export btn-group">',
  2628. '<button class="btn btn-default dropdown-toggle" ' +
  2629. 'data-toggle="dropdown" type="button">',
  2630. '<i class="glyphicon glyphicon-export icon-share"></i> ',
  2631. '<span class="caret"></span>',
  2632. '</button>',
  2633. '<ul class="dropdown-menu" role="menu">',
  2634. '</ul>',
  2635. '</div>'].join('')).appendTo($btnGroup);
  2636. var $menu = $export.find('.dropdown-menu'),
  2637. exportTypes = this.options.exportTypes;
  2638. if (typeof this.options.exportTypes === 'string') {
  2639. var types = this.options.exportTypes.slice(1, -1).replace(/ /g, '').split(',');
  2640. exportTypes = [];
  2641. $.each(types, function (i, value) {
  2642. exportTypes.push(value.slice(1, -1));
  2643. });
  2644. }
  2645. $.each(exportTypes, function (i, type) {
  2646. if (TYPE_NAME.hasOwnProperty(type)) {
  2647. $menu.append(['<li data-type="' + type + '">',
  2648. '<a href="javascript:void(0)">',
  2649. TYPE_NAME[type],
  2650. '</a>',
  2651. '</li>'].join(''));
  2652. }
  2653. });
  2654. $menu.find('li').click(function () {
  2655. var type = $(this).data('type'),
  2656. doExport = function () {
  2657. that.$el.tableExport($.extend({}, that.options.exportOptions, {
  2658. type: type,
  2659. escape: false
  2660. }));
  2661. };
  2662. if (that.options.exportDataType === 'all' && that.options.pagination) {
  2663. that.togglePagination();
  2664. doExport();
  2665. that.togglePagination();
  2666. } else if (that.options.exportDataType === 'selected') {
  2667. var data = that.getData(),
  2668. selectedData = that.getAllSelections();
  2669. that.load(selectedData);
  2670. doExport();
  2671. that.load(data);
  2672. } else {
  2673. doExport();
  2674. }
  2675. });
  2676. }
  2677. }
  2678. };
  2679. })(jQuery);
  2680. /**
  2681. * @author: Dennis Hernández
  2682. * @webSite: http://djhvscf.github.io/Blog
  2683. * @version: v1.0.0
  2684. */
  2685. !function ($) {
  2686. 'use strict';
  2687. var sprintf = function (str) {
  2688. var args = arguments,
  2689. flag = true,
  2690. i = 1;
  2691. str = str.replace(/%s/g, function () {
  2692. var arg = args[i++];
  2693. if (typeof arg === 'undefined') {
  2694. flag = false;
  2695. return '';
  2696. }
  2697. return arg;
  2698. });
  2699. return flag ? str : '';
  2700. };
  2701. var getFieldIndex = function (columns, field) {
  2702. var index = -1;
  2703. $.each(columns, function (i, column) {
  2704. if (column.field === field) {
  2705. index = i;
  2706. return false;
  2707. }
  2708. return true;
  2709. });
  2710. return index;
  2711. };
  2712. var calculateObjectValue = function (self, name, args, defaultValue) {
  2713. if (typeof name === 'string') {
  2714. // support obj.func1.func2
  2715. var names = name.split('.');
  2716. if (names.length > 1) {
  2717. name = window;
  2718. $.each(names, function (i, f) {
  2719. name = name[f];
  2720. });
  2721. } else {
  2722. name = window[name];
  2723. }
  2724. }
  2725. if (typeof name === 'object') {
  2726. return name;
  2727. }
  2728. if (typeof name === 'function') {
  2729. return name.apply(self, args);
  2730. }
  2731. return defaultValue;
  2732. };
  2733. var addOptionToSelectControl = function (selectControl, value, text) {
  2734. //selectControl = $(selectControl.get(0));
  2735. if (existsOptionInSelectControl(selectControl, value)) {
  2736. selectControl.append($("<option></option>")
  2737. .attr("value", value)
  2738. .text($('<div />').html(text).text()));
  2739. // Sort it. Not overly efficient to do this here
  2740. var $opts = selectControl.find('option:gt(0)');
  2741. $opts.sort(function (a, b) {
  2742. a = $(a).text().toLowerCase();
  2743. b = $(b).text().toLowerCase();
  2744. if ($.isNumeric(a) && $.isNumeric(b)) {
  2745. // Convert numerical values from string to float.
  2746. a = parseFloat(a);
  2747. b = parseFloat(b);
  2748. }
  2749. return a > b ? 1 : a < b ? -1 : 0;
  2750. });
  2751. selectControl.find('option:gt(0)').remove();
  2752. selectControl.append($opts);
  2753. }
  2754. };
  2755. var existsOptionInSelectControl = function (selectControl, value) {
  2756. var options = selectControl.get(0).options,
  2757. iOpt = 0;
  2758. for (; iOpt < options.length; iOpt++) {
  2759. if (options[iOpt].value === value) {
  2760. //The value is nor valid to add
  2761. return false;
  2762. }
  2763. }
  2764. //If we get here, the value is valid to add
  2765. return true;
  2766. };
  2767. var fixHeaderCSS = function (that) {
  2768. that.$tableHeader.css('height', '77px');
  2769. };
  2770. var getCurrentHeader = function (that) {
  2771. var header = that.$header;
  2772. if (that.options.height) {
  2773. header = that.$tableHeader;
  2774. }
  2775. return header;
  2776. };
  2777. var getCurrentSearchControls = function (that) {
  2778. var searchControls = 'select, input';
  2779. if (that.options.height) {
  2780. searchControls = 'table select, table input';
  2781. }
  2782. return searchControls;
  2783. };
  2784. var copyValues = function (that) {
  2785. var header = getCurrentHeader(that),
  2786. searchControls = getCurrentSearchControls(that);
  2787. that.options.values = [];
  2788. header.find(searchControls).each(function () {
  2789. that.options.values.push(
  2790. {
  2791. field: $(this).parent().parent().parent().data('field'),
  2792. value: $(this).val()
  2793. });
  2794. });
  2795. };
  2796. var setValues = function(that) {
  2797. var field = null,
  2798. result = [],
  2799. header = getCurrentHeader(that),
  2800. searchControls = getCurrentSearchControls(that);
  2801. if (that.options.values.length > 0) {
  2802. header.find(searchControls).each(function (index, ele) {
  2803. field = $(this).parent().parent().parent().data('field');
  2804. result = $.grep(that.options.values, function (valueObj) {
  2805. return valueObj.field === field;
  2806. });
  2807. if (result.length > 0) {
  2808. $(this).val(result[0].value);
  2809. }
  2810. });
  2811. }
  2812. };
  2813. var createControls = function (that, header) {
  2814. var addedFilterControl = false,
  2815. isVisible,
  2816. html,
  2817. timeoutId = 0;
  2818. $.each(that.columns, function (i, column) {
  2819. isVisible = 'hidden';
  2820. html = [];
  2821. if (!column.visible) {
  2822. return;
  2823. }
  2824. if (!column.filterControl) {
  2825. html.push('<div style="height: 34px;"></div>');
  2826. } else {
  2827. html.push('<div style="margin: 0px 2px 2px 2px;" class="filterControl">');
  2828. if (column.filterControl && column.searchable) {
  2829. addedFilterControl = true;
  2830. isVisible = 'visible'
  2831. }
  2832. switch (column.filterControl.toLowerCase()) {
  2833. case 'input' :
  2834. html.push(sprintf('<input type="text" class="form-control" style="width: 100%; visibility: %s">', isVisible));
  2835. break;
  2836. case 'select':
  2837. html.push(sprintf('<select class="%s form-control" style="width: 100%; visibility: %s"></select>',
  2838. column.field, isVisible))
  2839. break;
  2840. case 'datepicker':
  2841. html.push(sprintf('<input type="text" class="date-filter-control %s form-control" style="width: 100%; visibility: %s">',
  2842. column.field, isVisible));
  2843. break;
  2844. }
  2845. }
  2846. $.each(header.children().children(), function (i, tr) {
  2847. tr = $(tr);
  2848. if (tr.data('field') === column.field) {
  2849. tr.find('.fht-cell').append(html.join(''));
  2850. return false;
  2851. }
  2852. });
  2853. if (column.filterData !== undefined && column.filterData.toLowerCase() !== 'column') {
  2854. var filterDataType = column.filterData.substring(0, 3);
  2855. var filterDataSource = column.filterData.substring(4, column.filterData.length);
  2856. var selectControl = $('.' + column.field);
  2857. addOptionToSelectControl(selectControl, '', '');
  2858. switch (filterDataType) {
  2859. case 'url':
  2860. $.ajax({
  2861. url: filterDataSource,
  2862. dataType: 'json',
  2863. success: function (data) {
  2864. $.each(data, function (key, value) {
  2865. addOptionToSelectControl(selectControl, key, value);
  2866. });
  2867. }
  2868. });
  2869. break;
  2870. case 'var':
  2871. var variableValues = window[filterDataSource];
  2872. for (var key in variableValues) {
  2873. addOptionToSelectControl(selectControl, key, variableValues[key]);
  2874. }
  2875. break;
  2876. }
  2877. }
  2878. });
  2879. if (addedFilterControl) {
  2880. header.off('keyup', 'input').on('keyup', 'input', function (event) {
  2881. clearTimeout(timeoutId);
  2882. timeoutId = setTimeout(function () {
  2883. that.onColumnSearch(event);
  2884. }, that.options.searchTimeOut);
  2885. });
  2886. header.off('change', 'select').on('change', 'select', function (event) {
  2887. clearTimeout(timeoutId);
  2888. timeoutId = setTimeout(function () {
  2889. that.onColumnSearch(event);
  2890. }, that.options.searchTimeOut);
  2891. });
  2892. if (header.find('.date-filter-control').length > 0) {
  2893. $.each(that.columns, function (i, column) {
  2894. if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'datepicker') {
  2895. header.find('.date-filter-control.' + column.field).datepicker(column.filterDatepickerOptions)
  2896. .on('changeDate', function (e) {
  2897. //Fired the keyup event
  2898. $(e.currentTarget).keyup();
  2899. });
  2900. }
  2901. });
  2902. }
  2903. } else {
  2904. header.find('.filterControl').hide();
  2905. }
  2906. };
  2907. $.extend($.fn.bootstrapTable.defaults, {
  2908. filterControl: false,
  2909. onColumnSearch: function (field, text) {
  2910. return false;
  2911. },
  2912. filterShowClear: false,
  2913. //internal variables
  2914. values: []
  2915. });
  2916. $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
  2917. filterControl: undefined,
  2918. filterData: undefined,
  2919. filterDatepickerOptions: undefined
  2920. });
  2921. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2922. 'column-search.bs.table': 'onColumnSearch'
  2923. });
  2924. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2925. _init = BootstrapTable.prototype.init,
  2926. _initToolbar = BootstrapTable.prototype.initToolbar,
  2927. _initHeader = BootstrapTable.prototype.initHeader,
  2928. _initBody = BootstrapTable.prototype.initBody,
  2929. _initSearch = BootstrapTable.prototype.initSearch;
  2930. BootstrapTable.prototype.init = function () {
  2931. //Make sure that the filtercontrol option is set
  2932. if (this.options.filterControl) {
  2933. var that = this;
  2934. //Make sure that the internal variables are set correctly
  2935. this.options.values = [];
  2936. this.$el.on('reset-view.bs.table', function () {
  2937. //Create controls on $tableHeader if the height is set
  2938. if (!that.options.height) {
  2939. return;
  2940. }
  2941. //Avoid recreate the controls
  2942. if (that.$tableHeader.find('select').length > 0 || that.$tableHeader.find('input').length > 0) {
  2943. return;
  2944. }
  2945. createControls(that, that.$tableHeader);
  2946. }).on('post-header.bs.table', function () {
  2947. setValues(that);
  2948. }).on('post-body.bs.table', function () {
  2949. if (that.options.height) {
  2950. fixHeaderCSS(that);
  2951. }
  2952. }).on('column-switch.bs.table', function(field, checked) {
  2953. setValues(that);
  2954. });
  2955. }
  2956. _init.apply(this, Array.prototype.slice.apply(arguments));
  2957. };
  2958. BootstrapTable.prototype.initToolbar = function () {
  2959. if ((!this.showToolbar) && (this.options.filterControl)) {
  2960. this.showToolbar = this.options.filterControl;
  2961. }
  2962. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  2963. if (this.options.filterControl && this.options.filterShowClear) {
  2964. var $btnGroup = this.$toolbar.find('>.btn-group'),
  2965. $btnClear = $btnGroup.find('div.export');
  2966. if (!$btnClear.length) {
  2967. $btnClear = $([
  2968. '<button class="btn btn-default " ' +
  2969. 'type="button">',
  2970. '<i class="glyphicon glyphicon-trash icon-share"></i> ',
  2971. '</button>',
  2972. '</ul>'].join('')).appendTo($btnGroup);
  2973. $btnClear.off('click').on('click', $.proxy(this.clearFilterControl, this));
  2974. }
  2975. }
  2976. };
  2977. BootstrapTable.prototype.initHeader = function () {
  2978. _initHeader.apply(this, Array.prototype.slice.apply(arguments));
  2979. if (!this.options.filterControl) {
  2980. return;
  2981. }
  2982. createControls(this, this.$header);
  2983. };
  2984. BootstrapTable.prototype.initBody = function () {
  2985. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  2986. var that = this,
  2987. data = this.options.data,
  2988. pageTo = this.pageTo < this.options.data.length ? this.options.data.length : this.pageTo;
  2989. for (var i = this.pageFrom - 1; i < pageTo; i++) {
  2990. var item = data[i];
  2991. $.each(this.header.fields, function (j, field) {
  2992. var value = item[field],
  2993. column = that.columns[getFieldIndex(that.columns, field)];
  2994. value = calculateObjectValue(that.header, that.header.formatters[j], [value, item, i], value);
  2995. if ((!column.checkbox) || (!column.radio)) {
  2996. if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select' && column.searchable) {
  2997. if (column.filterData === undefined || column.filterData.toLowerCase() === 'column') {
  2998. var selectControl = $('.' + column.field);
  2999. if (selectControl !== undefined && selectControl.length > 0) {
  3000. if (selectControl.get(0).options.length === 0) {
  3001. //Added the default option
  3002. addOptionToSelectControl(selectControl, '', '');
  3003. }
  3004. //Added a new value
  3005. addOptionToSelectControl(selectControl, value, value);
  3006. }
  3007. }
  3008. }
  3009. }
  3010. });
  3011. }
  3012. };
  3013. BootstrapTable.prototype.initSearch = function () {
  3014. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  3015. var that = this;
  3016. var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
  3017. //Check partial column filter
  3018. this.data = fp ? $.grep(this.data, function (item, i) {
  3019. for (var key in fp) {
  3020. var fval = fp[key].toLowerCase();
  3021. var value = item[key];
  3022. value = calculateObjectValue(that.header,
  3023. that.header.formatters[$.inArray(key, that.header.fields)],
  3024. [value, item, i], value);
  3025. if (!($.inArray(key, that.header.fields) !== -1 &&
  3026. (typeof value === 'string' || typeof value === 'number') &&
  3027. (value + '').toLowerCase().indexOf(fval) !== -1)) {
  3028. return false;
  3029. }
  3030. }
  3031. return true;
  3032. }) : this.data;
  3033. };
  3034. BootstrapTable.prototype.onColumnSearch = function (event) {
  3035. copyValues(this);
  3036. var text = $.trim($(event.currentTarget).val());
  3037. var $field = $(event.currentTarget).parent().parent().parent().data('field')
  3038. if ($.isEmptyObject(this.filterColumnsPartial)) {
  3039. this.filterColumnsPartial = {};
  3040. }
  3041. if (text) {
  3042. this.filterColumnsPartial[$field] = text;
  3043. } else {
  3044. delete this.filterColumnsPartial[$field];
  3045. }
  3046. this.options.pageNumber = 1;
  3047. this.onSearch(event);
  3048. this.updatePagination();
  3049. this.trigger('column-search', $field, text);
  3050. };
  3051. BootstrapTable.prototype.clearFilterControl = function () {
  3052. if (this.options.filterControl && this.options.filterShowClear) {
  3053. $.each(this.options.values, function (i, item) {
  3054. item.value = '';
  3055. });
  3056. setValues(this);
  3057. var controls = getCurrentHeader(this).find(getCurrentSearchControls(this)),
  3058. timeoutId = 0;
  3059. if (controls.length > 0) {
  3060. this.filterColumnsPartial = {};
  3061. clearTimeout(timeoutId);
  3062. timeoutId = setTimeout(function () {
  3063. $(controls[0]).trigger(controls[0].tagName === 'INPUT' ? 'keyup' : 'change');
  3064. }, this.options.searchTimeOut);
  3065. }
  3066. }
  3067. };
  3068. }(jQuery);
  3069. /**
  3070. * @author zhixin wen <wenzhixin2010@gmail.com>
  3071. * extensions: https://github.com/lukaskral/bootstrap-table-filter
  3072. */
  3073. !function($) {
  3074. 'use strict';
  3075. $.extend($.fn.bootstrapTable.defaults, {
  3076. showFilter: false
  3077. });
  3078. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3079. _init = BootstrapTable.prototype.init,
  3080. _initSearch = BootstrapTable.prototype.initSearch;
  3081. BootstrapTable.prototype.init = function () {
  3082. _init.apply(this, Array.prototype.slice.apply(arguments));
  3083. var that = this;
  3084. this.$el.on('load-success.bs.table', function () {
  3085. if (that.options.showFilter) {
  3086. $(that.options.toolbar).bootstrapTableFilter({
  3087. connectTo: that.$el
  3088. });
  3089. }
  3090. });
  3091. };
  3092. BootstrapTable.prototype.initSearch = function () {
  3093. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  3094. if (this.options.sidePagination !== 'server') {
  3095. if (typeof this.searchCallback === 'function') {
  3096. this.data = $.grep(this.options.data, this.searchCallback);
  3097. }
  3098. }
  3099. };
  3100. BootstrapTable.prototype.getData = function () {
  3101. return (this.searchText || this.searchCallback) ? this.data : this.options.data;
  3102. };
  3103. BootstrapTable.prototype.getColumns = function () {
  3104. return this.columns;
  3105. };
  3106. BootstrapTable.prototype.registerSearchCallback = function (callback) {
  3107. this.searchCallback = callback;
  3108. };
  3109. BootstrapTable.prototype.updateSearch = function () {
  3110. this.options.pageNumber = 1;
  3111. this.initSearch();
  3112. this.updatePagination();
  3113. };
  3114. BootstrapTable.prototype.getServerUrl = function () {
  3115. return (this.options.sidePagination === 'server') ? this.options.url : false;
  3116. };
  3117. $.fn.bootstrapTable.methods.push('getColumns',
  3118. 'registerSearchCallback', 'updateSearch',
  3119. 'getServerUrl');
  3120. }(jQuery);
  3121. /**
  3122. * @author: Dennis Hernández
  3123. * @webSite: http://djhvscf.github.io/Blog
  3124. * @version: v1.3.0
  3125. */
  3126. (function ($) {
  3127. 'use strict';
  3128. var flat = function (element, that) {
  3129. var result = {};
  3130. function recurse(cur, prop) {
  3131. if (Object(cur) !== cur) {
  3132. result[prop] = cur;
  3133. } else if ($.isArray(cur)) {
  3134. for (var i = 0, l = cur.length; i < l; i++) {
  3135. recurse(cur[i], prop ? prop + that.options.flatSeparator + i : "" + i);
  3136. if (l == 0) {
  3137. result[prop] = [];
  3138. }
  3139. }
  3140. } else {
  3141. var isEmpty = true;
  3142. for (var p in cur) {
  3143. isEmpty = false;
  3144. recurse(cur[p], prop ? prop + that.options.flatSeparator + p : p);
  3145. }
  3146. if (isEmpty) {
  3147. result[prop] = {};
  3148. }
  3149. }
  3150. }
  3151. recurse(element, "");
  3152. return result;
  3153. };
  3154. var flatHelper = function (data, that) {
  3155. var flatArray = [];
  3156. $.each(!$.isArray(data) ? [data] : data, function (i, element) {
  3157. flatArray.push(flat(element, that));
  3158. });
  3159. return flatArray;
  3160. };
  3161. $.extend($.fn.bootstrapTable.defaults, {
  3162. flat: false,
  3163. flatSeparator: '.'
  3164. });
  3165. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3166. _initData = BootstrapTable.prototype.initData;
  3167. BootstrapTable.prototype.initData = function (data, type) {
  3168. if (this.options.flat) {
  3169. data = flatHelper(data ? data : this.options.data, this);
  3170. }
  3171. _initData.apply(this, [data, type]);
  3172. };
  3173. })(jQuery);
  3174. /**
  3175. * @author: Dennis Hernández
  3176. * @webSite: http://djhvscf.github.io/Blog
  3177. * @version: v1.0.0
  3178. */
  3179. !function ($) {
  3180. 'use strict';
  3181. var originalRowAttr,
  3182. dataTTId = 'data-tt-id',
  3183. dataTTParentId = 'data-tt-parent-id',
  3184. obj = {},
  3185. parentId = undefined;
  3186. var getFieldIndex = function (columns, field) {
  3187. var index = -1;
  3188. $.each(columns, function (i, column) {
  3189. if (column.field === field) {
  3190. index = i;
  3191. return false;
  3192. }
  3193. return true;
  3194. });
  3195. return index;
  3196. };
  3197. var getParentRowId = function (that, id) {
  3198. var parentRows = that.$body.find('tr').not('[' + 'data-tt-parent-id]');
  3199. for (var i = 0; i < parentRows.length; i++) {
  3200. if (i === id) {
  3201. return $(parentRows[i]).attr('data-tt-id');
  3202. }
  3203. }
  3204. return undefined;
  3205. };
  3206. var sumData = function (that, data) {
  3207. var sumRow = {};
  3208. $.each(data, function (i, row) {
  3209. for(var prop in row) {
  3210. if (!row.IsParent) {
  3211. if (!isNaN(parseFloat(row[prop]))) {
  3212. if (that.columns[getFieldIndex(that.columns, prop)].groupBySumGroup) {
  3213. if (sumRow[prop] === undefined) {
  3214. sumRow[prop] = 0;
  3215. }
  3216. sumRow[prop] += +row[prop];
  3217. }
  3218. }
  3219. }
  3220. }
  3221. });
  3222. return sumRow;
  3223. };
  3224. var rowAttr = function (row, index) {
  3225. //Call the User Defined Function
  3226. originalRowAttr.apply([row, index]);
  3227. obj[dataTTId.toString()] = index;
  3228. if (!row.IsParent) {
  3229. obj[dataTTParentId.toString()] = parentId === undefined ? index : parentId;
  3230. } else {
  3231. parentId = index;
  3232. delete obj[dataTTParentId.toString()];
  3233. }
  3234. return obj;
  3235. };
  3236. var setObjectKeys = function () {
  3237. // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
  3238. Object.keys = function (o) {
  3239. if (o !== Object(o)) {
  3240. throw new TypeError('Object.keys called on a non-object');
  3241. }
  3242. var k = [],
  3243. p;
  3244. for (p in o) {
  3245. if (Object.prototype.hasOwnProperty.call(o, p)) {
  3246. k.push(p);
  3247. }
  3248. }
  3249. return k;
  3250. }
  3251. };
  3252. var groupBy = function (array , f) {
  3253. var groups = {};
  3254. $.each(array, function(i, o) {
  3255. var group = JSON.stringify(f(o));
  3256. groups[group] = groups[group] || [];
  3257. groups[group].push(o);
  3258. });
  3259. return Object.keys(groups).map(function (group) {
  3260. return groups[group];
  3261. });
  3262. };
  3263. var makeGrouped = function (that, data) {
  3264. var newRow = {},
  3265. newData = [],
  3266. sumRow = {};
  3267. var result = groupBy(data, function (item) {
  3268. return [item[that.options.groupByField]];
  3269. });
  3270. for (var i = 0; i < result.length; i++) {
  3271. newRow[that.options.groupByField.toString()] = result[i][0][that.options.groupByField];
  3272. newRow.IsParent = true;
  3273. result[i].unshift(newRow);
  3274. if (that.options.groupBySumGroup) {
  3275. sumRow = sumData(that, result[i])
  3276. if (!$.isEmptyObject(sumRow)) {
  3277. result[i].push(sumRow);
  3278. }
  3279. }
  3280. newRow = {};
  3281. }
  3282. newData = newData.concat.apply(newData, result);
  3283. if (!that.options.loaded && newData.length > 0) {
  3284. that.options.loaded = true;
  3285. that.options.originalData = that.options.data;
  3286. that.options.data = newData;
  3287. }
  3288. return newData;
  3289. };
  3290. $.extend($.fn.bootstrapTable.defaults, {
  3291. groupBy: false,
  3292. groupByField: '',
  3293. groupBySumGroup: false,
  3294. groupByInitExpanded: undefined, //node, 'all'
  3295. //internal variables
  3296. loaded: false,
  3297. originalData: undefined
  3298. });
  3299. $.fn.bootstrapTable.methods.push('collapseAll', 'expandAll');
  3300. $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
  3301. groupBySumGroup: false
  3302. });
  3303. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3304. _init = BootstrapTable.prototype.init,
  3305. _initData = BootstrapTable.prototype.initData;
  3306. BootstrapTable.prototype.init = function () {
  3307. //Temporal validation
  3308. if (!this.options.sortName) {
  3309. if ((this.options.groupBy) && (this.options.groupByField !== '')) {
  3310. var that = this;
  3311. // Compatibility: IE < 9 and old browsers
  3312. if (!Object.keys) {
  3313. setObjectKeys();
  3314. }
  3315. //Make sure that the internal variables are set correctly
  3316. this.options.loaded = false;
  3317. this.options.originalData = undefined;
  3318. originalRowAttr = this.options.rowAttributes;
  3319. this.options.rowAttributes = rowAttr;
  3320. this.$el.on('post-body.bs.table', function () {
  3321. that.$el.treetable({
  3322. expandable: true,
  3323. onNodeExpand: function () {
  3324. if (that.options.height) {
  3325. that.resetHeader();
  3326. }
  3327. },
  3328. onNodeCollapse: function () {
  3329. if (that.options.height) {
  3330. that.resetHeader();
  3331. }
  3332. }
  3333. }, true);
  3334. if (that.options.groupByInitExpanded !== undefined) {
  3335. if (typeof that.options.groupByInitExpanded === 'number') {
  3336. that.expandNode(that.options.groupByInitExpanded);
  3337. } else if (that.options.groupByInitExpanded.toLowerCase() === 'all') {
  3338. that.expandAll();
  3339. }
  3340. }
  3341. });
  3342. }
  3343. }
  3344. _init.apply(this, Array.prototype.slice.apply(arguments));
  3345. };
  3346. BootstrapTable.prototype.initData = function (data, type) {
  3347. //Temporal validation
  3348. if (!this.options.sortName) {
  3349. if ((this.options.groupBy) && (this.options.groupByField !== '')) {
  3350. data = makeGrouped(this, data ? data : this.options.data);
  3351. }
  3352. }
  3353. _initData.apply(this, [data, type]);
  3354. };
  3355. BootstrapTable.prototype.expandAll = function () {
  3356. this.$el.treetable('expandAll');
  3357. };
  3358. BootstrapTable.prototype.collapseAll = function () {
  3359. this.$el.treetable('collapseAll');
  3360. };
  3361. BootstrapTable.prototype.expandNode = function (id) {
  3362. id = getParentRowId(this, id);
  3363. if (id !== undefined) {
  3364. this.$el.treetable('expandNode', id);
  3365. }
  3366. }
  3367. }(jQuery);
  3368. /**
  3369. * @author: Dennis Hernández
  3370. * @webSite: http://djhvscf.github.io/Blog
  3371. * @version: v1.0.0
  3372. *
  3373. * @update zhixin wen <wenzhixin2010@gmail.com>
  3374. */
  3375. !function ($) {
  3376. 'use strict';
  3377. $.extend($.fn.bootstrapTable.defaults, {
  3378. keyEvents: false
  3379. });
  3380. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3381. _init = BootstrapTable.prototype.init;
  3382. BootstrapTable.prototype.init = function () {
  3383. _init.apply(this, Array.prototype.slice.apply(arguments));
  3384. this.initKeyEvents();
  3385. };
  3386. BootstrapTable.prototype.initKeyEvents = function () {
  3387. if (this.options.keyEvents) {
  3388. var that = this;
  3389. $(document).off('keydown').on('keydown', function (e) {
  3390. var $search = that.$toolbar.find('.search input'),
  3391. $refresh = that.$toolbar.find('button[name="refresh"]'),
  3392. $toggle = that.$toolbar.find('button[name="toggle"]'),
  3393. $paginationSwitch = that.$toolbar.find('button[name="paginationSwitch"]');
  3394. if (document.activeElement === $search.get(0)) {
  3395. return true;
  3396. }
  3397. switch (e.keyCode) {
  3398. case 83: //s
  3399. if (!that.options.search) {
  3400. return;
  3401. }
  3402. $search.focus();
  3403. return false;
  3404. case 82: //r
  3405. if (!that.options.showRefresh) {
  3406. return;
  3407. }
  3408. $refresh.click();
  3409. return false;
  3410. case 84: //t
  3411. if (!that.options.showToggle) {
  3412. return;
  3413. }
  3414. $toggle.click();
  3415. return false;
  3416. case 80: //p
  3417. if (!that.options.showPaginationSwitch) {
  3418. return;
  3419. }
  3420. $paginationSwitch.click();
  3421. return false;
  3422. case 37: // left
  3423. if (!that.options.pagination) {
  3424. return;
  3425. }
  3426. that.prevPage();
  3427. return false;
  3428. case 39: // right
  3429. if (!that.options.pagination) {
  3430. return;
  3431. }
  3432. that.nextPage();
  3433. return;
  3434. }
  3435. });
  3436. }
  3437. };
  3438. }(jQuery);
  3439. /**
  3440. * @author: Dennis Hernández
  3441. * @webSite: http://djhvscf.github.io/Blog
  3442. * @version: v1.1.0
  3443. */
  3444. !function ($) {
  3445. 'use strict';
  3446. var getFieldIndex = function (columns, field) {
  3447. var index = -1;
  3448. $.each(columns, function (i, column) {
  3449. if (column.field === field) {
  3450. index = i;
  3451. return false;
  3452. }
  3453. return true;
  3454. });
  3455. return index;
  3456. };
  3457. var showHideColumns = function (that, checked) {
  3458. if (that.options.columnsHidden.length > 0 ) {
  3459. $.each(that.columns, function (i, column) {
  3460. if (that.options.columnsHidden.indexOf(column.field) !== -1) {
  3461. if (column.visible !== checked) {
  3462. that.toggleColumn(getFieldIndex(that.columns, column.field), checked, true);
  3463. }
  3464. }
  3465. });
  3466. }
  3467. };
  3468. var resetView = function (that) {
  3469. if (that.options.height || that.options.showFooter) {
  3470. setTimeout(that.resetView, 1);
  3471. }
  3472. };
  3473. var changeView = function (that, width, height) {
  3474. if (that.options.minHeight) {
  3475. if ((width <= that.options.minWidth) && (height <= that.options.minHeight)) {
  3476. conditionCardView(that);
  3477. } else if ((width > that.options.minWidth) && (height > that.options.minHeight)) {
  3478. conditionFullView(that);
  3479. }
  3480. } else {
  3481. if (width <= that.options.minWidth) {
  3482. conditionCardView(that);
  3483. } else if (width > that.options.minWidth) {
  3484. conditionFullView(that);
  3485. }
  3486. }
  3487. resetView(that);
  3488. };
  3489. var conditionCardView = function (that) {
  3490. changeTableView(that, false);
  3491. showHideColumns(that, false);
  3492. };
  3493. var conditionFullView = function (that) {
  3494. changeTableView(that, true);
  3495. showHideColumns(that, true);
  3496. };
  3497. var changeTableView = function (that, cardViewState) {
  3498. that.options.cardView = cardViewState;
  3499. that.toggleView();
  3500. };
  3501. var debounce = function(func,wait) {
  3502. var timeout;
  3503. return function() {
  3504. var context = this,
  3505. args = arguments;
  3506. var later = function() {
  3507. timeout = null;
  3508. func.apply(context,args);
  3509. };
  3510. clearTimeout(timeout);
  3511. timeout = setTimeout(later, wait);
  3512. };
  3513. };
  3514. $.extend($.fn.bootstrapTable.defaults, {
  3515. mobileResponsive: false,
  3516. minWidth: 562,
  3517. minHeight: undefined,
  3518. heightThreshold: 100, // just slightly larger than mobile chrome's auto-hiding toolbar
  3519. checkOnInit: true,
  3520. columnsHidden: []
  3521. });
  3522. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3523. _init = BootstrapTable.prototype.init;
  3524. BootstrapTable.prototype.init = function () {
  3525. _init.apply(this, Array.prototype.slice.apply(arguments));
  3526. if (!this.options.mobileResponsive) {
  3527. return;
  3528. }
  3529. if (!this.options.minWidth) {
  3530. return;
  3531. }
  3532. var that = this,
  3533. old = {
  3534. width: $(window).width(),
  3535. height: $(window).height()
  3536. };
  3537. $(window).on('resize orientationchange',debounce(function (evt) {
  3538. // reset view if height has only changed by at least the threshold.
  3539. var height = $(this).height(),
  3540. width = $(this).width();
  3541. if (Math.abs(old.height - height) > that.options.heightThreshold || old.width != width) {
  3542. changeView(that, width, height);
  3543. old = {
  3544. width: width,
  3545. height: height
  3546. };
  3547. }
  3548. },200));
  3549. if (this.options.checkOnInit) {
  3550. var height = $(window).height(),
  3551. width = $(window).width();
  3552. changeView(this, width, height);
  3553. old = {
  3554. width: width,
  3555. height: height
  3556. };
  3557. }
  3558. };
  3559. }(jQuery);
  3560. /**
  3561. * @author Nadim Basalamah <dimbslmh@gmail.com>
  3562. * @version: v1.0.0
  3563. * https://github.com/dimbslmh/bootstrap-table/tree/master/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js
  3564. */
  3565. (function($) {
  3566. 'use strict';
  3567. var isSingleSort = false;
  3568. var sort_order = {
  3569. asc: 'Ascending',
  3570. desc: 'Descending'
  3571. };
  3572. var showSortModal = function(that) {
  3573. var _selector = that.$sortModal.selector,
  3574. _id = _selector.substr(1);
  3575. if (!$(_id).hasClass("modal")) {
  3576. var sModal = ' <div class="modal fade" id="' + _id + '" tabindex="-1" role="dialog" aria-labelledby="' + _id + 'Label" aria-hidden="true">';
  3577. sModal += ' <div class="modal-dialog">';
  3578. sModal += ' <div class="modal-content">';
  3579. sModal += ' <div class="modal-header">';
  3580. sModal += ' <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>';
  3581. sModal += ' <h4 class="modal-title" id="' + _id + 'Label">' + that.options.formatMultipleSort() + '</h4>';
  3582. sModal += ' </div>';
  3583. sModal += ' <div class="modal-body">';
  3584. sModal += ' <div class="bootstrap-table">';
  3585. sModal += ' <div class="fixed-table-toolbar">';
  3586. sModal += ' <div class="bars">';
  3587. sModal += ' <div id="toolbar">';
  3588. sModal += ' <button id="add" type="button" class="btn btn-default"><i class="' + that.options.iconsPrefix + ' ' + that.options.icons.plus + '"></i> ' + that.options.formatAddLevel() + '</button>';
  3589. sModal += ' <button id="delete" type="button" class="btn btn-default" disabled><i class="' + that.options.iconsPrefix + ' ' + that.options.icons.minus + '"></i> ' + that.options.formatDeleteLevel() + '</button>';
  3590. sModal += ' </div>';
  3591. sModal += ' </div>';
  3592. sModal += ' </div>';
  3593. sModal += ' <div class="fixed-table-container">';
  3594. sModal += ' <table id="multi-sort" class="table">';
  3595. sModal += ' <thead>';
  3596. sModal += ' <tr>';
  3597. sModal += ' <th></th>';
  3598. sModal += ' <th><div class="th-inner">' + that.options.formatColumn() + '</div></th>';
  3599. sModal += ' <th><div class="th-inner">' + that.options.formatOrder() + '</div></th>';
  3600. sModal += ' </tr>';
  3601. sModal += ' </thead>';
  3602. sModal += ' <tbody></tbody>';
  3603. sModal += ' </table>';
  3604. sModal += ' </div>';
  3605. sModal += ' </div>';
  3606. sModal += ' </div>';
  3607. sModal += ' <div class="modal-footer">';
  3608. sModal += ' <button type="button" class="btn btn-default" data-dismiss="modal">' + that.options.formatCancel() + '</button>';
  3609. sModal += ' <button type="button" class="btn btn-primary">' + that.options.formatSort() + '</button>';
  3610. sModal += ' </div>';
  3611. sModal += ' </div>';
  3612. sModal += ' </div>';
  3613. sModal += ' </div>';
  3614. $("body").append($(sModal));
  3615. that.$sortModal = $(_selector);
  3616. var $rows = that.$sortModal.find("tbody > tr");
  3617. that.$sortModal.off('click', '#add').on('click', '#add', function() {
  3618. var total = that.$sortModal.find('.multi-sort-name:first option').length,
  3619. current = that.$sortModal.find('tbody tr').length;
  3620. if (current < total) {
  3621. current++;
  3622. that.addLevel();
  3623. that.setButtonStates();
  3624. }
  3625. });
  3626. that.$sortModal.off('click', '#delete').on('click', '#delete', function() {
  3627. var total = that.$sortModal.find('.multi-sort-name:first option').length,
  3628. current = that.$sortModal.find('tbody tr').length;
  3629. if (current > 1 && current <= total) {
  3630. current--;
  3631. that.$sortModal.find('tbody tr:last').remove();
  3632. that.setButtonStates();
  3633. }
  3634. });
  3635. that.$sortModal.off('click', '.btn-primary').on('click', '.btn-primary', function() {
  3636. var $rows = that.$sortModal.find("tbody > tr"),
  3637. $alert = that.$sortModal.find('div.alert'),
  3638. fields = [],
  3639. results = [];
  3640. that.options.sortPriority = $.map($rows, function(row) {
  3641. var $row = $(row),
  3642. name = $row.find('.multi-sort-name').val(),
  3643. order = $row.find('.multi-sort-order').val();
  3644. fields.push(name);
  3645. return {
  3646. sortName: name,
  3647. sortOrder: order
  3648. };
  3649. });
  3650. var sorted_fields = fields.sort();
  3651. for (var i = 0; i < fields.length - 1; i++) {
  3652. if (sorted_fields[i + 1] == sorted_fields[i]) {
  3653. results.push(sorted_fields[i]);
  3654. }
  3655. }
  3656. if (results.length > 0) {
  3657. if ($alert.length === 0) {
  3658. $alert = '<div class="alert alert-danger" role="alert"><strong>' + that.options.formatDuplicateAlertTitle() + '</strong> ' + that.options.formatDuplicateAlertDescription() + '</div>';
  3659. $($alert).insertBefore(that.$sortModal.find('.bars'));
  3660. }
  3661. } else {
  3662. if ($alert.length === 1) {
  3663. $($alert).remove();
  3664. }
  3665. that.options.sortName = "";
  3666. that.onMultipleSort();
  3667. that.$sortModal.modal('hide');
  3668. }
  3669. });
  3670. if (that.options.sortPriority === null || that.options.sortPriority.length === 0) {
  3671. if (that.options.sortName) {
  3672. that.options.sortPriority = [{
  3673. sortName: that.options.sortName,
  3674. sortOrder: that.options.sortOrder
  3675. }];
  3676. }
  3677. }
  3678. if (that.options.sortPriority !== null && that.options.sortPriority.length > 0) {
  3679. if ($rows.length < that.options.sortPriority.length && typeof that.options.sortPriority === 'object') {
  3680. for (var i = 0; i < that.options.sortPriority.length; i++) {
  3681. that.addLevel(i, that.options.sortPriority[i]);
  3682. }
  3683. }
  3684. } else {
  3685. that.addLevel(0);
  3686. }
  3687. that.setButtonStates();
  3688. }
  3689. };
  3690. $.extend($.fn.bootstrapTable.defaults, {
  3691. showMultiSort: false,
  3692. sortPriority: null,
  3693. onMultipleSort: function() {
  3694. return false;
  3695. }
  3696. });
  3697. $.extend($.fn.bootstrapTable.defaults.icons, {
  3698. sort: 'glyphicon-sort',
  3699. plus: 'glyphicon-plus',
  3700. minus: 'glyphicon-minus'
  3701. });
  3702. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  3703. 'multiple-sort.bs.table': 'onMultipleSort'
  3704. });
  3705. $.extend($.fn.bootstrapTable.locales, {
  3706. formatMultipleSort: function() {
  3707. return 'Multiple Sort';
  3708. },
  3709. formatAddLevel: function() {
  3710. return "Add Level";
  3711. },
  3712. formatDeleteLevel: function() {
  3713. return "Delete Level";
  3714. },
  3715. formatColumn: function() {
  3716. return "Column";
  3717. },
  3718. formatOrder: function() {
  3719. return "Order";
  3720. },
  3721. formatSortBy: function() {
  3722. return "Sort by";
  3723. },
  3724. formatThenBy: function() {
  3725. return "Then by";
  3726. },
  3727. formatSort: function() {
  3728. return "Sort";
  3729. },
  3730. formatCancel: function() {
  3731. return "Cancel";
  3732. },
  3733. formatDuplicateAlertTitle: function() {
  3734. return "Duplicate(s) detected!";
  3735. },
  3736. formatDuplicateAlertDescription: function() {
  3737. return "Please remove or change any duplicate column.";
  3738. }
  3739. });
  3740. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  3741. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3742. _initToolbar = BootstrapTable.prototype.initToolbar;
  3743. BootstrapTable.prototype.initToolbar = function() {
  3744. this.showToolbar = true;
  3745. var that = this,
  3746. sortModalId = '#sortModal_' + this.$el.attr('id');
  3747. this.$sortModal = $(sortModalId);
  3748. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  3749. if (this.options.showMultiSort) {
  3750. var $btnGroup = this.$toolbar.find('>.btn-group').first(),
  3751. $multiSortBtn = this.$toolbar.find('div.multi-sort');
  3752. if (!$multiSortBtn.length) {
  3753. $multiSortBtn = ' <button class="multi-sort btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" data-toggle="modal" data-target="' + sortModalId + '" title="' + this.options.formatMultipleSort() + '">';
  3754. $multiSortBtn += ' <i class="' + this.options.iconsPrefix + ' ' + this.options.icons.sort + '"></i>';
  3755. $multiSortBtn += '</button>';
  3756. $btnGroup.append($multiSortBtn);
  3757. showSortModal(that);
  3758. }
  3759. this.$el.on('sort.bs.table', function() {
  3760. isSingleSort = true;
  3761. });
  3762. this.$el.on('multiple-sort.bs.table', function() {
  3763. isSingleSort = false;
  3764. });
  3765. this.$el.on('load-success.bs.table', function() {
  3766. if (!isSingleSort && that.options.sortPriority !== null && typeof that.options.sortPriority === 'object') {
  3767. that.onMultipleSort();
  3768. }
  3769. });
  3770. this.$el.on('column-switch.bs.table', function(field, checked) {
  3771. for (var i = 0; i < that.options.sortPriority.length; i++) {
  3772. if (that.options.sortPriority[i].sortName === checked) {
  3773. that.options.sortPriority.splice(i, 1);
  3774. }
  3775. }
  3776. that.assignSortableArrows();
  3777. that.$sortModal.remove();
  3778. showSortModal(that);
  3779. });
  3780. this.$el.on('reset-view.bs.table', function() {
  3781. if (!isSingleSort && that.options.sortPriority !== null && typeof that.options.sortPriority === 'object') {
  3782. that.assignSortableArrows();
  3783. }
  3784. });
  3785. }
  3786. };
  3787. BootstrapTable.prototype.onMultipleSort = function() {
  3788. var that = this;
  3789. var cmp = function(x, y) {
  3790. return x > y ? 1 : x < y ? -1 : 0;
  3791. };
  3792. var arrayCmp = function(a, b) {
  3793. var arr1 = [],
  3794. arr2 = [];
  3795. for (var i = 0; i < that.options.sortPriority.length; i++) {
  3796. var order = that.options.sortPriority[i].sortOrder === 'desc' ? -1 : 1,
  3797. aa = a[that.options.sortPriority[i].sortName],
  3798. bb = b[that.options.sortPriority[i].sortName];
  3799. if (aa === undefined || aa === null) {
  3800. aa = '';
  3801. }
  3802. if (bb === undefined || bb === null) {
  3803. bb = '';
  3804. }
  3805. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  3806. aa = parseFloat(aa);
  3807. bb = parseFloat(bb);
  3808. }
  3809. if (typeof aa !== 'string') {
  3810. aa = aa.toString();
  3811. }
  3812. arr1.push(
  3813. order * cmp(aa, bb));
  3814. arr2.push(
  3815. order * cmp(bb, aa));
  3816. }
  3817. return cmp(arr1, arr2);
  3818. };
  3819. this.data.sort(function(a, b) {
  3820. return arrayCmp(a, b);
  3821. });
  3822. this.initBody();
  3823. this.assignSortableArrows();
  3824. this.trigger('multiple-sort');
  3825. };
  3826. BootstrapTable.prototype.addLevel = function(index, sortPriority) {
  3827. var text = index === 0 ? this.options.formatSortBy() : this.options.formatThenBy();
  3828. this.$sortModal.find('tbody')
  3829. .append($('<tr>')
  3830. .append($('<td>').text(text))
  3831. .append($('<td>').append($('<select class="form-control multi-sort-name">')))
  3832. .append($('<td>').append($('<select class="form-control multi-sort-order">')))
  3833. );
  3834. var $multiSortName = this.$sortModal.find('.multi-sort-name').last(),
  3835. $multiSortOrder = this.$sortModal.find('.multi-sort-order').last();
  3836. $.each(this.columns, function (i, column) {
  3837. if (column.sortable === false || column.visible === false) {
  3838. return true;
  3839. }
  3840. $multiSortName.append('<option value="' + column.field + '">' + column.title + '</option>');
  3841. });
  3842. $.each(sort_order, function(value, order) {
  3843. $multiSortOrder.append('<option value="' + value + '">' + order + '</option>');
  3844. });
  3845. if (sortPriority !== undefined) {
  3846. $multiSortName.find('option[value="' + sortPriority.sortName + '"]').attr("selected", true);
  3847. $multiSortOrder.find('option[value="' + sortPriority.sortOrder + '"]').attr("selected", true);
  3848. }
  3849. };
  3850. BootstrapTable.prototype.assignSortableArrows = function() {
  3851. var that = this,
  3852. headers = that.$header.find('th');
  3853. for (var i = 0; i < headers.length; i++) {
  3854. for (var c = 0; c < that.options.sortPriority.length; c++) {
  3855. if ($(headers[i]).data('field') === that.options.sortPriority[c].sortName) {
  3856. $(headers[i]).find('.sortable').removeClass('desc asc').addClass(that.options.sortPriority[c].sortOrder);
  3857. }
  3858. }
  3859. }
  3860. };
  3861. BootstrapTable.prototype.setButtonStates = function() {
  3862. var total = this.$sortModal.find('.multi-sort-name:first option').length,
  3863. current = this.$sortModal.find('tbody tr').length;
  3864. if (current == total) {
  3865. this.$sortModal.find('#add').attr('disabled', 'disabled');
  3866. }
  3867. if (current > 1) {
  3868. this.$sortModal.find('#delete').removeAttr('disabled');
  3869. }
  3870. if (current < total) {
  3871. this.$sortModal.find('#add').removeAttr('disabled');
  3872. }
  3873. if (current == 1) {
  3874. this.$sortModal.find('#delete').attr('disabled', 'disabled');
  3875. }
  3876. };
  3877. })(jQuery);
  3878. /**
  3879. * @author: Brian Huisman
  3880. * @webSite: http://www.greywyvern.com
  3881. * @version: v1.0.0
  3882. * JS function to allow natural sorting on bootstrap-table columns
  3883. * just add data-sorter="alphanum" to any th
  3884. *
  3885. * @update Dennis Hernández <http://djhvscf.github.io/Blog>
  3886. */
  3887. function alphanum(a, b) {
  3888. function chunkify(t) {
  3889. var tz = [],
  3890. x = 0,
  3891. y = -1,
  3892. n = 0,
  3893. i,
  3894. j;
  3895. while (i = (j = t.charAt(x++)).charCodeAt(0)) {
  3896. var m = (i === 46 || (i >= 48 && i <= 57));
  3897. if (m !== n) {
  3898. tz[++y] = "";
  3899. n = m;
  3900. }
  3901. tz[y] += j;
  3902. }
  3903. return tz;
  3904. }
  3905. var aa = chunkify(a);
  3906. var bb = chunkify(b);
  3907. for (x = 0; aa[x] && bb[x]; x++) {
  3908. if (aa[x] !== bb[x]) {
  3909. var c = Number(aa[x]),
  3910. d = Number(bb[x]);
  3911. if (c == aa[x] && d == bb[x]) {
  3912. return c - d;
  3913. } else {
  3914. return (aa[x] > bb[x]) ? 1 : -1;
  3915. }
  3916. }
  3917. }
  3918. return aa.length - bb.length;
  3919. }
  3920. /**
  3921. * @author: Dennis Hernández
  3922. * @webSite: http://djhvscf.github.io/Blog
  3923. * @version: v1.1.0
  3924. */
  3925. !function ($) {
  3926. 'use strict';
  3927. var getFieldIndex = function (columns, field) {
  3928. var index = -1;
  3929. $.each(columns, function (i, column) {
  3930. if (column.field === field) {
  3931. index = i;
  3932. return false;
  3933. }
  3934. return true;
  3935. });
  3936. return index;
  3937. };
  3938. $.extend($.fn.bootstrapTable.defaults, {
  3939. reorderableColumns: false,
  3940. maxMovingRows: 10,
  3941. onReorderColumn: function (headerFields) {
  3942. return false;
  3943. },
  3944. dragaccept: null
  3945. });
  3946. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  3947. 'reorder-column.bs.table': 'onReorderColumn'
  3948. });
  3949. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3950. _initHeader = BootstrapTable.prototype.initHeader,
  3951. _toggleColumn = BootstrapTable.prototype.toggleColumn,
  3952. _toggleView = BootstrapTable.prototype.toggleView,
  3953. _resetView = BootstrapTable.prototype.resetView;
  3954. BootstrapTable.prototype.initHeader = function () {
  3955. _initHeader.apply(this, Array.prototype.slice.apply(arguments));
  3956. if (!this.options.reorderableColumns) {
  3957. return;
  3958. }
  3959. this.makeRowsReorderable();
  3960. };
  3961. BootstrapTable.prototype.toggleColumn = function () {
  3962. _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
  3963. if (!this.options.reorderableColumns) {
  3964. return;
  3965. }
  3966. this.makeRowsReorderable();
  3967. };
  3968. BootstrapTable.prototype.toggleView = function () {
  3969. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  3970. if (!this.options.reorderableColumns) {
  3971. return;
  3972. }
  3973. if (this.options.cardView) {
  3974. return;
  3975. }
  3976. this.makeRowsReorderable();
  3977. };
  3978. BootstrapTable.prototype.resetView = function () {
  3979. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  3980. if (!this.options.reorderableColumns) {
  3981. return;
  3982. }
  3983. this.makeRowsReorderable();
  3984. };
  3985. BootstrapTable.prototype.makeRowsReorderable = function () {
  3986. var that = this;
  3987. try {
  3988. $(this.$el).dragtable('destroy');
  3989. } catch (e) {}
  3990. $(this.$el).dragtable({
  3991. maxMovingRows: that.options.maxMovingRows,
  3992. dragaccept: that.options.dragaccept,
  3993. clickDelay:200,
  3994. beforeStop: function() {
  3995. var ths = [],
  3996. columns = [],
  3997. columnsHidden = [],
  3998. columnIndex = -1;
  3999. that.$header.find('th').each(function (i) {
  4000. ths.push($(this).data('field'));
  4001. });
  4002. //Exist columns not shown
  4003. if (ths.length < that.columns.length) {
  4004. columnsHidden = $.grep(that.columns, function (column) {
  4005. return !column.visible;
  4006. });
  4007. for (var i = 0; i < columnsHidden.length; i++) {
  4008. ths.push(columnsHidden[i].field);
  4009. }
  4010. }
  4011. for (var i = 0; i < ths.length; i++ ) {
  4012. columnIndex = getFieldIndex(that.columns, ths[i]);
  4013. if (columnIndex !== -1) {
  4014. columns.push(that.columns[columnIndex]);
  4015. that.columns.splice(columnIndex, 1);
  4016. }
  4017. }
  4018. that.columns = that.columns.concat(columns);
  4019. that.header.fields = ths;
  4020. that.resetView();
  4021. that.trigger('reorder-column', ths);
  4022. }
  4023. });
  4024. };
  4025. }(jQuery);
  4026. /**
  4027. * @author: Dennis Hernández
  4028. * @webSite: http://djhvscf.github.io/Blog
  4029. * @version: v1.0.0
  4030. */
  4031. !function ($) {
  4032. 'use strict';
  4033. var isSearch = false;
  4034. var rowAttr = function (row, index) {
  4035. return {
  4036. id: 'customId_' + index
  4037. };
  4038. };
  4039. $.extend($.fn.bootstrapTable.defaults, {
  4040. reorderableRows: false,
  4041. onDragStyle: null,
  4042. onDropStyle: null,
  4043. onDragClass: "reorder_rows_onDragClass",
  4044. dragHandle: null,
  4045. useRowAttrFunc: false,
  4046. onReorderRowsDrag: function (table, row) {
  4047. return false;
  4048. },
  4049. onReorderRowsDrop: function (table, row) {
  4050. return false;
  4051. },
  4052. onReorderRow: function (newData) {
  4053. return false;
  4054. }
  4055. });
  4056. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  4057. 'reorder-row.bs.table': 'onReorderRow'
  4058. });
  4059. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  4060. _init = BootstrapTable.prototype.init,
  4061. _initSearch = BootstrapTable.prototype.initSearch;
  4062. BootstrapTable.prototype.init = function () {
  4063. if (!this.options.reorderableRows) {
  4064. return;
  4065. }
  4066. var that = this;
  4067. if (this.options.useRowAttrFunc) {
  4068. this.options.rowAttributes = rowAttr;
  4069. }
  4070. var onPostBody = this.options.onPostBody;
  4071. this.options.onPostBody = function () {
  4072. setTimeout(function () {
  4073. that.makeRowsReorderable();
  4074. onPostBody.apply();
  4075. }, 1);
  4076. };
  4077. _init.apply(this, Array.prototype.slice.apply(arguments));
  4078. };
  4079. BootstrapTable.prototype.initSearch = function () {
  4080. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  4081. if (!this.options.reorderableRows) {
  4082. return;
  4083. }
  4084. //Known issue after search if you reorder the rows the data is not display properly
  4085. //isSearch = true;
  4086. };
  4087. BootstrapTable.prototype.makeRowsReorderable = function () {
  4088. if (this.options.cardView) {
  4089. return;
  4090. }
  4091. var that = this;
  4092. this.$el.tableDnD({
  4093. onDragStyle: that.options.onDragStyle,
  4094. onDropStyle: that.options.onDropStyle,
  4095. onDragClass: that.options.onDragClass,
  4096. onDrop: that.onDrop,
  4097. onDragStart: that.options.onReorderRowsDrag,
  4098. dragHandle: that.options.dragHandle
  4099. });
  4100. };
  4101. BootstrapTable.prototype.onDrop = function (table, droppedRow) {
  4102. var tableBs = $(table),
  4103. tableBsData = tableBs.data('bootstrap.table'),
  4104. tableBsOptions = tableBs.data('bootstrap.table').options,
  4105. row = null,
  4106. newData = [];
  4107. for (var i = 0; i < table.tBodies[0].rows.length; i++) {
  4108. row = $(table.tBodies[0].rows[i]);
  4109. newData.push(tableBsOptions.data[row.data('index')]);
  4110. row.data('index', i).attr('data-index', i);
  4111. }
  4112. tableBsOptions.data = newData;
  4113. //Call the user defined function
  4114. tableBsOptions.onReorderRowsDrop.apply(table, [table, droppedRow]);
  4115. //Call the event reorder-row
  4116. tableBsData.trigger('reorder-row', newData);
  4117. };
  4118. }(jQuery);
  4119. /**
  4120. * @author: Dennis Hernández
  4121. * @webSite: http://djhvscf.github.io/Blog
  4122. * @version: v1.0.0
  4123. */
  4124. (function ($) {
  4125. 'use strict';
  4126. var initResizable = function (that) {
  4127. //Deletes the plugin to re-create it
  4128. that.$el.colResizable({disable: true});
  4129. //Creates the plugin
  4130. that.$el.colResizable({
  4131. liveDrag: that.options.liveDrag,
  4132. fixed: that.options.fixed,
  4133. headerOnly: that.options.headerOnly,
  4134. minWidth: that.options.minWidth,
  4135. hoverCursor: that.options.hoverCursor,
  4136. dragCursor: that.options.dragCursor,
  4137. onResize: that.onResize,
  4138. onDrag: that.options.onResizableDrag
  4139. });
  4140. };
  4141. $.extend($.fn.bootstrapTable.defaults, {
  4142. resizable: false,
  4143. liveDrag: false,
  4144. fixed: true,
  4145. headerOnly: false,
  4146. minWidth: 15,
  4147. hoverCursor: 'e-resize',
  4148. dragCursor: 'e-resize',
  4149. onResizableResize: function (e) {
  4150. return false;
  4151. },
  4152. onResizableDrag: function (e) {
  4153. return false;
  4154. }
  4155. });
  4156. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  4157. _toggleView = BootstrapTable.prototype.toggleView,
  4158. _resetView = BootstrapTable.prototype.resetView;
  4159. BootstrapTable.prototype.toggleView = function () {
  4160. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  4161. if (this.options.resizable && this.options.cardView) {
  4162. //Deletes the plugin
  4163. $(this.$el).colResizable({disable: true});
  4164. }
  4165. };
  4166. BootstrapTable.prototype.resetView = function () {
  4167. var that = this;
  4168. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  4169. if (this.options.resizable) {
  4170. // because in fitHeader function, we use setTimeout(func, 100);
  4171. setTimeout(function () {
  4172. initResizable(that);
  4173. }, 100);
  4174. }
  4175. };
  4176. BootstrapTable.prototype.onResize = function (e) {
  4177. var that = $(e.currentTarget);
  4178. that.bootstrapTable('resetView');
  4179. that.data('bootstrap.table').options.onResizableResize.apply(e);
  4180. }
  4181. })(jQuery);
  4182. /**
  4183. * @author: aperez <aperez@datadec.es>
  4184. * @version: v2.0.0
  4185. *
  4186. * @update Dennis Hernández <http://djhvscf.github.io/Blog>
  4187. */
  4188. !function($) {
  4189. 'use strict';
  4190. var firstLoad = false;
  4191. var sprintf = function(str) {
  4192. var args = arguments,
  4193. flag = true,
  4194. i = 1;
  4195. str = str.replace(/%s/g, function() {
  4196. var arg = args[i++];
  4197. if (typeof arg === 'undefined') {
  4198. flag = false;
  4199. return '';
  4200. }
  4201. return arg;
  4202. });
  4203. return flag ? str : '';
  4204. };
  4205. var calculateObjectValue = function (self, name, args, defaultValue) {
  4206. if (typeof name === 'string') {
  4207. // support obj.func1.func2
  4208. var names = name.split('.');
  4209. if (names.length > 1) {
  4210. name = window;
  4211. $.each(names, function (i, f) {
  4212. name = name[f];
  4213. });
  4214. } else {
  4215. name = window[name];
  4216. }
  4217. }
  4218. if (typeof name === 'object') {
  4219. return name;
  4220. }
  4221. if (typeof name === 'function') {
  4222. return name.apply(self, args);
  4223. }
  4224. return defaultValue;
  4225. };
  4226. var showAvdSearch = function(pColumns, searchTitle, searchText, that) {
  4227. if (!$("#avdSearchModal").hasClass("modal")) {
  4228. var vModal = "<div id=\"avdSearchModal\" class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\" aria-hidden=\"true\">";
  4229. vModal += "<div class=\"modal-dialog modal-xs\">";
  4230. vModal += " <div class=\"modal-content\">";
  4231. vModal += " <div class=\"modal-header\">";
  4232. vModal += " <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" >&times;</button>";
  4233. vModal += sprintf(" <h4 class=\"modal-title\">%s</h4>", searchTitle);
  4234. vModal += " </div>";
  4235. vModal += " <div class=\"modal-body modal-body-custom\">";
  4236. vModal += " <div class=\"container-fluid\" id=\"avdSearchModalContent\" style=\"padding-right: 0px;padding-left: 0px;\" >";
  4237. vModal += " </div>";
  4238. vModal += " </div>";
  4239. vModal += " </div>";
  4240. vModal += " </div>";
  4241. vModal += "</div>";
  4242. $("body").append($(vModal));
  4243. var vFormAvd = createFormAvd(pColumns, searchText, that),
  4244. timeoutId = 0;;
  4245. $('#avdSearchModalContent').append(vFormAvd.join(''));
  4246. $('#' + that.options.idForm).off('keyup blur', 'input').on('keyup blur', 'input', function (event) {
  4247. clearTimeout(timeoutId);
  4248. timeoutId = setTimeout(function () {
  4249. that.onColumnAdvancedSearch(event);
  4250. }, that.options.searchTimeOut);
  4251. });
  4252. $("#btnCloseAvd").click(function() {
  4253. $("#avdSearchModal").modal('hide');
  4254. });
  4255. $("#avdSearchModal").modal();
  4256. } else {
  4257. $("#avdSearchModal").modal();
  4258. }
  4259. };
  4260. var createFormAvd = function(pColumns, searchText, that) {
  4261. var htmlForm = [];
  4262. htmlForm.push(sprintf('<form class="form-horizontal" id="%s" action="%s" >', that.options.idForm, that.options.actionForm));
  4263. for (var i in pColumns) {
  4264. var vObjCol = pColumns[i];
  4265. if (!vObjCol.checkbox && vObjCol.visible && vObjCol.searchable) {
  4266. htmlForm.push('<div class="form-group">');
  4267. htmlForm.push(sprintf('<label class="col-sm-4 control-label">%s</label>', vObjCol.title));
  4268. htmlForm.push('<div class="col-sm-6">');
  4269. htmlForm.push(sprintf('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">', vObjCol.field, vObjCol.title, vObjCol.field));
  4270. htmlForm.push('</div>');
  4271. htmlForm.push('</div>');
  4272. }
  4273. }
  4274. htmlForm.push('<div class="form-group">');
  4275. htmlForm.push('<div class="col-sm-offset-9 col-sm-3">');
  4276. htmlForm.push(sprintf('<button type="button" id="btnCloseAvd" class="btn btn-default" >%s</button>', searchText));
  4277. htmlForm.push('</div>');
  4278. htmlForm.push('</div>');
  4279. htmlForm.push('</form>');
  4280. return htmlForm;
  4281. };
  4282. $.extend($.fn.bootstrapTable.defaults, {
  4283. advancedSearch: false,
  4284. idForm: 'advancedSearch',
  4285. actionForm: '',
  4286. idTable: undefined,
  4287. onColumnAdvancedSearch: function (field, text) {
  4288. return false;
  4289. }
  4290. });
  4291. $.extend($.fn.bootstrapTable.defaults.icons, {
  4292. advancedSearchIcon: 'glyphicon-chevron-down'
  4293. });
  4294. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  4295. 'column-advanced-search.bs.table': 'onColumnAdvancedSearch'
  4296. });
  4297. $.extend($.fn.bootstrapTable.locales, {
  4298. formatAdvancedSearch: function() {
  4299. return 'Advanced search';
  4300. },
  4301. formatAdvancedCloseButton: function() {
  4302. return "Close";
  4303. }
  4304. });
  4305. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  4306. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  4307. _initToolbar = BootstrapTable.prototype.initToolbar,
  4308. _load = BootstrapTable.prototype.load,
  4309. _initSearch = BootstrapTable.prototype.initSearch;
  4310. BootstrapTable.prototype.initToolbar = function() {
  4311. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  4312. if (!this.options.search) {
  4313. return;
  4314. }
  4315. if (!this.options.advancedSearch) {
  4316. return;
  4317. }
  4318. var that = this,
  4319. html = [];
  4320. html.push(sprintf('<div class="columns columns-%s btn-group pull-%s" role="group">', this.options.buttonsAlign, this.options.buttonsAlign));
  4321. html.push(sprintf('<button class="btn btn-default%s' + '" type="button" name="advancedSearch" title="%s">', that.options.iconSize === undefined ? '' : ' btn-' + that.options.iconSize, that.options.formatAdvancedSearch()));
  4322. html.push(sprintf('<i class="%s %s"></i>', that.options.iconsPrefix, that.options.icons.advancedSearchIcon))
  4323. html.push('</button></div>');
  4324. that.$toolbar.prepend(html.join(''));
  4325. that.$toolbar.find('button[name="advancedSearch"]')
  4326. .off('click').on('click', function() {
  4327. showAvdSearch(that.columns, that.options.formatAdvancedSearch(), that.options.formatAdvancedCloseButton(), that);
  4328. });
  4329. };
  4330. BootstrapTable.prototype.load = function(data) {
  4331. _load.apply(this, Array.prototype.slice.apply(arguments));
  4332. if (!this.options.advancedSearch) {
  4333. return;
  4334. }
  4335. if (typeof this.options.idTable === 'undefined') {
  4336. return;
  4337. } else {
  4338. if (!firstLoad) {
  4339. var height = parseInt($(".bootstrap-table").height());
  4340. height += 10;
  4341. $("#" + this.options.idTable).bootstrapTable("resetView", {height: height});
  4342. firstLoad = true;
  4343. }
  4344. }
  4345. };
  4346. BootstrapTable.prototype.initSearch = function () {
  4347. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  4348. if (!this.options.advancedSearch) {
  4349. return;
  4350. }
  4351. var that = this;
  4352. var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
  4353. this.data = fp ? $.grep(this.data, function (item, i) {
  4354. for (var key in fp) {
  4355. var fval = fp[key].toLowerCase();
  4356. var value = item[key];
  4357. value = calculateObjectValue(that.header,
  4358. that.header.formatters[$.inArray(key, that.header.fields)],
  4359. [value, item, i], value);
  4360. if (!($.inArray(key, that.header.fields) !== -1 &&
  4361. (typeof value === 'string' || typeof value === 'number') &&
  4362. (value + '').toLowerCase().indexOf(fval) !== -1)) {
  4363. return false;
  4364. }
  4365. }
  4366. return true;
  4367. }) : this.data;
  4368. };
  4369. BootstrapTable.prototype.onColumnAdvancedSearch = function (event) {
  4370. var text = $.trim($(event.currentTarget).val());
  4371. var $field = $(event.currentTarget)[0].id;
  4372. if ($.isEmptyObject(this.filterColumnsPartial)) {
  4373. this.filterColumnsPartial = {};
  4374. }
  4375. if (text) {
  4376. this.filterColumnsPartial[$field] = text;
  4377. } else {
  4378. delete this.filterColumnsPartial[$field];
  4379. }
  4380. this.options.pageNumber = 1;
  4381. this.onSearch(event);
  4382. this.updatePagination();
  4383. this.trigger('column-advanced-search', $field, text);
  4384. };
  4385. }(jQuery);