bootstrap-table.js 184 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('core-js/modules/es.array.concat.js'), require('core-js/modules/es.array.filter.js'), require('core-js/modules/es.array.find.js'), require('core-js/modules/es.array.find-index.js'), require('core-js/modules/es.array.includes.js'), require('core-js/modules/es.array.index-of.js'), require('core-js/modules/es.array.iterator.js'), require('core-js/modules/es.array.join.js'), require('core-js/modules/es.array.map.js'), require('core-js/modules/es.array.reverse.js'), require('core-js/modules/es.array.slice.js'), require('core-js/modules/es.array.sort.js'), require('core-js/modules/es.array.splice.js'), require('core-js/modules/es.date.to-json.js'), require('core-js/modules/es.number.constructor.js'), require('core-js/modules/es.object.assign.js'), require('core-js/modules/es.object.entries.js'), require('core-js/modules/es.object.keys.js'), require('core-js/modules/es.object.to-string.js'), require('core-js/modules/es.parse-float.js'), require('core-js/modules/es.parse-int.js'), require('core-js/modules/es.regexp.constructor.js'), require('core-js/modules/es.regexp.exec.js'), require('core-js/modules/es.regexp.to-string.js'), require('core-js/modules/es.string.includes.js'), require('core-js/modules/es.string.replace.js'), require('core-js/modules/es.string.search.js'), require('core-js/modules/es.string.split.js'), require('core-js/modules/es.string.trim.js'), require('core-js/modules/web.dom-collections.for-each.js'), require('core-js/modules/web.dom-collections.iterator.js'), require('jquery'), require('core-js/modules/es.object.get-prototype-of.js'), require('core-js/modules/es.string.ends-with.js'), require('core-js/modules/es.string.match.js'), require('core-js/modules/es.string.starts-with.js')) :
  3. typeof define === 'function' && define.amd ? define(['core-js/modules/es.array.concat.js', 'core-js/modules/es.array.filter.js', 'core-js/modules/es.array.find.js', 'core-js/modules/es.array.find-index.js', 'core-js/modules/es.array.includes.js', 'core-js/modules/es.array.index-of.js', 'core-js/modules/es.array.iterator.js', 'core-js/modules/es.array.join.js', 'core-js/modules/es.array.map.js', 'core-js/modules/es.array.reverse.js', 'core-js/modules/es.array.slice.js', 'core-js/modules/es.array.sort.js', 'core-js/modules/es.array.splice.js', 'core-js/modules/es.date.to-json.js', 'core-js/modules/es.number.constructor.js', 'core-js/modules/es.object.assign.js', 'core-js/modules/es.object.entries.js', 'core-js/modules/es.object.keys.js', 'core-js/modules/es.object.to-string.js', 'core-js/modules/es.parse-float.js', 'core-js/modules/es.parse-int.js', 'core-js/modules/es.regexp.constructor.js', 'core-js/modules/es.regexp.exec.js', 'core-js/modules/es.regexp.to-string.js', 'core-js/modules/es.string.includes.js', 'core-js/modules/es.string.replace.js', 'core-js/modules/es.string.search.js', 'core-js/modules/es.string.split.js', 'core-js/modules/es.string.trim.js', 'core-js/modules/web.dom-collections.for-each.js', 'core-js/modules/web.dom-collections.iterator.js', 'jquery', 'core-js/modules/es.object.get-prototype-of.js', 'core-js/modules/es.string.ends-with.js', 'core-js/modules/es.string.match.js', 'core-js/modules/es.string.starts-with.js'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.BootstrapTable = factory(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, global.jQuery));
  5. })(this, (function (es_array_concat_js, es_array_filter_js, es_array_find_js, es_array_findIndex_js, es_array_includes_js, es_array_indexOf_js, es_array_iterator_js, es_array_join_js, es_array_map_js, es_array_reverse_js, es_array_slice_js, es_array_sort_js, es_array_splice_js, es_date_toJson_js, es_number_constructor_js, es_object_assign_js, es_object_entries_js, es_object_keys_js, es_object_toString_js, es_parseFloat_js, es_parseInt_js, es_regexp_constructor_js, es_regexp_exec_js, es_regexp_toString_js, es_string_includes_js, es_string_replace_js, es_string_search_js, es_string_split_js, es_string_trim_js, web_domCollections_forEach_js, web_domCollections_iterator_js, $) { 'use strict';
  6. function _arrayLikeToArray(r, a) {
  7. (null == a || a > r.length) && (a = r.length);
  8. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  9. return n;
  10. }
  11. function _arrayWithHoles(r) {
  12. if (Array.isArray(r)) return r;
  13. }
  14. function _arrayWithoutHoles(r) {
  15. if (Array.isArray(r)) return _arrayLikeToArray(r);
  16. }
  17. function _classCallCheck(a, n) {
  18. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  19. }
  20. function _defineProperties(e, r) {
  21. for (var t = 0; t < r.length; t++) {
  22. var o = r[t];
  23. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
  24. }
  25. }
  26. function _createClass(e, r, t) {
  27. return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
  28. writable: !1
  29. }), e;
  30. }
  31. function _createForOfIteratorHelper(r, e) {
  32. var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  33. if (!t) {
  34. if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e ) {
  35. t && (r = t);
  36. var n = 0,
  37. F = function () {};
  38. return {
  39. s: F,
  40. n: function () {
  41. return n >= r.length ? {
  42. done: !0
  43. } : {
  44. done: !1,
  45. value: r[n++]
  46. };
  47. },
  48. e: function (r) {
  49. throw r;
  50. },
  51. f: F
  52. };
  53. }
  54. throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  55. }
  56. var o,
  57. a = !0,
  58. u = !1;
  59. return {
  60. s: function () {
  61. t = t.call(r);
  62. },
  63. n: function () {
  64. var r = t.next();
  65. return a = r.done, r;
  66. },
  67. e: function (r) {
  68. u = !0, o = r;
  69. },
  70. f: function () {
  71. try {
  72. a || null == t.return || t.return();
  73. } finally {
  74. if (u) throw o;
  75. }
  76. }
  77. };
  78. }
  79. function _iterableToArray(r) {
  80. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  81. }
  82. function _iterableToArrayLimit(r, l) {
  83. var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
  84. if (null != t) {
  85. var e,
  86. n,
  87. i,
  88. u,
  89. a = [],
  90. f = !0,
  91. o = !1;
  92. try {
  93. if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
  94. } catch (r) {
  95. o = !0, n = r;
  96. } finally {
  97. try {
  98. if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
  99. } finally {
  100. if (o) throw n;
  101. }
  102. }
  103. return a;
  104. }
  105. }
  106. function _nonIterableRest() {
  107. throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  108. }
  109. function _nonIterableSpread() {
  110. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  111. }
  112. function _slicedToArray(r, e) {
  113. return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
  114. }
  115. function _toConsumableArray(r) {
  116. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  117. }
  118. function _toPrimitive(t, r) {
  119. if ("object" != typeof t || !t) return t;
  120. var e = t[Symbol.toPrimitive];
  121. if (void 0 !== e) {
  122. var i = e.call(t, r );
  123. if ("object" != typeof i) return i;
  124. throw new TypeError("@@toPrimitive must return a primitive value.");
  125. }
  126. return (String )(t);
  127. }
  128. function _toPropertyKey(t) {
  129. var i = _toPrimitive(t, "string");
  130. return "symbol" == typeof i ? i : i + "";
  131. }
  132. function _typeof(o) {
  133. "@babel/helpers - typeof";
  134. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  135. return typeof o;
  136. } : function (o) {
  137. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  138. }, _typeof(o);
  139. }
  140. function _unsupportedIterableToArray(r, a) {
  141. if (r) {
  142. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  143. var t = {}.toString.call(r).slice(8, -1);
  144. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  145. }
  146. }
  147. var Utils = {
  148. getBootstrapVersion: function getBootstrapVersion() {
  149. var bootstrapVersion = 5;
  150. try {
  151. var rawVersion = $.fn.dropdown.Constructor.VERSION;
  152. // Only try to parse VERSION if it is defined.
  153. // It is undefined in older versions of Bootstrap (tested with 3.1.1).
  154. if (rawVersion !== undefined) {
  155. bootstrapVersion = parseInt(rawVersion, 10);
  156. }
  157. } catch (e) {
  158. // ignore
  159. }
  160. try {
  161. // eslint-disable-next-line no-undef
  162. var _rawVersion = bootstrap.Tooltip.VERSION;
  163. if (_rawVersion !== undefined) {
  164. bootstrapVersion = parseInt(_rawVersion, 10);
  165. }
  166. } catch (e) {
  167. // ignore
  168. }
  169. return bootstrapVersion;
  170. },
  171. getIconsPrefix: function getIconsPrefix(theme) {
  172. return {
  173. bootstrap3: 'glyphicon',
  174. bootstrap4: 'fa',
  175. bootstrap5: 'bi',
  176. 'bootstrap-table': 'icon',
  177. bulma: 'fa',
  178. foundation: 'fa',
  179. materialize: 'material-icons',
  180. semantic: 'fa'
  181. }[theme] || 'fa';
  182. },
  183. getIcons: function getIcons(prefix) {
  184. return {
  185. glyphicon: {
  186. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  187. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  188. refresh: 'glyphicon-refresh icon-refresh',
  189. toggleOff: 'glyphicon-list-alt icon-list-alt',
  190. toggleOn: 'glyphicon-list-alt icon-list-alt',
  191. columns: 'glyphicon-th icon-th',
  192. detailOpen: 'glyphicon-plus icon-plus',
  193. detailClose: 'glyphicon-minus icon-minus',
  194. fullscreen: 'glyphicon-fullscreen',
  195. search: 'glyphicon-search',
  196. clearSearch: 'glyphicon-trash'
  197. },
  198. fa: {
  199. paginationSwitchDown: 'fa-caret-square-down',
  200. paginationSwitchUp: 'fa-caret-square-up',
  201. refresh: 'fa-sync',
  202. toggleOff: 'fa-toggle-off',
  203. toggleOn: 'fa-toggle-on',
  204. columns: 'fa-th-list',
  205. detailOpen: 'fa-plus',
  206. detailClose: 'fa-minus',
  207. fullscreen: 'fa-arrows-alt',
  208. search: 'fa-search',
  209. clearSearch: 'fa-trash'
  210. },
  211. bi: {
  212. paginationSwitchDown: 'bi-caret-down-square',
  213. paginationSwitchUp: 'bi-caret-up-square',
  214. refresh: 'bi-arrow-clockwise',
  215. toggleOff: 'bi-toggle-off',
  216. toggleOn: 'bi-toggle-on',
  217. columns: 'bi-list-ul',
  218. detailOpen: 'bi-plus',
  219. detailClose: 'bi-dash',
  220. fullscreen: 'bi-arrows-move',
  221. search: 'bi-search',
  222. clearSearch: 'bi-trash'
  223. },
  224. icon: {
  225. paginationSwitchDown: 'icon-arrow-up-circle',
  226. paginationSwitchUp: 'icon-arrow-down-circle',
  227. refresh: 'icon-refresh-cw',
  228. toggleOff: 'icon-toggle-right',
  229. toggleOn: 'icon-toggle-right',
  230. columns: 'icon-list',
  231. detailOpen: 'icon-plus',
  232. detailClose: 'icon-minus',
  233. fullscreen: 'icon-maximize',
  234. search: 'icon-search',
  235. clearSearch: 'icon-trash-2'
  236. },
  237. 'material-icons': {
  238. paginationSwitchDown: 'grid_on',
  239. paginationSwitchUp: 'grid_off',
  240. refresh: 'refresh',
  241. toggleOff: 'tablet',
  242. toggleOn: 'tablet_android',
  243. columns: 'view_list',
  244. detailOpen: 'add',
  245. detailClose: 'remove',
  246. fullscreen: 'fullscreen',
  247. sort: 'sort',
  248. search: 'search',
  249. clearSearch: 'delete'
  250. }
  251. }[prefix] || {};
  252. },
  253. getSearchInput: function getSearchInput(that) {
  254. if (typeof that.options.searchSelector === 'string') {
  255. return $(that.options.searchSelector);
  256. }
  257. return that.$toolbar.find('.search input');
  258. },
  259. // $.extend: https://github.com/jquery/jquery/blob/3.6.2/src/core.js#L132
  260. extend: function extend() {
  261. var _this = this;
  262. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  263. args[_key] = arguments[_key];
  264. }
  265. var target = args[0] || {};
  266. var i = 1;
  267. var deep = false;
  268. var clone;
  269. // Handle a deep copy situation
  270. if (typeof target === 'boolean') {
  271. deep = target;
  272. // Skip the boolean and the target
  273. target = args[i] || {};
  274. i++;
  275. }
  276. // Handle case when target is a string or something (possible in deep copy)
  277. if (_typeof(target) !== 'object' && typeof target !== 'function') {
  278. target = {};
  279. }
  280. for (; i < args.length; i++) {
  281. var options = args[i];
  282. // Ignore undefined/null values
  283. if (typeof options === 'undefined' || options === null) {
  284. continue;
  285. }
  286. // Extend the base object
  287. // eslint-disable-next-line guard-for-in
  288. for (var name in options) {
  289. var copy = options[name];
  290. // Prevent Object.prototype pollution
  291. // Prevent never-ending loop
  292. if (name === '__proto__' || target === copy) {
  293. continue;
  294. }
  295. var copyIsArray = Array.isArray(copy);
  296. // Recurse if we're merging plain objects or arrays
  297. if (deep && copy && (this.isObject(copy) || copyIsArray)) {
  298. var src = target[name];
  299. if (copyIsArray && Array.isArray(src)) {
  300. if (src.every(function (it) {
  301. return !_this.isObject(it) && !Array.isArray(it);
  302. })) {
  303. target[name] = copy;
  304. continue;
  305. }
  306. }
  307. if (copyIsArray && !Array.isArray(src)) {
  308. clone = [];
  309. } else if (!copyIsArray && !this.isObject(src)) {
  310. clone = {};
  311. } else {
  312. clone = src;
  313. }
  314. // Never move original objects, clone them
  315. target[name] = this.extend(deep, clone, copy);
  316. // Don't bring in undefined values
  317. } else if (copy !== undefined) {
  318. target[name] = copy;
  319. }
  320. }
  321. }
  322. return target;
  323. },
  324. // it only does '%s', and return '' when arguments are undefined
  325. sprintf: function sprintf(_str) {
  326. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
  327. args[_key2 - 1] = arguments[_key2];
  328. }
  329. var flag = true;
  330. var i = 0;
  331. var str = _str.replace(/%s/g, function () {
  332. var arg = args[i++];
  333. if (typeof arg === 'undefined') {
  334. flag = false;
  335. return '';
  336. }
  337. return arg;
  338. });
  339. return flag ? str : '';
  340. },
  341. isObject: function isObject(obj) {
  342. if (_typeof(obj) !== 'object' || obj === null) {
  343. return false;
  344. }
  345. var proto = obj;
  346. while (Object.getPrototypeOf(proto) !== null) {
  347. proto = Object.getPrototypeOf(proto);
  348. }
  349. return Object.getPrototypeOf(obj) === proto;
  350. },
  351. isEmptyObject: function isEmptyObject() {
  352. var obj = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  353. return Object.entries(obj).length === 0 && obj.constructor === Object;
  354. },
  355. isNumeric: function isNumeric(n) {
  356. return !isNaN(parseFloat(n)) && isFinite(n);
  357. },
  358. getFieldTitle: function getFieldTitle(list, value) {
  359. var _iterator = _createForOfIteratorHelper(list),
  360. _step;
  361. try {
  362. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  363. var item = _step.value;
  364. if (item.field === value) {
  365. return item.title;
  366. }
  367. }
  368. } catch (err) {
  369. _iterator.e(err);
  370. } finally {
  371. _iterator.f();
  372. }
  373. return '';
  374. },
  375. setFieldIndex: function setFieldIndex(columns) {
  376. var totalCol = 0;
  377. var flag = [];
  378. var _iterator2 = _createForOfIteratorHelper(columns[0]),
  379. _step2;
  380. try {
  381. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  382. var column = _step2.value;
  383. totalCol += column.colspan || 1;
  384. }
  385. } catch (err) {
  386. _iterator2.e(err);
  387. } finally {
  388. _iterator2.f();
  389. }
  390. for (var i = 0; i < columns.length; i++) {
  391. flag[i] = [];
  392. for (var j = 0; j < totalCol; j++) {
  393. flag[i][j] = false;
  394. }
  395. }
  396. for (var _i = 0; _i < columns.length; _i++) {
  397. var _iterator3 = _createForOfIteratorHelper(columns[_i]),
  398. _step3;
  399. try {
  400. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  401. var r = _step3.value;
  402. var rowspan = r.rowspan || 1;
  403. var colspan = r.colspan || 1;
  404. var index = flag[_i].indexOf(false);
  405. r.colspanIndex = index;
  406. if (colspan === 1) {
  407. r.fieldIndex = index;
  408. // when field is undefined, use index instead
  409. if (typeof r.field === 'undefined') {
  410. r.field = index;
  411. }
  412. } else {
  413. r.colspanGroup = r.colspan;
  414. }
  415. for (var _j = 0; _j < rowspan; _j++) {
  416. for (var k = 0; k < colspan; k++) {
  417. flag[_i + _j][index + k] = true;
  418. }
  419. }
  420. }
  421. } catch (err) {
  422. _iterator3.e(err);
  423. } finally {
  424. _iterator3.f();
  425. }
  426. }
  427. },
  428. normalizeAccent: function normalizeAccent(value) {
  429. if (typeof value !== 'string') {
  430. return value;
  431. }
  432. return value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
  433. },
  434. updateFieldGroup: function updateFieldGroup(columns, fieldColumns) {
  435. var _ref;
  436. var allColumns = (_ref = []).concat.apply(_ref, _toConsumableArray(columns));
  437. var _iterator4 = _createForOfIteratorHelper(columns),
  438. _step4;
  439. try {
  440. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  441. var c = _step4.value;
  442. var _iterator6 = _createForOfIteratorHelper(c),
  443. _step6;
  444. try {
  445. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  446. var r = _step6.value;
  447. if (r.colspanGroup > 1) {
  448. var colspan = 0;
  449. var _loop = function _loop(i) {
  450. var underColumns = allColumns.filter(function (col) {
  451. return col.fieldIndex === i;
  452. });
  453. var column = underColumns[underColumns.length - 1];
  454. if (underColumns.length > 1) {
  455. for (var j = 0; j < underColumns.length - 1; j++) {
  456. underColumns[j].visible = column.visible;
  457. }
  458. }
  459. if (column.visible) {
  460. colspan++;
  461. }
  462. };
  463. for (var i = r.colspanIndex; i < r.colspanIndex + r.colspanGroup; i++) {
  464. _loop(i);
  465. }
  466. r.colspan = colspan;
  467. r.visible = colspan > 0;
  468. }
  469. }
  470. } catch (err) {
  471. _iterator6.e(err);
  472. } finally {
  473. _iterator6.f();
  474. }
  475. }
  476. } catch (err) {
  477. _iterator4.e(err);
  478. } finally {
  479. _iterator4.f();
  480. }
  481. if (columns.length < 2) {
  482. return;
  483. }
  484. var _iterator5 = _createForOfIteratorHelper(fieldColumns),
  485. _step5;
  486. try {
  487. var _loop2 = function _loop2() {
  488. var column = _step5.value;
  489. var sameColumns = allColumns.filter(function (col) {
  490. return col.fieldIndex === column.fieldIndex;
  491. });
  492. if (sameColumns.length > 1) {
  493. var _iterator7 = _createForOfIteratorHelper(sameColumns),
  494. _step7;
  495. try {
  496. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  497. var _c = _step7.value;
  498. _c.visible = column.visible;
  499. }
  500. } catch (err) {
  501. _iterator7.e(err);
  502. } finally {
  503. _iterator7.f();
  504. }
  505. }
  506. };
  507. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  508. _loop2();
  509. }
  510. } catch (err) {
  511. _iterator5.e(err);
  512. } finally {
  513. _iterator5.f();
  514. }
  515. },
  516. getScrollBarWidth: function getScrollBarWidth() {
  517. if (this.cachedWidth === undefined) {
  518. var $inner = $('<div/>').addClass('fixed-table-scroll-inner');
  519. var $outer = $('<div/>').addClass('fixed-table-scroll-outer');
  520. $outer.append($inner);
  521. $('body').append($outer);
  522. var w1 = $inner[0].offsetWidth;
  523. $outer.css('overflow', 'scroll');
  524. var w2 = $inner[0].offsetWidth;
  525. if (w1 === w2) {
  526. w2 = $outer[0].clientWidth;
  527. }
  528. $outer.remove();
  529. this.cachedWidth = w1 - w2;
  530. }
  531. return this.cachedWidth;
  532. },
  533. calculateObjectValue: function calculateObjectValue(self, name, args, defaultValue) {
  534. var func = name;
  535. if (typeof name === 'string') {
  536. // support obj.func1.func2
  537. var names = name.split('.');
  538. if (names.length > 1) {
  539. func = window;
  540. var _iterator8 = _createForOfIteratorHelper(names),
  541. _step8;
  542. try {
  543. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  544. var f = _step8.value;
  545. func = func[f];
  546. }
  547. } catch (err) {
  548. _iterator8.e(err);
  549. } finally {
  550. _iterator8.f();
  551. }
  552. } else {
  553. func = window[name];
  554. }
  555. }
  556. if (func !== null && _typeof(func) === 'object') {
  557. return func;
  558. }
  559. if (typeof func === 'function') {
  560. return func.apply(self, args || []);
  561. }
  562. if (!func && typeof name === 'string' && args && this.sprintf.apply(this, [name].concat(_toConsumableArray(args)))) {
  563. return this.sprintf.apply(this, [name].concat(_toConsumableArray(args)));
  564. }
  565. return defaultValue;
  566. },
  567. compareObjects: function compareObjects(objectA, objectB, compareLength) {
  568. var aKeys = Object.keys(objectA);
  569. var bKeys = Object.keys(objectB);
  570. if (compareLength && aKeys.length !== bKeys.length) {
  571. return false;
  572. }
  573. for (var _i2 = 0, _aKeys = aKeys; _i2 < _aKeys.length; _i2++) {
  574. var key = _aKeys[_i2];
  575. if (bKeys.includes(key) && objectA[key] !== objectB[key]) {
  576. return false;
  577. }
  578. }
  579. return true;
  580. },
  581. regexCompare: function regexCompare(value, search) {
  582. try {
  583. var regexpParts = search.match(/^\/(.*?)\/([gim]*)$/);
  584. if (value.toString().search(regexpParts ? new RegExp(regexpParts[1], regexpParts[2]) : new RegExp(search, 'gim')) !== -1) {
  585. return true;
  586. }
  587. } catch (e) {
  588. return false;
  589. }
  590. return false;
  591. },
  592. escapeApostrophe: function escapeApostrophe(value) {
  593. return value.toString().replace(/'/g, '&#39;');
  594. },
  595. escapeHTML: function escapeHTML(text) {
  596. if (!text) {
  597. return text;
  598. }
  599. return text.toString().replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
  600. },
  601. unescapeHTML: function unescapeHTML(text) {
  602. if (typeof text !== 'string' || !text) {
  603. return text;
  604. }
  605. return text.toString().replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, '\'');
  606. },
  607. removeHTML: function removeHTML(text) {
  608. if (!text) {
  609. return text;
  610. }
  611. return text.toString().replace(/(<([^>]+)>)/ig, '').replace(/&[#A-Za-z0-9]+;/gi, '').trim();
  612. },
  613. getRealDataAttr: function getRealDataAttr(dataAttr) {
  614. for (var _i3 = 0, _Object$entries = Object.entries(dataAttr); _i3 < _Object$entries.length; _i3++) {
  615. var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
  616. attr = _Object$entries$_i[0],
  617. value = _Object$entries$_i[1];
  618. var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
  619. if (auxAttr !== attr) {
  620. dataAttr[auxAttr] = value;
  621. delete dataAttr[attr];
  622. }
  623. }
  624. return dataAttr;
  625. },
  626. getItemField: function getItemField(item, field, escape) {
  627. var columnEscape = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
  628. var value = item;
  629. // use column escape if it is defined
  630. if (typeof columnEscape !== 'undefined') {
  631. escape = columnEscape;
  632. }
  633. if (typeof field !== 'string' || item.hasOwnProperty(field)) {
  634. return escape ? this.escapeHTML(item[field]) : item[field];
  635. }
  636. var props = field.split('.');
  637. var _iterator9 = _createForOfIteratorHelper(props),
  638. _step9;
  639. try {
  640. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  641. var p = _step9.value;
  642. value = value && value[p];
  643. }
  644. } catch (err) {
  645. _iterator9.e(err);
  646. } finally {
  647. _iterator9.f();
  648. }
  649. return escape ? this.escapeHTML(value) : value;
  650. },
  651. isIEBrowser: function isIEBrowser() {
  652. return navigator.userAgent.includes('MSIE ') || /Trident.*rv:11\./.test(navigator.userAgent);
  653. },
  654. findIndex: function findIndex(items, item) {
  655. var _iterator10 = _createForOfIteratorHelper(items),
  656. _step10;
  657. try {
  658. for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
  659. var it = _step10.value;
  660. if (JSON.stringify(it) === JSON.stringify(item)) {
  661. return items.indexOf(it);
  662. }
  663. }
  664. } catch (err) {
  665. _iterator10.e(err);
  666. } finally {
  667. _iterator10.f();
  668. }
  669. return -1;
  670. },
  671. trToData: function trToData(columns, $els) {
  672. var _this2 = this;
  673. var data = [];
  674. var m = [];
  675. $els.each(function (y, el) {
  676. var $el = $(el);
  677. var row = {};
  678. // save tr's id, class and data-* attributes
  679. row._id = $el.attr('id');
  680. row._class = $el.attr('class');
  681. row._data = _this2.getRealDataAttr($el.data());
  682. row._style = $el.attr('style');
  683. $el.find('>td,>th').each(function (_x, el) {
  684. var $el = $(el);
  685. var colspan = +$el.attr('colspan') || 1;
  686. var rowspan = +$el.attr('rowspan') || 1;
  687. var x = _x;
  688. // skip already occupied cells in current row
  689. for (; m[y] && m[y][x]; x++) {
  690. // ignore
  691. }
  692. // mark matrix elements occupied by current cell with true
  693. for (var tx = x; tx < x + colspan; tx++) {
  694. for (var ty = y; ty < y + rowspan; ty++) {
  695. if (!m[ty]) {
  696. // fill missing rows
  697. m[ty] = [];
  698. }
  699. m[ty][tx] = true;
  700. }
  701. }
  702. var field = columns[x].field;
  703. row[field] = _this2.escapeApostrophe($el.html().trim());
  704. // save td's id, class and data-* attributes
  705. row["_".concat(field, "_id")] = $el.attr('id');
  706. row["_".concat(field, "_class")] = $el.attr('class');
  707. row["_".concat(field, "_rowspan")] = $el.attr('rowspan');
  708. row["_".concat(field, "_colspan")] = $el.attr('colspan');
  709. row["_".concat(field, "_title")] = $el.attr('title');
  710. row["_".concat(field, "_data")] = _this2.getRealDataAttr($el.data());
  711. row["_".concat(field, "_style")] = $el.attr('style');
  712. });
  713. data.push(row);
  714. });
  715. return data;
  716. },
  717. sort: function sort(a, b, order, options, aPosition, bPosition) {
  718. if (a === undefined || a === null) {
  719. a = '';
  720. }
  721. if (b === undefined || b === null) {
  722. b = '';
  723. }
  724. if (options.sortStable && a === b) {
  725. a = aPosition;
  726. b = bPosition;
  727. }
  728. // If both values are numeric, do a numeric comparison
  729. if (this.isNumeric(a) && this.isNumeric(b)) {
  730. // Convert numerical values form string to float.
  731. a = parseFloat(a);
  732. b = parseFloat(b);
  733. if (a < b) {
  734. return order * -1;
  735. }
  736. if (a > b) {
  737. return order;
  738. }
  739. return 0;
  740. }
  741. if (options.sortEmptyLast) {
  742. if (a === '') {
  743. return 1;
  744. }
  745. if (b === '') {
  746. return -1;
  747. }
  748. }
  749. if (a === b) {
  750. return 0;
  751. }
  752. // If value is not a string, convert to string
  753. if (typeof a !== 'string') {
  754. a = a.toString();
  755. }
  756. if (a.localeCompare(b) === -1) {
  757. return order * -1;
  758. }
  759. return order;
  760. },
  761. getEventName: function getEventName(eventPrefix) {
  762. var id = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  763. id = id || "".concat(+new Date()).concat(~~(Math.random() * 1000000));
  764. return "".concat(eventPrefix, "-").concat(id);
  765. },
  766. hasDetailViewIcon: function hasDetailViewIcon(options) {
  767. return options.detailView && options.detailViewIcon && !options.cardView;
  768. },
  769. getDetailViewIndexOffset: function getDetailViewIndexOffset(options) {
  770. return this.hasDetailViewIcon(options) && options.detailViewAlign !== 'right' ? 1 : 0;
  771. },
  772. checkAutoMergeCells: function checkAutoMergeCells(data) {
  773. var _iterator11 = _createForOfIteratorHelper(data),
  774. _step11;
  775. try {
  776. for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
  777. var row = _step11.value;
  778. for (var _i4 = 0, _Object$keys = Object.keys(row); _i4 < _Object$keys.length; _i4++) {
  779. var key = _Object$keys[_i4];
  780. if (key.startsWith('_') && (key.endsWith('_rowspan') || key.endsWith('_colspan'))) {
  781. return true;
  782. }
  783. }
  784. }
  785. } catch (err) {
  786. _iterator11.e(err);
  787. } finally {
  788. _iterator11.f();
  789. }
  790. return false;
  791. },
  792. deepCopy: function deepCopy(arg) {
  793. if (arg === undefined) {
  794. return arg;
  795. }
  796. return this.extend(true, Array.isArray(arg) ? [] : {}, arg);
  797. },
  798. debounce: function debounce(func, wait, immediate) {
  799. var timeout;
  800. return function executedFunction() {
  801. var context = this;
  802. var args = arguments;
  803. var later = function later() {
  804. timeout = null;
  805. if (!immediate) func.apply(context, args);
  806. };
  807. var callNow = immediate && !timeout;
  808. clearTimeout(timeout);
  809. timeout = setTimeout(later, wait);
  810. if (callNow) func.apply(context, args);
  811. };
  812. }
  813. };
  814. var VERSION = '1.23.1';
  815. var bootstrapVersion = Utils.getBootstrapVersion();
  816. var CONSTANTS = {
  817. 3: {
  818. classes: {
  819. buttonsPrefix: 'btn',
  820. buttons: 'default',
  821. buttonsGroup: 'btn-group',
  822. buttonsDropdown: 'btn-group',
  823. pull: 'pull',
  824. inputGroup: 'input-group',
  825. inputPrefix: 'input-',
  826. input: 'form-control',
  827. select: 'form-control',
  828. paginationDropdown: 'btn-group dropdown',
  829. dropup: 'dropup',
  830. dropdownActive: 'active',
  831. paginationActive: 'active',
  832. buttonActive: 'active'
  833. },
  834. html: {
  835. toolbarDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  836. toolbarDropdownItem: '<li class="dropdown-item-marker" role="menuitem"><label>%s</label></li>',
  837. toolbarDropdownSeparator: '<li class="divider"></li>',
  838. pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  839. pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>',
  840. dropdownCaret: '<span class="caret"></span>',
  841. pagination: ['<ul class="pagination%s">', '</ul>'],
  842. paginationItem: '<li class="page-item%s"><a class="page-link" aria-label="%s" href="javascript:void(0)">%s</a></li>',
  843. icon: '<i class="%s %s"></i>',
  844. inputGroup: '<div class="input-group">%s<span class="input-group-btn">%s</span></div>',
  845. searchInput: '<input class="%s%s" type="text" placeholder="%s">',
  846. searchButton: '<button class="%s" type="button" name="search" title="%s">%s %s</button>',
  847. searchClearButton: '<button class="%s" type="button" name="clearSearch" title="%s">%s %s</button>'
  848. }
  849. },
  850. 4: {
  851. classes: {
  852. buttonsPrefix: 'btn',
  853. buttons: 'secondary',
  854. buttonsGroup: 'btn-group',
  855. buttonsDropdown: 'btn-group',
  856. pull: 'float',
  857. inputGroup: 'btn-group',
  858. inputPrefix: 'form-control-',
  859. input: 'form-control',
  860. select: 'form-control',
  861. paginationDropdown: 'btn-group dropdown',
  862. dropup: 'dropup',
  863. dropdownActive: 'active',
  864. paginationActive: 'active',
  865. buttonActive: 'active'
  866. },
  867. html: {
  868. toolbarDropdown: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'],
  869. toolbarDropdownItem: '<label class="dropdown-item dropdown-item-marker">%s</label>',
  870. pageDropdown: ['<div class="dropdown-menu">', '</div>'],
  871. pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>',
  872. toolbarDropdownSeparator: '<div class="dropdown-divider"></div>',
  873. dropdownCaret: '<span class="caret"></span>',
  874. pagination: ['<ul class="pagination%s">', '</ul>'],
  875. paginationItem: '<li class="page-item%s"><a class="page-link" aria-label="%s" href="javascript:void(0)">%s</a></li>',
  876. icon: '<i class="%s %s"></i>',
  877. inputGroup: '<div class="input-group">%s<div class="input-group-append">%s</div></div>',
  878. searchInput: '<input class="%s%s" type="text" placeholder="%s">',
  879. searchButton: '<button class="%s" type="button" name="search" title="%s">%s %s</button>',
  880. searchClearButton: '<button class="%s" type="button" name="clearSearch" title="%s">%s %s</button>'
  881. }
  882. },
  883. 5: {
  884. classes: {
  885. buttonsPrefix: 'btn',
  886. buttons: 'secondary',
  887. buttonsGroup: 'btn-group',
  888. buttonsDropdown: 'btn-group',
  889. pull: 'float',
  890. inputGroup: 'btn-group',
  891. inputPrefix: 'form-control-',
  892. input: 'form-control',
  893. select: 'form-select',
  894. paginationDropdown: 'btn-group dropdown',
  895. dropup: 'dropup',
  896. dropdownActive: 'active',
  897. paginationActive: 'active',
  898. buttonActive: 'active'
  899. },
  900. html: {
  901. dataToggle: 'data-bs-toggle',
  902. toolbarDropdown: ['<div class="dropdown-menu dropdown-menu-end">', '</div>'],
  903. toolbarDropdownItem: '<label class="dropdown-item dropdown-item-marker">%s</label>',
  904. pageDropdown: ['<div class="dropdown-menu">', '</div>'],
  905. pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>',
  906. toolbarDropdownSeparator: '<div class="dropdown-divider"></div>',
  907. dropdownCaret: '<span class="caret"></span>',
  908. pagination: ['<ul class="pagination%s">', '</ul>'],
  909. paginationItem: '<li class="page-item%s"><a class="page-link" aria-label="%s" href="javascript:void(0)">%s</a></li>',
  910. icon: '<i class="%s %s"></i>',
  911. inputGroup: '<div class="input-group">%s%s</div>',
  912. searchInput: '<input class="%s%s" type="text" placeholder="%s">',
  913. searchButton: '<button class="%s" type="button" name="search" title="%s">%s %s</button>',
  914. searchClearButton: '<button class="%s" type="button" name="clearSearch" title="%s">%s %s</button>'
  915. }
  916. }
  917. }[bootstrapVersion];
  918. var DEFAULTS = {
  919. height: undefined,
  920. classes: 'table table-bordered table-hover',
  921. buttons: {},
  922. theadClasses: '',
  923. headerStyle: function headerStyle(column) {
  924. return {};
  925. },
  926. rowStyle: function rowStyle(row, index) {
  927. return {};
  928. },
  929. rowAttributes: function rowAttributes(row, index) {
  930. return {};
  931. },
  932. undefinedText: '-',
  933. locale: undefined,
  934. virtualScroll: false,
  935. virtualScrollItemHeight: undefined,
  936. sortable: true,
  937. sortClass: undefined,
  938. silentSort: true,
  939. sortEmptyLast: false,
  940. sortName: undefined,
  941. sortOrder: undefined,
  942. sortReset: false,
  943. sortStable: false,
  944. sortResetPage: false,
  945. rememberOrder: false,
  946. serverSort: true,
  947. customSort: undefined,
  948. columns: [[]],
  949. data: [],
  950. url: undefined,
  951. method: 'get',
  952. cache: true,
  953. contentType: 'application/json',
  954. dataType: 'json',
  955. ajax: undefined,
  956. ajaxOptions: {},
  957. queryParams: function queryParams(params) {
  958. return params;
  959. },
  960. queryParamsType: 'limit',
  961. // 'limit', undefined
  962. responseHandler: function responseHandler(res) {
  963. return res;
  964. },
  965. totalField: 'total',
  966. totalNotFilteredField: 'totalNotFiltered',
  967. dataField: 'rows',
  968. footerField: 'footer',
  969. pagination: false,
  970. paginationParts: ['pageInfo', 'pageSize', 'pageList'],
  971. showExtendedPagination: false,
  972. paginationLoop: true,
  973. sidePagination: 'client',
  974. // client or server
  975. totalRows: 0,
  976. totalNotFiltered: 0,
  977. pageNumber: 1,
  978. pageSize: 10,
  979. pageList: [10, 25, 50, 100],
  980. paginationHAlign: 'right',
  981. // right, left
  982. paginationVAlign: 'bottom',
  983. // bottom, top, both
  984. paginationDetailHAlign: 'left',
  985. // right, left
  986. paginationPreText: '&lsaquo;',
  987. paginationNextText: '&rsaquo;',
  988. paginationSuccessivelySize: 5,
  989. // Maximum successively number of pages in a row
  990. paginationPagesBySide: 1,
  991. // Number of pages on each side (right, left) of the current page.
  992. paginationUseIntermediate: false,
  993. // Calculate intermediate pages for quick access
  994. paginationLoadMore: false,
  995. search: false,
  996. searchable: false,
  997. searchHighlight: false,
  998. searchOnEnterKey: false,
  999. strictSearch: false,
  1000. regexSearch: false,
  1001. searchSelector: false,
  1002. visibleSearch: false,
  1003. showButtonIcons: true,
  1004. showButtonText: false,
  1005. showSearchButton: false,
  1006. showSearchClearButton: false,
  1007. trimOnSearch: true,
  1008. searchAlign: 'right',
  1009. searchTimeOut: 500,
  1010. searchText: '',
  1011. customSearch: undefined,
  1012. showHeader: true,
  1013. showFooter: false,
  1014. footerStyle: function footerStyle(column) {
  1015. return {};
  1016. },
  1017. searchAccentNeutralise: false,
  1018. showColumns: false,
  1019. showColumnsToggleAll: false,
  1020. showColumnsSearch: false,
  1021. minimumCountColumns: 1,
  1022. showPaginationSwitch: false,
  1023. showRefresh: false,
  1024. showToggle: false,
  1025. showFullscreen: false,
  1026. smartDisplay: true,
  1027. escape: false,
  1028. escapeTitle: true,
  1029. filterOptions: {
  1030. filterAlgorithm: 'and'
  1031. },
  1032. idField: undefined,
  1033. selectItemName: 'btSelectItem',
  1034. clickToSelect: false,
  1035. ignoreClickToSelectOn: function ignoreClickToSelectOn(_ref) {
  1036. var tagName = _ref.tagName;
  1037. return ['A', 'BUTTON'].includes(tagName);
  1038. },
  1039. singleSelect: false,
  1040. checkboxHeader: true,
  1041. maintainMetaData: false,
  1042. multipleSelectRow: false,
  1043. uniqueId: undefined,
  1044. cardView: false,
  1045. detailView: false,
  1046. detailViewIcon: true,
  1047. detailViewByClick: false,
  1048. detailViewAlign: 'left',
  1049. detailFormatter: function detailFormatter(index, row) {
  1050. return '';
  1051. },
  1052. detailFilter: function detailFilter(index, row) {
  1053. return true;
  1054. },
  1055. toolbar: undefined,
  1056. toolbarAlign: 'left',
  1057. buttonsToolbar: undefined,
  1058. buttonsAlign: 'right',
  1059. buttonsOrder: ['paginationSwitch', 'refresh', 'toggle', 'fullscreen', 'columns'],
  1060. buttonsPrefix: CONSTANTS.classes.buttonsPrefix,
  1061. buttonsClass: CONSTANTS.classes.buttons,
  1062. iconsPrefix: undefined,
  1063. // init in initConstants
  1064. icons: {},
  1065. // init in initConstants
  1066. iconSize: undefined,
  1067. fixedScroll: false,
  1068. loadingFontSize: 'auto',
  1069. loadingTemplate: function loadingTemplate(loadingMessage) {
  1070. return "<span class=\"loading-wrap\">\n <span class=\"loading-text\">".concat(loadingMessage, "</span>\n <span class=\"animation-wrap\"><span class=\"animation-dot\"></span></span>\n </span>\n ");
  1071. },
  1072. onAll: function onAll(name, args) {
  1073. return false;
  1074. },
  1075. onClickCell: function onClickCell(field, value, row, $element) {
  1076. return false;
  1077. },
  1078. onDblClickCell: function onDblClickCell(field, value, row, $element) {
  1079. return false;
  1080. },
  1081. onClickRow: function onClickRow(item, $element) {
  1082. return false;
  1083. },
  1084. onDblClickRow: function onDblClickRow(item, $element) {
  1085. return false;
  1086. },
  1087. onSort: function onSort(name, order) {
  1088. return false;
  1089. },
  1090. onCheck: function onCheck(row) {
  1091. return false;
  1092. },
  1093. onUncheck: function onUncheck(row) {
  1094. return false;
  1095. },
  1096. onCheckAll: function onCheckAll(rows) {
  1097. return false;
  1098. },
  1099. onUncheckAll: function onUncheckAll(rows) {
  1100. return false;
  1101. },
  1102. onCheckSome: function onCheckSome(rows) {
  1103. return false;
  1104. },
  1105. onUncheckSome: function onUncheckSome(rows) {
  1106. return false;
  1107. },
  1108. onLoadSuccess: function onLoadSuccess(data) {
  1109. return false;
  1110. },
  1111. onLoadError: function onLoadError(status) {
  1112. return false;
  1113. },
  1114. onColumnSwitch: function onColumnSwitch(field, checked) {
  1115. return false;
  1116. },
  1117. onColumnSwitchAll: function onColumnSwitchAll(checked) {
  1118. return false;
  1119. },
  1120. onPageChange: function onPageChange(number, size) {
  1121. return false;
  1122. },
  1123. onSearch: function onSearch(text) {
  1124. return false;
  1125. },
  1126. onToggle: function onToggle(cardView) {
  1127. return false;
  1128. },
  1129. onPreBody: function onPreBody(data) {
  1130. return false;
  1131. },
  1132. onPostBody: function onPostBody() {
  1133. return false;
  1134. },
  1135. onPostHeader: function onPostHeader() {
  1136. return false;
  1137. },
  1138. onPostFooter: function onPostFooter() {
  1139. return false;
  1140. },
  1141. onExpandRow: function onExpandRow(index, row, $detail) {
  1142. return false;
  1143. },
  1144. onCollapseRow: function onCollapseRow(index, row) {
  1145. return false;
  1146. },
  1147. onRefreshOptions: function onRefreshOptions(options) {
  1148. return false;
  1149. },
  1150. onRefresh: function onRefresh(params) {
  1151. return false;
  1152. },
  1153. onResetView: function onResetView() {
  1154. return false;
  1155. },
  1156. onScrollBody: function onScrollBody() {
  1157. return false;
  1158. },
  1159. onTogglePagination: function onTogglePagination(newState) {
  1160. return false;
  1161. },
  1162. onVirtualScroll: function onVirtualScroll(startIndex, endIndex) {
  1163. return false;
  1164. }
  1165. };
  1166. var EN = {
  1167. formatLoadingMessage: function formatLoadingMessage() {
  1168. return 'Loading, please wait';
  1169. },
  1170. formatRecordsPerPage: function formatRecordsPerPage(pageNumber) {
  1171. return "".concat(pageNumber, " rows per page");
  1172. },
  1173. formatShowingRows: function formatShowingRows(pageFrom, pageTo, totalRows, totalNotFiltered) {
  1174. if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered > totalRows) {
  1175. return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows (filtered from ").concat(totalNotFiltered, " total rows)");
  1176. }
  1177. return "Showing ".concat(pageFrom, " to ").concat(pageTo, " of ").concat(totalRows, " rows");
  1178. },
  1179. formatSRPaginationPreText: function formatSRPaginationPreText() {
  1180. return 'previous page';
  1181. },
  1182. formatSRPaginationPageText: function formatSRPaginationPageText(page) {
  1183. return "to page ".concat(page);
  1184. },
  1185. formatSRPaginationNextText: function formatSRPaginationNextText() {
  1186. return 'next page';
  1187. },
  1188. formatDetailPagination: function formatDetailPagination(totalRows) {
  1189. return "Showing ".concat(totalRows, " rows");
  1190. },
  1191. formatSearch: function formatSearch() {
  1192. return 'Search';
  1193. },
  1194. formatClearSearch: function formatClearSearch() {
  1195. return 'Clear Search';
  1196. },
  1197. formatNoMatches: function formatNoMatches() {
  1198. return 'No matching records found';
  1199. },
  1200. formatPaginationSwitch: function formatPaginationSwitch() {
  1201. return 'Hide/Show pagination';
  1202. },
  1203. formatPaginationSwitchDown: function formatPaginationSwitchDown() {
  1204. return 'Show pagination';
  1205. },
  1206. formatPaginationSwitchUp: function formatPaginationSwitchUp() {
  1207. return 'Hide pagination';
  1208. },
  1209. formatRefresh: function formatRefresh() {
  1210. return 'Refresh';
  1211. },
  1212. formatToggleOn: function formatToggleOn() {
  1213. return 'Show card view';
  1214. },
  1215. formatToggleOff: function formatToggleOff() {
  1216. return 'Hide card view';
  1217. },
  1218. formatColumns: function formatColumns() {
  1219. return 'Columns';
  1220. },
  1221. formatColumnsToggleAll: function formatColumnsToggleAll() {
  1222. return 'Toggle all';
  1223. },
  1224. formatFullscreen: function formatFullscreen() {
  1225. return 'Fullscreen';
  1226. },
  1227. formatAllRows: function formatAllRows() {
  1228. return 'All';
  1229. }
  1230. };
  1231. var COLUMN_DEFAULTS = {
  1232. field: undefined,
  1233. title: undefined,
  1234. titleTooltip: undefined,
  1235. class: undefined,
  1236. width: undefined,
  1237. widthUnit: 'px',
  1238. rowspan: undefined,
  1239. colspan: undefined,
  1240. align: undefined,
  1241. // left, right, center
  1242. halign: undefined,
  1243. // left, right, center
  1244. falign: undefined,
  1245. // left, right, center
  1246. valign: undefined,
  1247. // top, middle, bottom
  1248. cellStyle: undefined,
  1249. radio: false,
  1250. checkbox: false,
  1251. checkboxEnabled: true,
  1252. clickToSelect: true,
  1253. showSelectTitle: false,
  1254. sortable: false,
  1255. sortName: undefined,
  1256. order: 'asc',
  1257. // asc, desc
  1258. sorter: undefined,
  1259. visible: true,
  1260. switchable: true,
  1261. switchableLabel: undefined,
  1262. cardVisible: true,
  1263. searchable: true,
  1264. formatter: undefined,
  1265. footerFormatter: undefined,
  1266. footerStyle: undefined,
  1267. detailFormatter: undefined,
  1268. searchFormatter: true,
  1269. searchHighlightFormatter: false,
  1270. escape: undefined,
  1271. events: undefined
  1272. };
  1273. var METHODS = ['getOptions', 'refreshOptions', 'getData', 'getSelections', 'load', 'append', 'prepend', 'remove', 'removeAll', 'insertRow', 'updateRow', 'getRowByUniqueId', 'updateByUniqueId', 'removeByUniqueId', 'updateCell', 'updateCellByUniqueId', 'showRow', 'hideRow', 'getHiddenRows', 'showColumn', 'hideColumn', 'getVisibleColumns', 'getHiddenColumns', 'showAllColumns', 'hideAllColumns', 'mergeCells', 'checkAll', 'uncheckAll', 'checkInvert', 'check', 'uncheck', 'checkBy', 'uncheckBy', 'refresh', 'destroy', 'resetView', 'showLoading', 'hideLoading', 'togglePagination', 'toggleFullscreen', 'toggleView', 'resetSearch', 'filterBy', 'sortBy', 'scrollTo', 'getScrollPosition', 'selectPage', 'prevPage', 'nextPage', 'toggleDetailView', 'expandRow', 'collapseRow', 'expandRowByUniqueId', 'collapseRowByUniqueId', 'expandAllRows', 'collapseAllRows', 'updateColumnTitle', 'updateFormatText'];
  1274. var EVENTS = {
  1275. 'all.bs.table': 'onAll',
  1276. 'click-row.bs.table': 'onClickRow',
  1277. 'dbl-click-row.bs.table': 'onDblClickRow',
  1278. 'click-cell.bs.table': 'onClickCell',
  1279. 'dbl-click-cell.bs.table': 'onDblClickCell',
  1280. 'sort.bs.table': 'onSort',
  1281. 'check.bs.table': 'onCheck',
  1282. 'uncheck.bs.table': 'onUncheck',
  1283. 'check-all.bs.table': 'onCheckAll',
  1284. 'uncheck-all.bs.table': 'onUncheckAll',
  1285. 'check-some.bs.table': 'onCheckSome',
  1286. 'uncheck-some.bs.table': 'onUncheckSome',
  1287. 'load-success.bs.table': 'onLoadSuccess',
  1288. 'load-error.bs.table': 'onLoadError',
  1289. 'column-switch.bs.table': 'onColumnSwitch',
  1290. 'column-switch-all.bs.table': 'onColumnSwitchAll',
  1291. 'page-change.bs.table': 'onPageChange',
  1292. 'search.bs.table': 'onSearch',
  1293. 'toggle.bs.table': 'onToggle',
  1294. 'pre-body.bs.table': 'onPreBody',
  1295. 'post-body.bs.table': 'onPostBody',
  1296. 'post-header.bs.table': 'onPostHeader',
  1297. 'post-footer.bs.table': 'onPostFooter',
  1298. 'expand-row.bs.table': 'onExpandRow',
  1299. 'collapse-row.bs.table': 'onCollapseRow',
  1300. 'refresh-options.bs.table': 'onRefreshOptions',
  1301. 'reset-view.bs.table': 'onResetView',
  1302. 'refresh.bs.table': 'onRefresh',
  1303. 'scroll-body.bs.table': 'onScrollBody',
  1304. 'toggle-pagination.bs.table': 'onTogglePagination',
  1305. 'virtual-scroll.bs.table': 'onVirtualScroll'
  1306. };
  1307. Object.assign(DEFAULTS, EN);
  1308. var Constants = {
  1309. VERSION: VERSION,
  1310. THEME: "bootstrap".concat(bootstrapVersion),
  1311. CONSTANTS: CONSTANTS,
  1312. DEFAULTS: DEFAULTS,
  1313. COLUMN_DEFAULTS: COLUMN_DEFAULTS,
  1314. METHODS: METHODS,
  1315. EVENTS: EVENTS,
  1316. LOCALES: {
  1317. en: EN,
  1318. 'en-US': EN
  1319. }
  1320. };
  1321. var BLOCK_ROWS = 50;
  1322. var CLUSTER_BLOCKS = 4;
  1323. var VirtualScroll = /*#__PURE__*/function () {
  1324. function VirtualScroll(options) {
  1325. var _this = this;
  1326. _classCallCheck(this, VirtualScroll);
  1327. this.rows = options.rows;
  1328. this.scrollEl = options.scrollEl;
  1329. this.contentEl = options.contentEl;
  1330. this.callback = options.callback;
  1331. this.itemHeight = options.itemHeight;
  1332. this.cache = {};
  1333. this.scrollTop = this.scrollEl.scrollTop;
  1334. this.initDOM(this.rows, options.fixedScroll);
  1335. this.scrollEl.scrollTop = this.scrollTop;
  1336. this.lastCluster = 0;
  1337. var onScroll = function onScroll() {
  1338. if (_this.lastCluster !== (_this.lastCluster = _this.getNum())) {
  1339. _this.initDOM(_this.rows);
  1340. _this.callback(_this.startIndex, _this.endIndex);
  1341. }
  1342. };
  1343. this.scrollEl.addEventListener('scroll', onScroll, false);
  1344. this.destroy = function () {
  1345. _this.contentEl.innerHtml = '';
  1346. _this.scrollEl.removeEventListener('scroll', onScroll, false);
  1347. };
  1348. }
  1349. return _createClass(VirtualScroll, [{
  1350. key: "initDOM",
  1351. value: function initDOM(rows, fixedScroll) {
  1352. if (typeof this.clusterHeight === 'undefined') {
  1353. this.cache.scrollTop = this.scrollEl.scrollTop;
  1354. this.cache.data = this.contentEl.innerHTML = rows[0] + rows[0] + rows[0];
  1355. this.getRowsHeight(rows);
  1356. } else if (this.blockHeight === 0) {
  1357. this.getRowsHeight(rows);
  1358. }
  1359. var data = this.initData(rows, this.getNum(fixedScroll));
  1360. var thisRows = data.rows.join('');
  1361. var dataChanged = this.checkChanges('data', thisRows);
  1362. var topOffsetChanged = this.checkChanges('top', data.topOffset);
  1363. var bottomOffsetChanged = this.checkChanges('bottom', data.bottomOffset);
  1364. var html = [];
  1365. if (dataChanged && topOffsetChanged) {
  1366. if (data.topOffset) {
  1367. html.push(this.getExtra('top', data.topOffset));
  1368. }
  1369. html.push(thisRows);
  1370. if (data.bottomOffset) {
  1371. html.push(this.getExtra('bottom', data.bottomOffset));
  1372. }
  1373. this.startIndex = data.start;
  1374. this.endIndex = data.end;
  1375. this.contentEl.innerHTML = html.join('');
  1376. if (fixedScroll) {
  1377. this.contentEl.scrollTop = this.cache.scrollTop;
  1378. }
  1379. } else if (bottomOffsetChanged) {
  1380. this.contentEl.lastChild.style.height = "".concat(data.bottomOffset, "px");
  1381. }
  1382. }
  1383. }, {
  1384. key: "getRowsHeight",
  1385. value: function getRowsHeight() {
  1386. if (typeof this.itemHeight === 'undefined' || this.itemHeight === 0) {
  1387. var nodes = this.contentEl.children;
  1388. var node = nodes[Math.floor(nodes.length / 2)];
  1389. this.itemHeight = node.offsetHeight;
  1390. }
  1391. this.blockHeight = this.itemHeight * BLOCK_ROWS;
  1392. this.clusterRows = BLOCK_ROWS * CLUSTER_BLOCKS;
  1393. this.clusterHeight = this.blockHeight * CLUSTER_BLOCKS;
  1394. }
  1395. }, {
  1396. key: "getNum",
  1397. value: function getNum(fixedScroll) {
  1398. this.scrollTop = fixedScroll ? this.cache.scrollTop : this.scrollEl.scrollTop;
  1399. return Math.floor(this.scrollTop / (this.clusterHeight - this.blockHeight)) || 0;
  1400. }
  1401. }, {
  1402. key: "initData",
  1403. value: function initData(rows, num) {
  1404. if (rows.length < BLOCK_ROWS) {
  1405. return {
  1406. topOffset: 0,
  1407. bottomOffset: 0,
  1408. rowsAbove: 0,
  1409. rows: rows
  1410. };
  1411. }
  1412. var start = Math.max((this.clusterRows - BLOCK_ROWS) * num, 0);
  1413. var end = start + this.clusterRows;
  1414. var topOffset = Math.max(start * this.itemHeight, 0);
  1415. var bottomOffset = Math.max((rows.length - end) * this.itemHeight, 0);
  1416. var thisRows = [];
  1417. var rowsAbove = start;
  1418. if (topOffset < 1) {
  1419. rowsAbove++;
  1420. }
  1421. for (var i = start; i < end; i++) {
  1422. rows[i] && thisRows.push(rows[i]);
  1423. }
  1424. return {
  1425. start: start,
  1426. end: end,
  1427. topOffset: topOffset,
  1428. bottomOffset: bottomOffset,
  1429. rowsAbove: rowsAbove,
  1430. rows: thisRows
  1431. };
  1432. }
  1433. }, {
  1434. key: "checkChanges",
  1435. value: function checkChanges(type, value) {
  1436. var changed = value !== this.cache[type];
  1437. this.cache[type] = value;
  1438. return changed;
  1439. }
  1440. }, {
  1441. key: "getExtra",
  1442. value: function getExtra(className, height) {
  1443. var tag = document.createElement('tr');
  1444. tag.className = "virtual-scroll-".concat(className);
  1445. if (height) {
  1446. tag.style.height = "".concat(height, "px");
  1447. }
  1448. return tag.outerHTML;
  1449. }
  1450. }]);
  1451. }();
  1452. var BootstrapTable = /*#__PURE__*/function () {
  1453. function BootstrapTable(el, options) {
  1454. _classCallCheck(this, BootstrapTable);
  1455. this.options = options;
  1456. this.$el = $(el);
  1457. this.$el_ = this.$el.clone();
  1458. this.timeoutId_ = 0;
  1459. this.timeoutFooter_ = 0;
  1460. }
  1461. return _createClass(BootstrapTable, [{
  1462. key: "init",
  1463. value: function init() {
  1464. this.initConstants();
  1465. this.initLocale();
  1466. this.initContainer();
  1467. this.initTable();
  1468. this.initHeader();
  1469. this.initData();
  1470. this.initHiddenRows();
  1471. this.initToolbar();
  1472. this.initPagination();
  1473. this.initBody();
  1474. this.initSearchText();
  1475. this.initServer();
  1476. }
  1477. }, {
  1478. key: "initConstants",
  1479. value: function initConstants() {
  1480. var opts = this.options;
  1481. this.constants = Constants.CONSTANTS;
  1482. this.constants.theme = $.fn.bootstrapTable.theme;
  1483. this.constants.dataToggle = this.constants.html.dataToggle || 'data-toggle';
  1484. // init iconsPrefix and icons
  1485. var iconsPrefix = Utils.getIconsPrefix($.fn.bootstrapTable.theme);
  1486. if (typeof opts.icons === 'string') {
  1487. opts.icons = Utils.calculateObjectValue(null, opts.icons);
  1488. }
  1489. opts.iconsPrefix = opts.iconsPrefix || $.fn.bootstrapTable.defaults.iconsPrefix || iconsPrefix;
  1490. opts.icons = Object.assign(Utils.getIcons(opts.iconsPrefix), $.fn.bootstrapTable.defaults.icons, opts.icons);
  1491. // init buttons class
  1492. var buttonsPrefix = opts.buttonsPrefix ? "".concat(opts.buttonsPrefix, "-") : '';
  1493. this.constants.buttonsClass = [opts.buttonsPrefix, buttonsPrefix + opts.buttonsClass, Utils.sprintf("".concat(buttonsPrefix, "%s"), opts.iconSize)].join(' ').trim();
  1494. this.buttons = Utils.calculateObjectValue(this, opts.buttons, [], {});
  1495. if (_typeof(this.buttons) !== 'object') {
  1496. this.buttons = {};
  1497. }
  1498. }
  1499. }, {
  1500. key: "initLocale",
  1501. value: function initLocale() {
  1502. if (this.options.locale) {
  1503. var locales = $.fn.bootstrapTable.locales;
  1504. var parts = this.options.locale.split(/-|_/);
  1505. parts[0] = parts[0].toLowerCase();
  1506. if (parts[1]) {
  1507. parts[1] = parts[1].toUpperCase();
  1508. }
  1509. var localesToExtend = {};
  1510. if (locales[this.options.locale]) {
  1511. localesToExtend = locales[this.options.locale];
  1512. } else if (locales[parts.join('-')]) {
  1513. localesToExtend = locales[parts.join('-')];
  1514. } else if (locales[parts[0]]) {
  1515. localesToExtend = locales[parts[0]];
  1516. }
  1517. this._defaultLocales = this._defaultLocales || {};
  1518. for (var _i = 0, _Object$entries = Object.entries(localesToExtend); _i < _Object$entries.length; _i++) {
  1519. var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
  1520. formatName = _Object$entries$_i[0],
  1521. func = _Object$entries$_i[1];
  1522. var defaultLocale = this._defaultLocales.hasOwnProperty(formatName) ? this._defaultLocales[formatName] : BootstrapTable.DEFAULTS[formatName];
  1523. if (this.options[formatName] !== defaultLocale) {
  1524. continue;
  1525. }
  1526. this.options[formatName] = func;
  1527. this._defaultLocales[formatName] = func;
  1528. }
  1529. }
  1530. }
  1531. }, {
  1532. key: "initContainer",
  1533. value: function initContainer() {
  1534. var topPagination = ['top', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination clearfix"></div>' : '';
  1535. var bottomPagination = ['bottom', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination"></div>' : '';
  1536. var loadingTemplate = Utils.calculateObjectValue(this.options, this.options.loadingTemplate, [this.options.formatLoadingMessage()]);
  1537. this.$container = $("\n <div class=\"bootstrap-table ".concat(this.constants.theme, "\">\n <div class=\"fixed-table-toolbar\"></div>\n ").concat(topPagination, "\n <div class=\"fixed-table-container\">\n <div class=\"fixed-table-header\"><table></table></div>\n <div class=\"fixed-table-body\">\n <div class=\"fixed-table-loading\">\n ").concat(loadingTemplate, "\n </div>\n </div>\n <div class=\"fixed-table-footer\"></div>\n </div>\n ").concat(bottomPagination, "\n </div>\n "));
  1538. this.$container.insertAfter(this.$el);
  1539. this.$tableContainer = this.$container.find('.fixed-table-container');
  1540. this.$tableHeader = this.$container.find('.fixed-table-header');
  1541. this.$tableBody = this.$container.find('.fixed-table-body');
  1542. this.$tableLoading = this.$container.find('.fixed-table-loading');
  1543. this.$tableFooter = this.$el.find('tfoot');
  1544. // checking if custom table-toolbar exists or not
  1545. if (this.options.buttonsToolbar) {
  1546. this.$toolbar = $('body').find(this.options.buttonsToolbar);
  1547. } else {
  1548. this.$toolbar = this.$container.find('.fixed-table-toolbar');
  1549. }
  1550. this.$pagination = this.$container.find('.fixed-table-pagination');
  1551. this.$tableBody.append(this.$el);
  1552. this.$container.after('<div class="clearfix"></div>');
  1553. this.$el.addClass(this.options.classes);
  1554. this.$tableLoading.addClass(this.options.classes);
  1555. if (this.options.height) {
  1556. this.$tableContainer.addClass('fixed-height');
  1557. if (this.options.showFooter) {
  1558. this.$tableContainer.addClass('has-footer');
  1559. }
  1560. if (this.options.classes.split(' ').includes('table-bordered')) {
  1561. this.$tableBody.append('<div class="fixed-table-border"></div>');
  1562. this.$tableBorder = this.$tableBody.find('.fixed-table-border');
  1563. this.$tableLoading.addClass('fixed-table-border');
  1564. }
  1565. this.$tableFooter = this.$container.find('.fixed-table-footer');
  1566. }
  1567. }
  1568. }, {
  1569. key: "initTable",
  1570. value: function initTable() {
  1571. var _this = this;
  1572. var columns = [];
  1573. this.$header = this.$el.find('>thead');
  1574. if (!this.$header.length) {
  1575. this.$header = $("<thead class=\"".concat(this.options.theadClasses, "\"></thead>")).appendTo(this.$el);
  1576. } else if (this.options.theadClasses) {
  1577. this.$header.addClass(this.options.theadClasses);
  1578. }
  1579. this._headerTrClasses = [];
  1580. this._headerTrStyles = [];
  1581. this.$header.find('tr').each(function (i, el) {
  1582. var $tr = $(el);
  1583. var column = [];
  1584. $tr.find('th').each(function (i, el) {
  1585. var $th = $(el);
  1586. // #2014: getFieldIndex and elsewhere assume this is string, causes issues if not
  1587. if (typeof $th.data('field') !== 'undefined') {
  1588. $th.data('field', "".concat($th.data('field')));
  1589. }
  1590. var _data = Object.assign({}, $th.data());
  1591. for (var key in _data) {
  1592. if ($.fn.bootstrapTable.columnDefaults.hasOwnProperty(key)) {
  1593. delete _data[key];
  1594. }
  1595. }
  1596. column.push(Utils.extend({}, {
  1597. _data: Utils.getRealDataAttr(_data),
  1598. title: $th.html(),
  1599. class: $th.attr('class'),
  1600. titleTooltip: $th.attr('title'),
  1601. rowspan: $th.attr('rowspan') ? +$th.attr('rowspan') : undefined,
  1602. colspan: $th.attr('colspan') ? +$th.attr('colspan') : undefined
  1603. }, $th.data()));
  1604. });
  1605. columns.push(column);
  1606. if ($tr.attr('class')) {
  1607. _this._headerTrClasses.push($tr.attr('class'));
  1608. }
  1609. if ($tr.attr('style')) {
  1610. _this._headerTrStyles.push($tr.attr('style'));
  1611. }
  1612. });
  1613. if (!Array.isArray(this.options.columns[0])) {
  1614. this.options.columns = [this.options.columns];
  1615. }
  1616. this.options.columns = Utils.extend(true, [], columns, this.options.columns);
  1617. this.columns = [];
  1618. this.fieldsColumnsIndex = [];
  1619. Utils.setFieldIndex(this.options.columns);
  1620. this.options.columns.forEach(function (columns, i) {
  1621. columns.forEach(function (_column, j) {
  1622. var column = Utils.extend({}, BootstrapTable.COLUMN_DEFAULTS, _column, {
  1623. passed: _column
  1624. });
  1625. if (typeof column.fieldIndex !== 'undefined') {
  1626. _this.columns[column.fieldIndex] = column;
  1627. _this.fieldsColumnsIndex[column.field] = column.fieldIndex;
  1628. }
  1629. _this.options.columns[i][j] = column;
  1630. });
  1631. });
  1632. // if options.data is setting, do not process tbody and tfoot data
  1633. if (!this.options.data.length) {
  1634. var htmlData = Utils.trToData(this.columns, this.$el.find('>tbody>tr'));
  1635. if (htmlData.length) {
  1636. this.options.data = htmlData;
  1637. this.fromHtml = true;
  1638. }
  1639. }
  1640. if (!(this.options.pagination && this.options.sidePagination !== 'server')) {
  1641. this.footerData = Utils.trToData(this.columns, this.$el.find('>tfoot>tr'));
  1642. }
  1643. if (this.footerData) {
  1644. this.$el.find('tfoot').html('<tr></tr>');
  1645. }
  1646. if (!this.options.showFooter || this.options.cardView) {
  1647. this.$tableFooter.hide();
  1648. } else {
  1649. this.$tableFooter.show();
  1650. }
  1651. }
  1652. }, {
  1653. key: "initHeader",
  1654. value: function initHeader() {
  1655. var _this2 = this;
  1656. var visibleColumns = {};
  1657. var headerHtml = [];
  1658. this.header = {
  1659. fields: [],
  1660. styles: [],
  1661. classes: [],
  1662. formatters: [],
  1663. detailFormatters: [],
  1664. events: [],
  1665. sorters: [],
  1666. sortNames: [],
  1667. cellStyles: [],
  1668. searchables: []
  1669. };
  1670. Utils.updateFieldGroup(this.options.columns, this.columns);
  1671. this.options.columns.forEach(function (columns, i) {
  1672. var html = [];
  1673. html.push("<tr".concat(Utils.sprintf(' class="%s"', _this2._headerTrClasses[i]), " ").concat(Utils.sprintf(' style="%s"', _this2._headerTrStyles[i]), ">"));
  1674. var detailViewTemplate = '';
  1675. if (i === 0 && Utils.hasDetailViewIcon(_this2.options)) {
  1676. var rowspan = _this2.options.columns.length > 1 ? " rowspan=\"".concat(_this2.options.columns.length, "\"") : '';
  1677. detailViewTemplate = "<th class=\"detail\"".concat(rowspan, ">\n <div class=\"fht-cell\"></div>\n </th>");
  1678. }
  1679. if (detailViewTemplate && _this2.options.detailViewAlign !== 'right') {
  1680. html.push(detailViewTemplate);
  1681. }
  1682. columns.forEach(function (column, j) {
  1683. var class_ = Utils.sprintf(' class="%s"', column['class']);
  1684. var unitWidth = column.widthUnit;
  1685. var width = parseFloat(column.width);
  1686. var columnHalign = column.halign ? column.halign : column.align;
  1687. var halign = Utils.sprintf('text-align: %s; ', columnHalign);
  1688. var align = Utils.sprintf('text-align: %s; ', column.align);
  1689. var style = Utils.sprintf('vertical-align: %s; ', column.valign);
  1690. style += Utils.sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? !column.showSelectTitle ? '36px' : undefined : width ? width + unitWidth : undefined);
  1691. if (typeof column.fieldIndex === 'undefined' && !column.visible) {
  1692. return;
  1693. }
  1694. var headerStyle = Utils.calculateObjectValue(null, _this2.options.headerStyle, [column]);
  1695. var csses = [];
  1696. var data_ = [];
  1697. var classes = '';
  1698. if (headerStyle && headerStyle.css) {
  1699. for (var _i2 = 0, _Object$entries2 = Object.entries(headerStyle.css); _i2 < _Object$entries2.length; _i2++) {
  1700. var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
  1701. key = _Object$entries2$_i[0],
  1702. value = _Object$entries2$_i[1];
  1703. csses.push("".concat(key, ": ").concat(value));
  1704. }
  1705. }
  1706. if (headerStyle && headerStyle.classes) {
  1707. classes = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], headerStyle.classes].join(' ') : headerStyle.classes);
  1708. }
  1709. if (typeof column.fieldIndex !== 'undefined') {
  1710. _this2.header.fields[column.fieldIndex] = column.field;
  1711. _this2.header.styles[column.fieldIndex] = align + style;
  1712. _this2.header.classes[column.fieldIndex] = class_;
  1713. _this2.header.formatters[column.fieldIndex] = column.formatter;
  1714. _this2.header.detailFormatters[column.fieldIndex] = column.detailFormatter;
  1715. _this2.header.events[column.fieldIndex] = column.events;
  1716. _this2.header.sorters[column.fieldIndex] = column.sorter;
  1717. _this2.header.sortNames[column.fieldIndex] = column.sortName;
  1718. _this2.header.cellStyles[column.fieldIndex] = column.cellStyle;
  1719. _this2.header.searchables[column.fieldIndex] = column.searchable;
  1720. if (!column.visible) {
  1721. return;
  1722. }
  1723. if (_this2.options.cardView && !column.cardVisible) {
  1724. return;
  1725. }
  1726. visibleColumns[column.field] = column;
  1727. }
  1728. if (Object.keys(column._data || {}).length > 0) {
  1729. for (var _i3 = 0, _Object$entries3 = Object.entries(column._data); _i3 < _Object$entries3.length; _i3++) {
  1730. var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
  1731. k = _Object$entries3$_i[0],
  1732. v = _Object$entries3$_i[1];
  1733. data_.push("data-".concat(k, "='").concat(_typeof(v) === 'object' ? JSON.stringify(v) : v, "'"));
  1734. }
  1735. }
  1736. html.push("<th".concat(Utils.sprintf(' title="%s"', column.titleTooltip)), column.checkbox || column.radio ? Utils.sprintf(' class="bs-checkbox %s"', column['class'] || '') : classes || class_, Utils.sprintf(' style="%s"', halign + style + csses.join('; ') || undefined), Utils.sprintf(' rowspan="%s"', column.rowspan), Utils.sprintf(' colspan="%s"', column.colspan), Utils.sprintf(' data-field="%s"', column.field),
  1737. // If `column` is not the first element of `this.options.columns[0]`, then className 'data-not-first-th' should be added.
  1738. j === 0 && i > 0 ? ' data-not-first-th' : '', data_.length > 0 ? data_.join(' ') : '', '>');
  1739. html.push(Utils.sprintf('<div class="th-inner %s">', _this2.options.sortable && column.sortable ? "sortable".concat(columnHalign === 'center' ? ' sortable-center' : '', " both") : ''));
  1740. var text = _this2.options.escape && _this2.options.escapeTitle ? Utils.escapeHTML(column.title) : column.title;
  1741. var title = text;
  1742. if (column.checkbox) {
  1743. text = '';
  1744. if (!_this2.options.singleSelect && _this2.options.checkboxHeader) {
  1745. text = '<label><input name="btSelectAll" type="checkbox" /><span></span></label>';
  1746. }
  1747. _this2.header.stateField = column.field;
  1748. }
  1749. if (column.radio) {
  1750. text = '';
  1751. _this2.header.stateField = column.field;
  1752. }
  1753. if (!text && column.showSelectTitle) {
  1754. text += title;
  1755. }
  1756. html.push(text);
  1757. html.push('</div>');
  1758. html.push('<div class="fht-cell"></div>');
  1759. html.push('</div>');
  1760. html.push('</th>');
  1761. });
  1762. if (detailViewTemplate && _this2.options.detailViewAlign === 'right') {
  1763. html.push(detailViewTemplate);
  1764. }
  1765. html.push('</tr>');
  1766. if (html.length > 3) {
  1767. headerHtml.push(html.join(''));
  1768. }
  1769. });
  1770. this.$header.html(headerHtml.join(''));
  1771. this.$header.find('th[data-field]').each(function (i, el) {
  1772. $(el).data(visibleColumns[$(el).data('field')]);
  1773. });
  1774. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (e) {
  1775. var $this = $(e.currentTarget);
  1776. if (_this2.options.detailView && !$this.parent().hasClass('bs-checkbox')) {
  1777. if ($this.closest('.bootstrap-table')[0] !== _this2.$container[0]) {
  1778. return false;
  1779. }
  1780. }
  1781. if (_this2.options.sortable && $this.parent().data().sortable) {
  1782. _this2.onSort(e);
  1783. }
  1784. });
  1785. var resizeEvent = Utils.getEventName('resize.bootstrap-table', this.$el.attr('id'));
  1786. $(window).off(resizeEvent);
  1787. if (!this.options.showHeader || this.options.cardView) {
  1788. this.$header.hide();
  1789. this.$tableHeader.hide();
  1790. this.$tableLoading.css('top', 0);
  1791. } else {
  1792. this.$header.show();
  1793. this.$tableHeader.show();
  1794. this.$tableLoading.css('top', this.$header.outerHeight() + 1);
  1795. // Assign the correct sortable arrow
  1796. this.getCaret();
  1797. $(window).on(resizeEvent, function () {
  1798. return _this2.resetView();
  1799. });
  1800. }
  1801. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  1802. this.$selectAll.off('click').on('click', function (e) {
  1803. e.stopPropagation();
  1804. var checked = $(e.currentTarget).prop('checked');
  1805. _this2[checked ? 'checkAll' : 'uncheckAll']();
  1806. _this2.updateSelected();
  1807. });
  1808. }
  1809. }, {
  1810. key: "initData",
  1811. value: function initData(data, type) {
  1812. if (type === 'append') {
  1813. this.options.data = this.options.data.concat(data);
  1814. } else if (type === 'prepend') {
  1815. this.options.data = [].concat(data).concat(this.options.data);
  1816. } else {
  1817. data = data || Utils.deepCopy(this.options.data);
  1818. this.options.data = Array.isArray(data) ? data : data[this.options.dataField];
  1819. }
  1820. this.data = _toConsumableArray(this.options.data);
  1821. if (this.options.sortReset) {
  1822. this.unsortedData = _toConsumableArray(this.data);
  1823. }
  1824. if (this.options.sidePagination === 'server') {
  1825. return;
  1826. }
  1827. this.initSort();
  1828. }
  1829. }, {
  1830. key: "initSort",
  1831. value: function initSort() {
  1832. var _this3 = this;
  1833. var name = this.options.sortName;
  1834. var order = this.options.sortOrder === 'desc' ? -1 : 1;
  1835. var index = this.header.fields.indexOf(this.options.sortName);
  1836. var timeoutId = 0;
  1837. if (index !== -1) {
  1838. if (this.options.sortStable) {
  1839. this.data.forEach(function (row, i) {
  1840. if (!row.hasOwnProperty('_position')) {
  1841. row._position = i;
  1842. }
  1843. });
  1844. }
  1845. if (this.options.customSort) {
  1846. Utils.calculateObjectValue(this.options, this.options.customSort, [this.options.sortName, this.options.sortOrder, this.data]);
  1847. } else {
  1848. this.data.sort(function (a, b) {
  1849. if (_this3.header.sortNames[index]) {
  1850. name = _this3.header.sortNames[index];
  1851. }
  1852. var aa = Utils.getItemField(a, name, _this3.options.escape);
  1853. var bb = Utils.getItemField(b, name, _this3.options.escape);
  1854. var value = Utils.calculateObjectValue(_this3.header, _this3.header.sorters[index], [aa, bb, a, b]);
  1855. if (value !== undefined) {
  1856. if (_this3.options.sortStable && value === 0) {
  1857. return order * (a._position - b._position);
  1858. }
  1859. return order * value;
  1860. }
  1861. return Utils.sort(aa, bb, order, _this3.options, a._position, b._position);
  1862. });
  1863. }
  1864. if (this.options.sortClass !== undefined) {
  1865. clearTimeout(timeoutId);
  1866. timeoutId = setTimeout(function () {
  1867. _this3.$el.removeClass(_this3.options.sortClass);
  1868. var index = _this3.$header.find("[data-field=\"".concat(_this3.options.sortName, "\"]")).index();
  1869. _this3.$el.find("tr td:nth-child(".concat(index + 1, ")")).addClass(_this3.options.sortClass);
  1870. }, 250);
  1871. }
  1872. } else if (this.options.sortReset) {
  1873. this.data = _toConsumableArray(this.unsortedData);
  1874. }
  1875. }
  1876. }, {
  1877. key: "sortBy",
  1878. value: function sortBy(params) {
  1879. this.options.sortName = params.field;
  1880. this.options.sortOrder = params.hasOwnProperty('sortOrder') ? params.sortOrder : 'asc';
  1881. this._sort();
  1882. }
  1883. }, {
  1884. key: "onSort",
  1885. value: function onSort(_ref) {
  1886. var type = _ref.type,
  1887. currentTarget = _ref.currentTarget;
  1888. var $this = type === 'keypress' ? $(currentTarget) : $(currentTarget).parent();
  1889. var $this_ = this.$header.find('th').eq($this.index());
  1890. this.$header.add(this.$header_).find('span.order').remove();
  1891. if (this.options.sortName === $this.data('field')) {
  1892. var currentSortOrder = this.options.sortOrder;
  1893. var initialSortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].sortOrder || this.columns[this.fieldsColumnsIndex[$this.data('field')]].order;
  1894. if (currentSortOrder === undefined) {
  1895. this.options.sortOrder = 'asc';
  1896. } else if (currentSortOrder === 'asc') {
  1897. this.options.sortOrder = this.options.sortReset ? initialSortOrder === 'asc' ? 'desc' : undefined : 'desc';
  1898. } else if (this.options.sortOrder === 'desc') {
  1899. this.options.sortOrder = this.options.sortReset ? initialSortOrder === 'desc' ? 'asc' : undefined : 'asc';
  1900. }
  1901. if (this.options.sortOrder === undefined) {
  1902. this.options.sortName = undefined;
  1903. }
  1904. } else {
  1905. this.options.sortName = $this.data('field');
  1906. if (this.options.rememberOrder) {
  1907. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  1908. } else {
  1909. this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].sortOrder || this.columns[this.fieldsColumnsIndex[$this.data('field')]].order;
  1910. }
  1911. }
  1912. $this.add($this_).data('order', this.options.sortOrder);
  1913. // Assign the correct sortable arrow
  1914. this.getCaret();
  1915. this._sort();
  1916. }
  1917. }, {
  1918. key: "_sort",
  1919. value: function _sort() {
  1920. if (this.options.sidePagination === 'server' && this.options.serverSort) {
  1921. this.options.pageNumber = 1;
  1922. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  1923. this.initServer(this.options.silentSort);
  1924. return;
  1925. }
  1926. if (this.options.pagination && this.options.sortResetPage) {
  1927. this.options.pageNumber = 1;
  1928. this.initPagination();
  1929. }
  1930. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  1931. this.initSort();
  1932. this.initBody();
  1933. }
  1934. }, {
  1935. key: "initToolbar",
  1936. value: function initToolbar() {
  1937. var _this4 = this;
  1938. var opts = this.options;
  1939. var html = [];
  1940. var timeoutId = 0;
  1941. var $keepOpen;
  1942. var switchableCount = 0;
  1943. if (this.$toolbar.find('.bs-bars').children().length) {
  1944. $('body').append($(opts.toolbar));
  1945. }
  1946. this.$toolbar.html('');
  1947. if (typeof opts.toolbar === 'string' || _typeof(opts.toolbar) === 'object') {
  1948. $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', this.constants.classes.pull, opts.toolbarAlign)).appendTo(this.$toolbar).append($(opts.toolbar));
  1949. }
  1950. // showColumns, showToggle, showRefresh
  1951. html = ["<div class=\"".concat(['columns', "columns-".concat(opts.buttonsAlign), this.constants.classes.buttonsGroup, "".concat(this.constants.classes.pull, "-").concat(opts.buttonsAlign)].join(' '), "\">")];
  1952. if (typeof opts.buttonsOrder === 'string') {
  1953. opts.buttonsOrder = opts.buttonsOrder.replace(/\[|\]| |'/g, '').split(',');
  1954. }
  1955. this.buttons = Object.assign(this.buttons, {
  1956. paginationSwitch: {
  1957. text: opts.pagination ? opts.formatPaginationSwitchUp() : opts.formatPaginationSwitchDown(),
  1958. icon: opts.pagination ? opts.icons.paginationSwitchDown : opts.icons.paginationSwitchUp,
  1959. render: false,
  1960. event: this.togglePagination,
  1961. attributes: {
  1962. 'aria-label': opts.formatPaginationSwitch(),
  1963. title: opts.formatPaginationSwitch()
  1964. }
  1965. },
  1966. refresh: {
  1967. text: opts.formatRefresh(),
  1968. icon: opts.icons.refresh,
  1969. render: false,
  1970. event: this.refresh,
  1971. attributes: {
  1972. 'aria-label': opts.formatRefresh(),
  1973. title: opts.formatRefresh()
  1974. }
  1975. },
  1976. toggle: {
  1977. text: opts.formatToggleOn(),
  1978. icon: opts.icons.toggleOff,
  1979. render: false,
  1980. event: this.toggleView,
  1981. attributes: {
  1982. 'aria-label': opts.formatToggleOn(),
  1983. title: opts.formatToggleOn()
  1984. }
  1985. },
  1986. fullscreen: {
  1987. text: opts.formatFullscreen(),
  1988. icon: opts.icons.fullscreen,
  1989. render: false,
  1990. event: this.toggleFullscreen,
  1991. attributes: {
  1992. 'aria-label': opts.formatFullscreen(),
  1993. title: opts.formatFullscreen()
  1994. }
  1995. },
  1996. columns: {
  1997. render: false,
  1998. html: function html() {
  1999. var html = [];
  2000. html.push("<div class=\"keep-open ".concat(_this4.constants.classes.buttonsDropdown, "\">\n <button class=\"").concat(_this4.constants.buttonsClass, " dropdown-toggle\" type=\"button\" ").concat(_this4.constants.dataToggle, "=\"dropdown\"\n aria-label=\"").concat(opts.formatColumns(), "\" title=\"").concat(opts.formatColumns(), "\">\n ").concat(opts.showButtonIcons ? Utils.sprintf(_this4.constants.html.icon, opts.iconsPrefix, opts.icons.columns) : '', "\n ").concat(opts.showButtonText ? opts.formatColumns() : '', "\n ").concat(_this4.constants.html.dropdownCaret, "\n </button>\n ").concat(_this4.constants.html.toolbarDropdown[0]));
  2001. if (opts.showColumnsSearch) {
  2002. html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf('<input type="text" class="%s" name="columnsSearch" placeholder="%s" autocomplete="off">', _this4.constants.classes.input, opts.formatSearch())));
  2003. html.push(_this4.constants.html.toolbarDropdownSeparator);
  2004. }
  2005. if (opts.showColumnsToggleAll) {
  2006. var allFieldsVisible = _this4.getVisibleColumns().length === _this4.columns.filter(function (column) {
  2007. return !_this4.isSelectionColumn(column);
  2008. }).length;
  2009. html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf('<input type="checkbox" class="toggle-all" %s> <span>%s</span>', allFieldsVisible ? 'checked="checked"' : '', opts.formatColumnsToggleAll())));
  2010. html.push(_this4.constants.html.toolbarDropdownSeparator);
  2011. }
  2012. var visibleColumns = 0;
  2013. _this4.columns.forEach(function (column) {
  2014. if (column.visible) {
  2015. visibleColumns++;
  2016. }
  2017. });
  2018. _this4.columns.forEach(function (column, i) {
  2019. if (_this4.isSelectionColumn(column)) {
  2020. return;
  2021. }
  2022. if (opts.cardView && !column.cardVisible) {
  2023. return;
  2024. }
  2025. var checked = column.visible ? ' checked="checked"' : '';
  2026. var disabled = visibleColumns <= opts.minimumCountColumns && checked ? ' disabled="disabled"' : '';
  2027. if (column.switchable) {
  2028. html.push(Utils.sprintf(_this4.constants.html.toolbarDropdownItem, Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s%s> <span>%s</span>', column.field, i, checked, disabled, column.switchableLabel || column.title)));
  2029. switchableCount++;
  2030. }
  2031. });
  2032. html.push(_this4.constants.html.toolbarDropdown[1], '</div>');
  2033. return html.join('');
  2034. }
  2035. }
  2036. });
  2037. var buttonsHtml = {};
  2038. for (var _i4 = 0, _Object$entries4 = Object.entries(this.buttons); _i4 < _Object$entries4.length; _i4++) {
  2039. var _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2),
  2040. buttonName = _Object$entries4$_i[0],
  2041. buttonConfig = _Object$entries4$_i[1];
  2042. var buttonHtml = void 0;
  2043. if (buttonConfig.hasOwnProperty('html')) {
  2044. if (typeof buttonConfig.html === 'function') {
  2045. buttonHtml = buttonConfig.html();
  2046. } else if (typeof buttonConfig.html === 'string') {
  2047. buttonHtml = buttonConfig.html;
  2048. }
  2049. } else {
  2050. var buttonClass = this.constants.buttonsClass;
  2051. if (buttonConfig.hasOwnProperty('attributes') && buttonConfig.attributes.class) {
  2052. buttonClass += " ".concat(buttonConfig.attributes.class);
  2053. }
  2054. buttonHtml = "<button class=\"".concat(buttonClass, "\" type=\"button\" name=\"").concat(buttonName, "\"");
  2055. if (buttonConfig.hasOwnProperty('attributes')) {
  2056. for (var _i5 = 0, _Object$entries5 = Object.entries(buttonConfig.attributes); _i5 < _Object$entries5.length; _i5++) {
  2057. var _Object$entries5$_i = _slicedToArray(_Object$entries5[_i5], 2),
  2058. attributeName = _Object$entries5$_i[0],
  2059. value = _Object$entries5$_i[1];
  2060. if (attributeName === 'class') {
  2061. continue;
  2062. }
  2063. buttonHtml += " ".concat(attributeName, "=\"").concat(value, "\"");
  2064. }
  2065. }
  2066. buttonHtml += '>';
  2067. if (opts.showButtonIcons && buttonConfig.hasOwnProperty('icon')) {
  2068. buttonHtml += "".concat(Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, buttonConfig.icon), " ");
  2069. }
  2070. if (opts.showButtonText && buttonConfig.hasOwnProperty('text')) {
  2071. buttonHtml += buttonConfig.text;
  2072. }
  2073. buttonHtml += '</button>';
  2074. }
  2075. buttonsHtml[buttonName] = buttonHtml;
  2076. var optionName = "show".concat(buttonName.charAt(0).toUpperCase()).concat(buttonName.substring(1));
  2077. var showOption = opts[optionName];
  2078. if ((!buttonConfig.hasOwnProperty('render') || buttonConfig.hasOwnProperty('render') && buttonConfig.render) && (showOption === undefined || showOption === true)) {
  2079. opts[optionName] = true;
  2080. }
  2081. if (!opts.buttonsOrder.includes(buttonName)) {
  2082. opts.buttonsOrder.push(buttonName);
  2083. }
  2084. }
  2085. // Adding the button html to the final toolbar html when the showOption is true
  2086. var _iterator = _createForOfIteratorHelper(opts.buttonsOrder),
  2087. _step;
  2088. try {
  2089. for (_iterator.s(); !(_step = _iterator.n()).done;) {
  2090. var button = _step.value;
  2091. var _showOption = opts["show".concat(button.charAt(0).toUpperCase()).concat(button.substring(1))];
  2092. if (_showOption) {
  2093. html.push(buttonsHtml[button]);
  2094. }
  2095. }
  2096. } catch (err) {
  2097. _iterator.e(err);
  2098. } finally {
  2099. _iterator.f();
  2100. }
  2101. html.push('</div>');
  2102. // Fix #188: this.showToolbar is for extensions
  2103. if (this.showToolbar || html.length > 2) {
  2104. this.$toolbar.append(html.join(''));
  2105. }
  2106. var _loop = function _loop() {
  2107. var _Object$entries6$_i = _slicedToArray(_Object$entries6[_i6], 2),
  2108. buttonName = _Object$entries6$_i[0],
  2109. buttonConfig = _Object$entries6$_i[1];
  2110. if (buttonConfig.hasOwnProperty('event')) {
  2111. if (typeof buttonConfig.event === 'function' || typeof buttonConfig.event === 'string') {
  2112. var event = typeof buttonConfig.event === 'string' ? window[buttonConfig.event] : buttonConfig.event;
  2113. _this4.$toolbar.find("button[name=\"".concat(buttonName, "\"]")).off('click').on('click', function () {
  2114. return event.call(_this4);
  2115. });
  2116. return 1; // continue
  2117. }
  2118. var _loop2 = function _loop2() {
  2119. var _Object$entries7$_i = _slicedToArray(_Object$entries7[_i7], 2),
  2120. eventType = _Object$entries7$_i[0],
  2121. eventFunction = _Object$entries7$_i[1];
  2122. var event = typeof eventFunction === 'string' ? window[eventFunction] : eventFunction;
  2123. _this4.$toolbar.find("button[name=\"".concat(buttonName, "\"]")).off(eventType).on(eventType, function () {
  2124. return event.call(_this4);
  2125. });
  2126. };
  2127. for (var _i7 = 0, _Object$entries7 = Object.entries(buttonConfig.event); _i7 < _Object$entries7.length; _i7++) {
  2128. _loop2();
  2129. }
  2130. }
  2131. };
  2132. for (var _i6 = 0, _Object$entries6 = Object.entries(this.buttons); _i6 < _Object$entries6.length; _i6++) {
  2133. if (_loop()) continue;
  2134. }
  2135. if (opts.showColumns) {
  2136. $keepOpen = this.$toolbar.find('.keep-open');
  2137. var $checkboxes = $keepOpen.find('input[type="checkbox"]:not(".toggle-all")');
  2138. var $toggleAll = $keepOpen.find('input[type="checkbox"].toggle-all');
  2139. if (switchableCount <= opts.minimumCountColumns) {
  2140. $keepOpen.find('input').prop('disabled', true);
  2141. }
  2142. $keepOpen.find('li, label').off('click').on('click', function (e) {
  2143. e.stopImmediatePropagation();
  2144. });
  2145. $checkboxes.off('click').on('click', function (_ref2) {
  2146. var currentTarget = _ref2.currentTarget;
  2147. var $this = $(currentTarget);
  2148. _this4._toggleColumn($this.val(), $this.prop('checked'), false);
  2149. _this4.trigger('column-switch', $this.data('field'), $this.prop('checked'));
  2150. $toggleAll.prop('checked', $checkboxes.filter(':checked').length === _this4.columns.filter(function (column) {
  2151. return !_this4.isSelectionColumn(column);
  2152. }).length);
  2153. });
  2154. $toggleAll.off('click').on('click', function (_ref3) {
  2155. var currentTarget = _ref3.currentTarget;
  2156. _this4._toggleAllColumns($(currentTarget).prop('checked'));
  2157. _this4.trigger('column-switch-all', $(currentTarget).prop('checked'));
  2158. });
  2159. if (opts.showColumnsSearch) {
  2160. var $columnsSearch = $keepOpen.find('[name="columnsSearch"]');
  2161. var $listItems = $keepOpen.find('.dropdown-item-marker');
  2162. $columnsSearch.on('keyup paste change', function (_ref4) {
  2163. var currentTarget = _ref4.currentTarget;
  2164. var $this = $(currentTarget);
  2165. var searchValue = $this.val().toLowerCase();
  2166. $listItems.show();
  2167. $checkboxes.each(function (i, el) {
  2168. var $checkbox = $(el);
  2169. var $listItem = $checkbox.parents('.dropdown-item-marker');
  2170. var text = $listItem.text().toLowerCase();
  2171. if (!text.includes(searchValue)) {
  2172. $listItem.hide();
  2173. }
  2174. });
  2175. });
  2176. }
  2177. }
  2178. var handleInputEvent = function handleInputEvent($searchInput) {
  2179. var eventTriggers = $searchInput.is('select') ? 'change' : 'keyup drop blur mouseup';
  2180. $searchInput.off(eventTriggers).on(eventTriggers, function (event) {
  2181. if (opts.searchOnEnterKey && event.keyCode !== 13) {
  2182. return;
  2183. }
  2184. if ([37, 38, 39, 40].includes(event.keyCode)) {
  2185. return;
  2186. }
  2187. clearTimeout(timeoutId); // doesn't matter if it's 0
  2188. timeoutId = setTimeout(function () {
  2189. _this4.onSearch({
  2190. currentTarget: event.currentTarget
  2191. });
  2192. }, opts.searchTimeOut);
  2193. });
  2194. };
  2195. // Fix #4516: this.showSearchClearButton is for extensions
  2196. if ((opts.search || this.showSearchClearButton) && typeof opts.searchSelector !== 'string') {
  2197. html = [];
  2198. var showSearchButton = Utils.sprintf(this.constants.html.searchButton, this.constants.buttonsClass, opts.formatSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.search) : '', opts.showButtonText ? opts.formatSearch() : '');
  2199. var showSearchClearButton = Utils.sprintf(this.constants.html.searchClearButton, this.constants.buttonsClass, opts.formatClearSearch(), opts.showButtonIcons ? Utils.sprintf(this.constants.html.icon, opts.iconsPrefix, opts.icons.clearSearch) : '', opts.showButtonText ? opts.formatClearSearch() : '');
  2200. var searchInputHtml = "<input class=\"".concat(this.constants.classes.input, "\n ").concat(Utils.sprintf(' %s%s', this.constants.classes.inputPrefix, opts.iconSize), "\n search-input\" type=\"search\" aria-label=\"").concat(opts.formatSearch(), "\" placeholder=\"").concat(opts.formatSearch(), "\" autocomplete=\"off\">");
  2201. var searchInputFinalHtml = searchInputHtml;
  2202. if (opts.showSearchButton || opts.showSearchClearButton) {
  2203. var _buttonsHtml = (opts.showSearchButton ? showSearchButton : '') + (opts.showSearchClearButton ? showSearchClearButton : '');
  2204. searchInputFinalHtml = opts.search ? Utils.sprintf(this.constants.html.inputGroup, searchInputHtml, _buttonsHtml) : _buttonsHtml;
  2205. }
  2206. html.push(Utils.sprintf("\n <div class=\"".concat(this.constants.classes.pull, "-").concat(opts.searchAlign, " search ").concat(this.constants.classes.inputGroup, "\">\n %s\n </div>\n "), searchInputFinalHtml));
  2207. this.$toolbar.append(html.join(''));
  2208. var $searchInput = Utils.getSearchInput(this);
  2209. if (opts.showSearchButton) {
  2210. this.$toolbar.find('.search button[name=search]').off('click').on('click', function () {
  2211. clearTimeout(timeoutId); // doesn't matter if it's 0
  2212. timeoutId = setTimeout(function () {
  2213. _this4.onSearch({
  2214. currentTarget: $searchInput
  2215. });
  2216. }, opts.searchTimeOut);
  2217. });
  2218. if (opts.searchOnEnterKey) {
  2219. handleInputEvent($searchInput);
  2220. }
  2221. } else {
  2222. handleInputEvent($searchInput);
  2223. }
  2224. if (opts.showSearchClearButton) {
  2225. this.$toolbar.find('.search button[name=clearSearch]').click(function () {
  2226. _this4.resetSearch();
  2227. });
  2228. }
  2229. } else if (typeof opts.searchSelector === 'string') {
  2230. handleInputEvent(Utils.getSearchInput(this));
  2231. }
  2232. }
  2233. }, {
  2234. key: "onSearch",
  2235. value: function onSearch() {
  2236. var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  2237. currentTarget = _ref5.currentTarget,
  2238. firedByInitSearchText = _ref5.firedByInitSearchText;
  2239. var overwriteSearchText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
  2240. if (currentTarget !== undefined && $(currentTarget).length && overwriteSearchText) {
  2241. var text = $(currentTarget).val().trim();
  2242. if (this.options.trimOnSearch && $(currentTarget).val() !== text) {
  2243. $(currentTarget).val(text);
  2244. }
  2245. if (this.searchText === text) {
  2246. return;
  2247. }
  2248. var $searchInput = Utils.getSearchInput(this);
  2249. var $currentTarget = currentTarget instanceof jQuery ? currentTarget : $(currentTarget);
  2250. if ($currentTarget.is($searchInput) || $currentTarget.hasClass('search-input')) {
  2251. this.searchText = text;
  2252. this.options.searchText = text;
  2253. }
  2254. }
  2255. if (!firedByInitSearchText) {
  2256. this.options.pageNumber = 1;
  2257. }
  2258. this.initSearch();
  2259. if (firedByInitSearchText) {
  2260. if (this.options.sidePagination === 'client') {
  2261. this.updatePagination();
  2262. }
  2263. } else {
  2264. this.updatePagination();
  2265. }
  2266. this.trigger('search', this.searchText);
  2267. }
  2268. }, {
  2269. key: "initSearch",
  2270. value: function initSearch() {
  2271. var _this5 = this;
  2272. this.filterOptions = this.filterOptions || this.options.filterOptions;
  2273. if (this.options.sidePagination !== 'server') {
  2274. if (this.options.customSearch) {
  2275. this.data = Utils.calculateObjectValue(this.options, this.options.customSearch, [this.options.data, this.searchText, this.filterColumns]);
  2276. if (this.options.sortReset) {
  2277. this.unsortedData = _toConsumableArray(this.data);
  2278. }
  2279. this.initSort();
  2280. return;
  2281. }
  2282. var rawSearchText = this.searchText && (this.fromHtml ? Utils.escapeHTML(this.searchText) : this.searchText);
  2283. var searchText = rawSearchText ? rawSearchText.toLowerCase() : '';
  2284. var f = Utils.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  2285. if (this.options.searchAccentNeutralise) {
  2286. searchText = Utils.normalizeAccent(searchText);
  2287. }
  2288. // Check filter
  2289. if (typeof this.filterOptions.filterAlgorithm === 'function') {
  2290. this.data = this.options.data.filter(function (item) {
  2291. return _this5.filterOptions.filterAlgorithm.apply(null, [item, f]);
  2292. });
  2293. } else if (typeof this.filterOptions.filterAlgorithm === 'string') {
  2294. this.data = f ? this.options.data.filter(function (item) {
  2295. var filterAlgorithm = _this5.filterOptions.filterAlgorithm;
  2296. if (filterAlgorithm === 'and') {
  2297. for (var key in f) {
  2298. if (Array.isArray(f[key]) && !f[key].includes(item[key]) || !Array.isArray(f[key]) && item[key] !== f[key]) {
  2299. return false;
  2300. }
  2301. }
  2302. } else if (filterAlgorithm === 'or') {
  2303. var match = false;
  2304. for (var _key in f) {
  2305. if (Array.isArray(f[_key]) && f[_key].includes(item[_key]) || !Array.isArray(f[_key]) && item[_key] === f[_key]) {
  2306. match = true;
  2307. }
  2308. }
  2309. return match;
  2310. }
  2311. return true;
  2312. }) : _toConsumableArray(this.options.data);
  2313. }
  2314. var visibleFields = this.getVisibleFields();
  2315. this.data = searchText ? this.data.filter(function (item, i) {
  2316. for (var j = 0; j < _this5.header.fields.length; j++) {
  2317. if (!_this5.header.searchables[j] || _this5.options.visibleSearch && visibleFields.indexOf(_this5.header.fields[j]) === -1) {
  2318. continue;
  2319. }
  2320. var key = Utils.isNumeric(_this5.header.fields[j]) ? parseInt(_this5.header.fields[j], 10) : _this5.header.fields[j];
  2321. var column = _this5.columns[_this5.fieldsColumnsIndex[key]];
  2322. var value = void 0;
  2323. if (typeof key === 'string' && !item.hasOwnProperty(key)) {
  2324. value = item;
  2325. var props = key.split('.');
  2326. for (var _i8 = 0; _i8 < props.length; _i8++) {
  2327. if (value[props[_i8]] !== null) {
  2328. value = value[props[_i8]];
  2329. } else {
  2330. value = null;
  2331. break;
  2332. }
  2333. }
  2334. } else {
  2335. value = item[key];
  2336. }
  2337. if (_this5.options.searchAccentNeutralise) {
  2338. value = Utils.normalizeAccent(value);
  2339. }
  2340. // Fix #142: respect searchFormatter boolean
  2341. if (column && column.searchFormatter) {
  2342. value = Utils.calculateObjectValue(column, _this5.header.formatters[j], [value, item, i, column.field], value);
  2343. }
  2344. if (typeof value === 'string' || typeof value === 'number') {
  2345. if (_this5.options.strictSearch && "".concat(value).toLowerCase() === searchText || _this5.options.regexSearch && Utils.regexCompare(value, rawSearchText)) {
  2346. return true;
  2347. }
  2348. var largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(-?\d+)?|(-?\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm;
  2349. var matches = largerSmallerEqualsRegex.exec(_this5.searchText);
  2350. var comparisonCheck = false;
  2351. if (matches) {
  2352. var operator = matches[1] || "".concat(matches[5], "l");
  2353. var comparisonValue = matches[2] || matches[3];
  2354. var int = parseInt(value, 10);
  2355. var comparisonInt = parseInt(comparisonValue, 10);
  2356. switch (operator) {
  2357. case '>':
  2358. case '<l':
  2359. comparisonCheck = int > comparisonInt;
  2360. break;
  2361. case '<':
  2362. case '>l':
  2363. comparisonCheck = int < comparisonInt;
  2364. break;
  2365. case '<=':
  2366. case '=<':
  2367. case '>=l':
  2368. case '=>l':
  2369. comparisonCheck = int <= comparisonInt;
  2370. break;
  2371. case '>=':
  2372. case '=>':
  2373. case '<=l':
  2374. case '=<l':
  2375. comparisonCheck = int >= comparisonInt;
  2376. break;
  2377. }
  2378. }
  2379. if (comparisonCheck || "".concat(value).toLowerCase().includes(searchText)) {
  2380. return true;
  2381. }
  2382. }
  2383. }
  2384. return false;
  2385. }) : this.data;
  2386. if (this.options.sortReset) {
  2387. this.unsortedData = _toConsumableArray(this.data);
  2388. }
  2389. this.initSort();
  2390. }
  2391. }
  2392. }, {
  2393. key: "initPagination",
  2394. value: function initPagination() {
  2395. var _this6 = this;
  2396. var opts = this.options;
  2397. if (!opts.pagination) {
  2398. this.$pagination.hide();
  2399. return;
  2400. }
  2401. this.$pagination.show();
  2402. var html = [];
  2403. var allSelected = false;
  2404. var i;
  2405. var from;
  2406. var to;
  2407. var $pageList;
  2408. var $pre;
  2409. var $next;
  2410. var $number;
  2411. var data = this.getData({
  2412. includeHiddenRows: false
  2413. });
  2414. var pageList = opts.pageList;
  2415. if (typeof pageList === 'string') {
  2416. pageList = pageList.replace(/\[|\]| /g, '').toLowerCase().split(',');
  2417. }
  2418. pageList = pageList.map(function (value) {
  2419. if (typeof value === 'string') {
  2420. return value.toLowerCase() === opts.formatAllRows().toLowerCase() || ['all', 'unlimited'].includes(value.toLowerCase()) ? opts.formatAllRows() : +value;
  2421. }
  2422. return value;
  2423. });
  2424. this.paginationParts = opts.paginationParts;
  2425. if (typeof this.paginationParts === 'string') {
  2426. this.paginationParts = this.paginationParts.replace(/\[|\]| |'/g, '').split(',');
  2427. }
  2428. if (opts.sidePagination !== 'server') {
  2429. opts.totalRows = data.length;
  2430. }
  2431. this.totalPages = 0;
  2432. if (opts.totalRows) {
  2433. if (opts.pageSize === opts.formatAllRows()) {
  2434. opts.pageSize = opts.totalRows;
  2435. allSelected = true;
  2436. }
  2437. this.totalPages = ~~((opts.totalRows - 1) / opts.pageSize) + 1;
  2438. opts.totalPages = this.totalPages;
  2439. }
  2440. if (this.totalPages > 0 && opts.pageNumber > this.totalPages) {
  2441. opts.pageNumber = this.totalPages;
  2442. }
  2443. this.pageFrom = (opts.pageNumber - 1) * opts.pageSize + 1;
  2444. this.pageTo = opts.pageNumber * opts.pageSize;
  2445. if (this.pageTo > opts.totalRows) {
  2446. this.pageTo = opts.totalRows;
  2447. }
  2448. if (this.options.pagination && this.options.sidePagination !== 'server') {
  2449. this.options.totalNotFiltered = this.options.data.length;
  2450. }
  2451. if (!this.options.showExtendedPagination) {
  2452. this.options.totalNotFiltered = undefined;
  2453. }
  2454. if (this.paginationParts.includes('pageInfo') || this.paginationParts.includes('pageInfoShort') || this.paginationParts.includes('pageSize')) {
  2455. html.push("<div class=\"".concat(this.constants.classes.pull, "-").concat(opts.paginationDetailHAlign, " pagination-detail\">"));
  2456. }
  2457. if (this.paginationParts.includes('pageInfo') || this.paginationParts.includes('pageInfoShort')) {
  2458. var totalRows = this.options.totalRows + (this.options.sidePagination === 'client' && this.options.paginationLoadMore && !this._paginationLoaded ? ' +' : '');
  2459. var paginationInfo = this.paginationParts.includes('pageInfoShort') ? opts.formatDetailPagination(totalRows) : opts.formatShowingRows(this.pageFrom, this.pageTo, totalRows, opts.totalNotFiltered);
  2460. html.push("<span class=\"pagination-info\">\n ".concat(paginationInfo, "\n </span>"));
  2461. }
  2462. if (this.paginationParts.includes('pageSize')) {
  2463. html.push('<div class="page-list">');
  2464. var pageNumber = ["<div class=\"".concat(this.constants.classes.paginationDropdown, "\">\n <button class=\"").concat(this.constants.buttonsClass, " dropdown-toggle\" type=\"button\" ").concat(this.constants.dataToggle, "=\"dropdown\">\n <span class=\"page-size\">\n ").concat(allSelected ? opts.formatAllRows() : opts.pageSize, "\n </span>\n ").concat(this.constants.html.dropdownCaret, "\n </button>\n ").concat(this.constants.html.pageDropdown[0])];
  2465. pageList.forEach(function (page, i) {
  2466. if (!opts.smartDisplay || i === 0 || pageList[i - 1] < opts.totalRows || page === opts.formatAllRows()) {
  2467. var active;
  2468. if (allSelected) {
  2469. active = page === opts.formatAllRows() ? _this6.constants.classes.dropdownActive : '';
  2470. } else {
  2471. active = page === opts.pageSize ? _this6.constants.classes.dropdownActive : '';
  2472. }
  2473. pageNumber.push(Utils.sprintf(_this6.constants.html.pageDropdownItem, active, page));
  2474. }
  2475. });
  2476. pageNumber.push("".concat(this.constants.html.pageDropdown[1], "</div>"));
  2477. html.push(opts.formatRecordsPerPage(pageNumber.join('')));
  2478. }
  2479. if (this.paginationParts.includes('pageInfo') || this.paginationParts.includes('pageInfoShort') || this.paginationParts.includes('pageSize')) {
  2480. html.push('</div></div>');
  2481. }
  2482. if (this.paginationParts.includes('pageList')) {
  2483. html.push("<div class=\"".concat(this.constants.classes.pull, "-").concat(opts.paginationHAlign, " pagination\">"), Utils.sprintf(this.constants.html.pagination[0], Utils.sprintf(' pagination-%s', opts.iconSize)), Utils.sprintf(this.constants.html.paginationItem, ' page-pre', opts.formatSRPaginationPreText(), opts.paginationPreText));
  2484. if (this.totalPages < opts.paginationSuccessivelySize) {
  2485. from = 1;
  2486. to = this.totalPages;
  2487. } else {
  2488. from = opts.pageNumber - opts.paginationPagesBySide;
  2489. to = from + opts.paginationPagesBySide * 2;
  2490. }
  2491. if (opts.pageNumber < opts.paginationSuccessivelySize - 1) {
  2492. to = opts.paginationSuccessivelySize;
  2493. }
  2494. if (opts.paginationSuccessivelySize > this.totalPages - from) {
  2495. from = from - (opts.paginationSuccessivelySize - (this.totalPages - from)) + 1;
  2496. }
  2497. if (from < 1) {
  2498. from = 1;
  2499. }
  2500. if (to > this.totalPages) {
  2501. to = this.totalPages;
  2502. }
  2503. var middleSize = Math.round(opts.paginationPagesBySide / 2);
  2504. var pageItem = function pageItem(i) {
  2505. var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  2506. return Utils.sprintf(_this6.constants.html.paginationItem, classes + (i === opts.pageNumber ? " ".concat(_this6.constants.classes.paginationActive) : ''), opts.formatSRPaginationPageText(i), i);
  2507. };
  2508. if (from > 1) {
  2509. var max = opts.paginationPagesBySide;
  2510. if (max >= from) max = from - 1;
  2511. for (i = 1; i <= max; i++) {
  2512. html.push(pageItem(i));
  2513. }
  2514. if (from - 1 === max + 1) {
  2515. i = from - 1;
  2516. html.push(pageItem(i));
  2517. } else if (from - 1 > max) {
  2518. if (from - opts.paginationPagesBySide * 2 > opts.paginationPagesBySide && opts.paginationUseIntermediate) {
  2519. i = Math.round((from - middleSize) / 2 + middleSize);
  2520. html.push(pageItem(i, ' page-intermediate'));
  2521. } else {
  2522. html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-first-separator disabled', '', '...'));
  2523. }
  2524. }
  2525. }
  2526. for (i = from; i <= to; i++) {
  2527. html.push(pageItem(i));
  2528. }
  2529. if (this.totalPages > to) {
  2530. var min = this.totalPages - (opts.paginationPagesBySide - 1);
  2531. if (to >= min) min = to + 1;
  2532. if (to + 1 === min - 1) {
  2533. i = to + 1;
  2534. html.push(pageItem(i));
  2535. } else if (min > to + 1) {
  2536. if (this.totalPages - to > opts.paginationPagesBySide * 2 && opts.paginationUseIntermediate) {
  2537. i = Math.round((this.totalPages - middleSize - to) / 2 + to);
  2538. html.push(pageItem(i, ' page-intermediate'));
  2539. } else {
  2540. html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-last-separator disabled', '', '...'));
  2541. }
  2542. }
  2543. for (i = min; i <= this.totalPages; i++) {
  2544. html.push(pageItem(i));
  2545. }
  2546. }
  2547. html.push(Utils.sprintf(this.constants.html.paginationItem, ' page-next', opts.formatSRPaginationNextText(), opts.paginationNextText));
  2548. html.push(this.constants.html.pagination[1], '</div>');
  2549. }
  2550. this.$pagination.html(html.join(''));
  2551. var dropupClass = ['bottom', 'both'].includes(opts.paginationVAlign) ? " ".concat(this.constants.classes.dropup) : '';
  2552. this.$pagination.last().find('.page-list > div').addClass(dropupClass);
  2553. if (!opts.onlyInfoPagination) {
  2554. $pageList = this.$pagination.find('.page-list a');
  2555. $pre = this.$pagination.find('.page-pre');
  2556. $next = this.$pagination.find('.page-next');
  2557. $number = this.$pagination.find('.page-item').not('.page-next, .page-pre, .page-last-separator, .page-first-separator');
  2558. if (this.totalPages <= 1) {
  2559. this.$pagination.find('div.pagination').hide();
  2560. }
  2561. if (opts.smartDisplay) {
  2562. if (pageList.length < 2 || opts.totalRows <= pageList[0]) {
  2563. this.$pagination.find('div.page-list').hide();
  2564. }
  2565. }
  2566. // when data is empty, hide the pagination
  2567. this.$pagination[this.getData().length ? 'show' : 'hide']();
  2568. if (!opts.paginationLoop) {
  2569. if (opts.pageNumber === 1) {
  2570. $pre.addClass('disabled');
  2571. }
  2572. if (opts.pageNumber === this.totalPages) {
  2573. $next.addClass('disabled');
  2574. }
  2575. }
  2576. if (allSelected) {
  2577. opts.pageSize = opts.formatAllRows();
  2578. }
  2579. $pageList.off('click').on('click', function (e) {
  2580. return _this6.onPageListChange(e);
  2581. });
  2582. $pre.off('click').on('click', function (e) {
  2583. return _this6.onPagePre(e);
  2584. });
  2585. $next.off('click').on('click', function (e) {
  2586. return _this6.onPageNext(e);
  2587. });
  2588. $number.off('click').on('click', function (e) {
  2589. return _this6.onPageNumber(e);
  2590. });
  2591. }
  2592. }
  2593. }, {
  2594. key: "updatePagination",
  2595. value: function updatePagination(event) {
  2596. // Fix #171: IE disabled button can be clicked bug.
  2597. if (event && $(event.currentTarget).hasClass('disabled')) {
  2598. return;
  2599. }
  2600. if (!this.options.maintainMetaData) {
  2601. this.resetRows();
  2602. }
  2603. this.initPagination();
  2604. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  2605. if (this.options.sidePagination === 'server' || this.options.sidePagination === 'client' && this.options.paginationLoadMore && !this._paginationLoaded && this.options.pageNumber === this.totalPages) {
  2606. this.initServer();
  2607. } else {
  2608. this.initBody();
  2609. }
  2610. }
  2611. }, {
  2612. key: "onPageListChange",
  2613. value: function onPageListChange(event) {
  2614. event.preventDefault();
  2615. var $this = $(event.currentTarget);
  2616. $this.parent().addClass(this.constants.classes.dropdownActive).siblings().removeClass(this.constants.classes.dropdownActive);
  2617. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ? this.options.formatAllRows() : +$this.text();
  2618. this.$toolbar.find('.page-size').text(this.options.pageSize);
  2619. this.updatePagination(event);
  2620. return false;
  2621. }
  2622. }, {
  2623. key: "onPagePre",
  2624. value: function onPagePre(event) {
  2625. if ($(event.target).hasClass('disabled')) {
  2626. return;
  2627. }
  2628. event.preventDefault();
  2629. if (this.options.pageNumber - 1 === 0) {
  2630. this.options.pageNumber = this.options.totalPages;
  2631. } else {
  2632. this.options.pageNumber--;
  2633. }
  2634. this.updatePagination(event);
  2635. return false;
  2636. }
  2637. }, {
  2638. key: "onPageNext",
  2639. value: function onPageNext(event) {
  2640. if ($(event.target).hasClass('disabled')) {
  2641. return;
  2642. }
  2643. event.preventDefault();
  2644. if (this.options.pageNumber + 1 > this.options.totalPages) {
  2645. this.options.pageNumber = 1;
  2646. } else {
  2647. this.options.pageNumber++;
  2648. }
  2649. this.updatePagination(event);
  2650. return false;
  2651. }
  2652. }, {
  2653. key: "onPageNumber",
  2654. value: function onPageNumber(event) {
  2655. event.preventDefault();
  2656. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  2657. return;
  2658. }
  2659. this.options.pageNumber = +$(event.currentTarget).text();
  2660. this.updatePagination(event);
  2661. return false;
  2662. }
  2663. // eslint-disable-next-line no-unused-vars
  2664. }, {
  2665. key: "initRow",
  2666. value: function initRow(item, i, data, trFragments) {
  2667. var _this7 = this;
  2668. var html = [];
  2669. var style = {};
  2670. var csses = [];
  2671. var data_ = '';
  2672. var attributes = {};
  2673. var htmlAttributes = [];
  2674. if (Utils.findIndex(this.hiddenRows, item) > -1) {
  2675. return;
  2676. }
  2677. style = Utils.calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  2678. if (style && style.css) {
  2679. for (var _i9 = 0, _Object$entries8 = Object.entries(style.css); _i9 < _Object$entries8.length; _i9++) {
  2680. var _Object$entries8$_i = _slicedToArray(_Object$entries8[_i9], 2),
  2681. key = _Object$entries8$_i[0],
  2682. value = _Object$entries8$_i[1];
  2683. csses.push("".concat(key, ": ").concat(value));
  2684. }
  2685. }
  2686. attributes = Utils.calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes);
  2687. if (attributes) {
  2688. for (var _i10 = 0, _Object$entries9 = Object.entries(attributes); _i10 < _Object$entries9.length; _i10++) {
  2689. var _Object$entries9$_i = _slicedToArray(_Object$entries9[_i10], 2),
  2690. _key2 = _Object$entries9$_i[0],
  2691. _value = _Object$entries9$_i[1];
  2692. htmlAttributes.push("".concat(_key2, "=\"").concat(Utils.escapeHTML(_value), "\""));
  2693. }
  2694. }
  2695. if (item._data && !Utils.isEmptyObject(item._data)) {
  2696. for (var _i11 = 0, _Object$entries10 = Object.entries(item._data); _i11 < _Object$entries10.length; _i11++) {
  2697. var _Object$entries10$_i = _slicedToArray(_Object$entries10[_i11], 2),
  2698. k = _Object$entries10$_i[0],
  2699. v = _Object$entries10$_i[1];
  2700. // ignore data-index
  2701. if (k === 'index') {
  2702. return;
  2703. }
  2704. data_ += " data-".concat(k, "='").concat(_typeof(v) === 'object' ? JSON.stringify(v) : v, "'");
  2705. }
  2706. }
  2707. html.push('<tr', Utils.sprintf(' %s', htmlAttributes.length ? htmlAttributes.join(' ') : undefined), Utils.sprintf(' id="%s"', Array.isArray(item) ? undefined : item._id), Utils.sprintf(' class="%s"', style.classes || (Array.isArray(item) ? undefined : item._class)), Utils.sprintf(' style="%s"', Array.isArray(item) ? undefined : item._style), " data-index=\"".concat(i, "\""), Utils.sprintf(' data-uniqueid="%s"', Utils.getItemField(item, this.options.uniqueId, false)), Utils.sprintf(' data-has-detail-view="%s"', this.options.detailView && Utils.calculateObjectValue(null, this.options.detailFilter, [i, item]) ? 'true' : undefined), Utils.sprintf('%s', data_), '>');
  2708. if (this.options.cardView) {
  2709. html.push("<td colspan=\"".concat(this.header.fields.length, "\"><div class=\"card-views\">"));
  2710. }
  2711. var detailViewTemplate = '';
  2712. if (Utils.hasDetailViewIcon(this.options)) {
  2713. detailViewTemplate = '<td>';
  2714. if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) {
  2715. detailViewTemplate += "\n <a class=\"detail-icon\" href=\"#\">\n ".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen), "\n </a>\n ");
  2716. }
  2717. detailViewTemplate += '</td>';
  2718. }
  2719. if (detailViewTemplate && this.options.detailViewAlign !== 'right') {
  2720. html.push(detailViewTemplate);
  2721. }
  2722. this.header.fields.forEach(function (field, j) {
  2723. var column = _this7.columns[j];
  2724. var text = '';
  2725. var value_ = Utils.getItemField(item, field, _this7.options.escape, column.escape);
  2726. var value = '';
  2727. var type = '';
  2728. var cellStyle = {};
  2729. var id_ = '';
  2730. var class_ = _this7.header.classes[j];
  2731. var style_ = '';
  2732. var styleToAdd_ = '';
  2733. var data_ = '';
  2734. var rowspan_ = '';
  2735. var colspan_ = '';
  2736. var title_ = '';
  2737. if ((_this7.fromHtml || _this7.autoMergeCells) && typeof value_ === 'undefined') {
  2738. if (!column.checkbox && !column.radio) {
  2739. return;
  2740. }
  2741. }
  2742. if (!column.visible) {
  2743. return;
  2744. }
  2745. if (_this7.options.cardView && !column.cardVisible) {
  2746. return;
  2747. }
  2748. // Style concat
  2749. if (csses.concat([_this7.header.styles[j]]).length) {
  2750. styleToAdd_ += "".concat(csses.concat([_this7.header.styles[j]]).join('; '));
  2751. }
  2752. if (item["_".concat(field, "_style")]) {
  2753. styleToAdd_ += "".concat(item["_".concat(field, "_style")]);
  2754. }
  2755. if (styleToAdd_) {
  2756. style_ = " style=\"".concat(styleToAdd_, "\"");
  2757. }
  2758. // Style concat
  2759. // handle id and class of td
  2760. if (item["_".concat(field, "_id")]) {
  2761. id_ = Utils.sprintf(' id="%s"', item["_".concat(field, "_id")]);
  2762. }
  2763. if (item["_".concat(field, "_class")]) {
  2764. class_ = Utils.sprintf(' class="%s"', item["_".concat(field, "_class")]);
  2765. }
  2766. if (item["_".concat(field, "_rowspan")]) {
  2767. rowspan_ = Utils.sprintf(' rowspan="%s"', item["_".concat(field, "_rowspan")]);
  2768. }
  2769. if (item["_".concat(field, "_colspan")]) {
  2770. colspan_ = Utils.sprintf(' colspan="%s"', item["_".concat(field, "_colspan")]);
  2771. }
  2772. if (item["_".concat(field, "_title")]) {
  2773. title_ = Utils.sprintf(' title="%s"', item["_".concat(field, "_title")]);
  2774. }
  2775. cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle);
  2776. if (cellStyle.classes) {
  2777. class_ = " class=\"".concat(cellStyle.classes, "\"");
  2778. }
  2779. if (cellStyle.css) {
  2780. var csses_ = [];
  2781. for (var _i12 = 0, _Object$entries11 = Object.entries(cellStyle.css); _i12 < _Object$entries11.length; _i12++) {
  2782. var _Object$entries11$_i = _slicedToArray(_Object$entries11[_i12], 2),
  2783. _key3 = _Object$entries11$_i[0],
  2784. _value2 = _Object$entries11$_i[1];
  2785. csses_.push("".concat(_key3, ": ").concat(_value2));
  2786. }
  2787. style_ = " style=\"".concat(csses_.concat(_this7.header.styles[j]).join('; '), "\"");
  2788. }
  2789. value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_);
  2790. if (!(column.checkbox || column.radio)) {
  2791. value = typeof value === 'undefined' || value === null ? _this7.options.undefinedText : value;
  2792. }
  2793. if (column.searchable && _this7.searchText && _this7.options.searchHighlight && !(column.checkbox || column.radio)) {
  2794. var defValue = '';
  2795. var searchText = _this7.searchText.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  2796. if (_this7.options.searchAccentNeutralise) {
  2797. var indexRegex = new RegExp("".concat(Utils.normalizeAccent(searchText)), 'gmi');
  2798. var match = indexRegex.exec(Utils.normalizeAccent(value));
  2799. if (match) {
  2800. searchText = value.substring(match.index, match.index + searchText.length);
  2801. }
  2802. }
  2803. var regExp = new RegExp("(".concat(searchText, ")"), 'gim');
  2804. var marker = '<mark>$1</mark>';
  2805. var isHTML = value && /<(?=.*? .*?\/ ?>|br|hr|input|!--|wbr)[a-z]+.*?>|<([a-z]+).*?<\/\1>/i.test(value);
  2806. if (isHTML) {
  2807. // value can contains a HTML tags
  2808. var textContent = new DOMParser().parseFromString(value.toString(), 'text/html').documentElement.textContent;
  2809. var textReplaced = textContent.replace(regExp, marker);
  2810. textContent = textContent.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  2811. defValue = value.replace(new RegExp("(>\\s*)(".concat(textContent, ")(\\s*)"), 'gm'), "$1".concat(textReplaced, "$3"));
  2812. } else {
  2813. // but usually not
  2814. defValue = value.toString().replace(regExp, marker);
  2815. }
  2816. value = Utils.calculateObjectValue(column, column.searchHighlightFormatter, [value, _this7.searchText], defValue);
  2817. }
  2818. if (item["_".concat(field, "_data")] && !Utils.isEmptyObject(item["_".concat(field, "_data")])) {
  2819. for (var _i13 = 0, _Object$entries12 = Object.entries(item["_".concat(field, "_data")]); _i13 < _Object$entries12.length; _i13++) {
  2820. var _Object$entries12$_i = _slicedToArray(_Object$entries12[_i13], 2),
  2821. _k = _Object$entries12$_i[0],
  2822. _v = _Object$entries12$_i[1];
  2823. // ignore data-index
  2824. if (_k === 'index') {
  2825. return;
  2826. }
  2827. data_ += " data-".concat(_k, "=\"").concat(_v, "\"");
  2828. }
  2829. }
  2830. if (column.checkbox || column.radio) {
  2831. type = column.checkbox ? 'checkbox' : type;
  2832. type = column.radio ? 'radio' : type;
  2833. var c = column['class'] || '';
  2834. var isChecked = Utils.isObject(value) && value.hasOwnProperty('checked') ? value.checked : (value === true || value_) && value !== false;
  2835. var isDisabled = !column.checkboxEnabled || value && value.disabled;
  2836. text = [_this7.options.cardView ? "<div class=\"card-view ".concat(c, "\">") : "<td class=\"bs-checkbox ".concat(c, "\"").concat(class_).concat(style_, ">"), "<label>\n <input\n data-index=\"".concat(i, "\"\n name=\"").concat(_this7.options.selectItemName, "\"\n type=\"").concat(type, "\"\n ").concat(Utils.sprintf('value="%s"', item[_this7.options.idField]), "\n ").concat(Utils.sprintf('checked="%s"', isChecked ? 'checked' : undefined), "\n ").concat(Utils.sprintf('disabled="%s"', isDisabled ? 'disabled' : undefined), " />\n <span></span>\n </label>"), _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '</div>' : '</td>'].join('');
  2837. item[_this7.header.stateField] = value === true || !!value_ || value && value.checked;
  2838. } else if (_this7.options.cardView) {
  2839. var cardTitle = _this7.options.showHeader ? "<span class=\"card-view-title ".concat(cellStyle.classes || '', "\"").concat(style_, ">").concat(Utils.getFieldTitle(_this7.columns, field), "</span>") : '';
  2840. text = "<div class=\"card-view\">".concat(cardTitle, "<span class=\"card-view-value ").concat(cellStyle.classes || '', "\"").concat(style_, ">").concat(value, "</span></div>");
  2841. if (_this7.options.smartDisplay && value === '') {
  2842. text = '<div class="card-view"></div>';
  2843. }
  2844. } else {
  2845. text = "<td".concat(id_).concat(class_).concat(style_).concat(data_).concat(rowspan_).concat(colspan_).concat(title_, ">").concat(value, "</td>");
  2846. }
  2847. html.push(text);
  2848. });
  2849. if (detailViewTemplate && this.options.detailViewAlign === 'right') {
  2850. html.push(detailViewTemplate);
  2851. }
  2852. if (this.options.cardView) {
  2853. html.push('</div></td>');
  2854. }
  2855. html.push('</tr>');
  2856. return html.join('');
  2857. }
  2858. }, {
  2859. key: "initBody",
  2860. value: function initBody(fixedScroll, updatedUid) {
  2861. var _this8 = this;
  2862. var data = this.getData();
  2863. this.trigger('pre-body', data);
  2864. this.$body = this.$el.find('>tbody');
  2865. if (!this.$body.length) {
  2866. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  2867. }
  2868. // Fix #389 Bootstrap-table-flatJSON is not working
  2869. if (!this.options.pagination || this.options.sidePagination === 'server') {
  2870. this.pageFrom = 1;
  2871. this.pageTo = data.length;
  2872. }
  2873. var rows = [];
  2874. var trFragments = $(document.createDocumentFragment());
  2875. var hasTr = false;
  2876. var toExpand = [];
  2877. this.autoMergeCells = Utils.checkAutoMergeCells(data.slice(this.pageFrom - 1, this.pageTo));
  2878. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  2879. var item = data[i];
  2880. var tr = this.initRow(item, i, data, trFragments);
  2881. hasTr = hasTr || !!tr;
  2882. if (tr && typeof tr === 'string') {
  2883. var uniqueId = this.options.uniqueId;
  2884. if (uniqueId && item.hasOwnProperty(uniqueId)) {
  2885. var itemUniqueId = item[uniqueId];
  2886. var oldTr = this.$body.find(Utils.sprintf('> tr[data-uniqueid="%s"][data-has-detail-view]', itemUniqueId));
  2887. var oldTrNext = oldTr.next();
  2888. if (oldTrNext.is('tr.detail-view')) {
  2889. toExpand.push(i);
  2890. if (!updatedUid || itemUniqueId !== updatedUid) {
  2891. tr += oldTrNext[0].outerHTML;
  2892. }
  2893. }
  2894. }
  2895. if (!this.options.virtualScroll) {
  2896. trFragments.append(tr);
  2897. } else {
  2898. rows.push(tr);
  2899. }
  2900. }
  2901. }
  2902. // show no records
  2903. if (!hasTr) {
  2904. this.$body.html("<tr class=\"no-records-found\">".concat(Utils.sprintf('<td colspan="%s">%s</td>', this.getVisibleFields().length + Utils.getDetailViewIndexOffset(this.options), this.options.formatNoMatches()), "</tr>"));
  2905. } else if (!this.options.virtualScroll) {
  2906. this.$body.html(trFragments);
  2907. } else {
  2908. if (this.virtualScroll) {
  2909. this.virtualScroll.destroy();
  2910. }
  2911. this.virtualScroll = new VirtualScroll({
  2912. rows: rows,
  2913. fixedScroll: fixedScroll,
  2914. scrollEl: this.$tableBody[0],
  2915. contentEl: this.$body[0],
  2916. itemHeight: this.options.virtualScrollItemHeight,
  2917. callback: function callback(startIndex, endIndex) {
  2918. _this8.fitHeader();
  2919. _this8.initBodyEvent();
  2920. _this8.trigger('virtual-scroll', startIndex, endIndex);
  2921. }
  2922. });
  2923. }
  2924. toExpand.forEach(function (index) {
  2925. _this8.expandRow(index);
  2926. });
  2927. if (!fixedScroll) {
  2928. this.scrollTo(0);
  2929. }
  2930. this.initBodyEvent();
  2931. this.initFooter();
  2932. this.resetView();
  2933. this.updateSelected();
  2934. if (this.options.sidePagination !== 'server') {
  2935. this.options.totalRows = data.length;
  2936. }
  2937. this.trigger('post-body', data);
  2938. }
  2939. }, {
  2940. key: "initBodyEvent",
  2941. value: function initBodyEvent() {
  2942. var _this9 = this;
  2943. // click to select by column
  2944. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
  2945. var $td = $(e.currentTarget);
  2946. if ($td.find('.detail-icon').length || $td.index() - Utils.getDetailViewIndexOffset(_this9.options) < 0) {
  2947. return;
  2948. }
  2949. var $tr = $td.parent();
  2950. var $cardViewArr = $(e.target).parents('.card-views').children();
  2951. var $cardViewTarget = $(e.target).parents('.card-view');
  2952. var rowIndex = $tr.data('index');
  2953. var item = _this9.data[rowIndex];
  2954. var index = _this9.options.cardView ? $cardViewArr.index($cardViewTarget) : $td[0].cellIndex;
  2955. var fields = _this9.getVisibleFields();
  2956. var field = fields[index - Utils.getDetailViewIndexOffset(_this9.options)];
  2957. var column = _this9.columns[_this9.fieldsColumnsIndex[field]];
  2958. var value = Utils.getItemField(item, field, _this9.options.escape, column.escape);
  2959. _this9.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  2960. _this9.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
  2961. // if click to select - then trigger the checkbox/radio click
  2962. if (e.type === 'click' && _this9.options.clickToSelect && column.clickToSelect && !Utils.calculateObjectValue(_this9.options, _this9.options.ignoreClickToSelectOn, [e.target])) {
  2963. var $selectItem = $tr.find(Utils.sprintf('[name="%s"]', _this9.options.selectItemName));
  2964. if ($selectItem.length) {
  2965. $selectItem[0].click();
  2966. }
  2967. }
  2968. if (e.type === 'click' && _this9.options.detailViewByClick) {
  2969. _this9.toggleDetailView(rowIndex, _this9.header.detailFormatters[_this9.fieldsColumnsIndex[field]]);
  2970. }
  2971. }).off('mousedown').on('mousedown', function (e) {
  2972. // https://github.com/jquery/jquery/issues/1741
  2973. _this9.multipleSelectRowCtrlKey = e.ctrlKey || e.metaKey;
  2974. _this9.multipleSelectRowShiftKey = e.shiftKey;
  2975. });
  2976. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) {
  2977. e.preventDefault();
  2978. _this9.toggleDetailView($(e.currentTarget).parent().parent().data('index'));
  2979. return false;
  2980. });
  2981. this.$selectItem = this.$body.find(Utils.sprintf('[name="%s"]', this.options.selectItemName));
  2982. this.$selectItem.off('click').on('click', function (e) {
  2983. e.stopImmediatePropagation();
  2984. var $this = $(e.currentTarget);
  2985. _this9._toggleCheck($this.prop('checked'), $this.data('index'));
  2986. });
  2987. this.header.events.forEach(function (_events, i) {
  2988. var events = _events;
  2989. if (!events) {
  2990. return;
  2991. }
  2992. // fix bug, if events is defined with namespace
  2993. if (typeof events === 'string') {
  2994. events = Utils.calculateObjectValue(null, events);
  2995. }
  2996. if (!events) {
  2997. throw new Error("Unknown event in the scope: ".concat(_events));
  2998. }
  2999. var field = _this9.header.fields[i];
  3000. var fieldIndex = _this9.getVisibleFields().indexOf(field);
  3001. if (fieldIndex === -1) {
  3002. return;
  3003. }
  3004. fieldIndex += Utils.getDetailViewIndexOffset(_this9.options);
  3005. var _loop3 = function _loop3(key) {
  3006. if (!events.hasOwnProperty(key)) {
  3007. return 1; // continue
  3008. }
  3009. var event = events[key];
  3010. _this9.$body.find('>tr:not(.no-records-found)').each(function (i, tr) {
  3011. var $tr = $(tr);
  3012. var $td = $tr.find(_this9.options.cardView ? '.card-views>.card-view' : '>td').eq(fieldIndex);
  3013. var index = key.indexOf(' ');
  3014. var name = key.substring(0, index);
  3015. var el = key.substring(index + 1);
  3016. $td.find(el).off(name).on(name, function (e) {
  3017. var index = $tr.data('index');
  3018. var row = _this9.data[index];
  3019. var value = row[field];
  3020. event.apply(_this9, [e, value, row, index]);
  3021. });
  3022. });
  3023. };
  3024. for (var key in events) {
  3025. if (_loop3(key)) continue;
  3026. }
  3027. });
  3028. }
  3029. }, {
  3030. key: "initServer",
  3031. value: function initServer(silent, query, url) {
  3032. var _this10 = this;
  3033. var data = {};
  3034. var index = this.header.fields.indexOf(this.options.sortName);
  3035. var params = {
  3036. searchText: this.searchText,
  3037. sortName: this.options.sortName,
  3038. sortOrder: this.options.sortOrder
  3039. };
  3040. if (this.header.sortNames[index]) {
  3041. params.sortName = this.header.sortNames[index];
  3042. }
  3043. if (this.options.pagination && this.options.sidePagination === 'server') {
  3044. params.pageSize = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize;
  3045. params.pageNumber = this.options.pageNumber;
  3046. }
  3047. if (!(url || this.options.url) && !this.options.ajax) {
  3048. return;
  3049. }
  3050. if (this.options.queryParamsType === 'limit') {
  3051. params = {
  3052. search: params.searchText,
  3053. sort: params.sortName,
  3054. order: params.sortOrder
  3055. };
  3056. if (this.options.pagination && this.options.sidePagination === 'server') {
  3057. params.offset = this.options.pageSize === this.options.formatAllRows() ? 0 : this.options.pageSize * (this.options.pageNumber - 1);
  3058. params.limit = this.options.pageSize;
  3059. if (params.limit === 0 || this.options.pageSize === this.options.formatAllRows()) {
  3060. delete params.limit;
  3061. }
  3062. }
  3063. }
  3064. if (this.options.search && this.options.sidePagination === 'server' && this.options.searchable && this.columns.filter(function (column) {
  3065. return column.searchable;
  3066. }).length) {
  3067. params.searchable = [];
  3068. var _iterator2 = _createForOfIteratorHelper(this.columns),
  3069. _step2;
  3070. try {
  3071. for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
  3072. var column = _step2.value;
  3073. if (!column.checkbox && column.searchable && (this.options.visibleSearch && column.visible || !this.options.visibleSearch)) {
  3074. params.searchable.push(column.field);
  3075. }
  3076. }
  3077. } catch (err) {
  3078. _iterator2.e(err);
  3079. } finally {
  3080. _iterator2.f();
  3081. }
  3082. }
  3083. if (!Utils.isEmptyObject(this.filterColumnsPartial)) {
  3084. params.filter = JSON.stringify(this.filterColumnsPartial, null);
  3085. }
  3086. Utils.extend(params, query || {});
  3087. data = Utils.calculateObjectValue(this.options, this.options.queryParams, [params], data);
  3088. // false to stop request
  3089. if (data === false) {
  3090. return;
  3091. }
  3092. if (!silent) {
  3093. this.showLoading();
  3094. }
  3095. var request = Utils.extend({}, Utils.calculateObjectValue(null, this.options.ajaxOptions), {
  3096. type: this.options.method,
  3097. url: url || this.options.url,
  3098. data: this.options.contentType === 'application/json' && this.options.method === 'post' ? JSON.stringify(data) : data,
  3099. cache: this.options.cache,
  3100. contentType: this.options.contentType,
  3101. dataType: this.options.dataType,
  3102. success: function success(_res, textStatus, jqXHR) {
  3103. var res = Utils.calculateObjectValue(_this10.options, _this10.options.responseHandler, [_res, jqXHR], _res);
  3104. if (_this10.options.sidePagination === 'client' && _this10.options.paginationLoadMore) {
  3105. _this10._paginationLoaded = _this10.data.length === res.length;
  3106. }
  3107. _this10.load(res);
  3108. _this10.trigger('load-success', res, jqXHR && jqXHR.status, jqXHR);
  3109. if (!silent) {
  3110. _this10.hideLoading();
  3111. }
  3112. if (_this10.options.sidePagination === 'server' && _this10.options.pageNumber > 1 && res[_this10.options.totalField] > 0 && !res[_this10.options.dataField].length) {
  3113. _this10.updatePagination();
  3114. }
  3115. },
  3116. error: function error(jqXHR) {
  3117. // abort ajax by multiple request
  3118. if (jqXHR && jqXHR.status === 0 && _this10._xhrAbort) {
  3119. _this10._xhrAbort = false;
  3120. return;
  3121. }
  3122. var data = [];
  3123. if (_this10.options.sidePagination === 'server') {
  3124. data = {};
  3125. data[_this10.options.totalField] = 0;
  3126. data[_this10.options.dataField] = [];
  3127. }
  3128. _this10.load(data);
  3129. _this10.trigger('load-error', jqXHR && jqXHR.status, jqXHR);
  3130. if (!silent) {
  3131. _this10.hideLoading();
  3132. }
  3133. }
  3134. });
  3135. if (this.options.ajax) {
  3136. Utils.calculateObjectValue(this, this.options.ajax, [request], null);
  3137. } else {
  3138. if (this._xhr && this._xhr.readyState !== 4) {
  3139. this._xhrAbort = true;
  3140. this._xhr.abort();
  3141. }
  3142. this._xhr = $.ajax(request);
  3143. }
  3144. return data;
  3145. }
  3146. }, {
  3147. key: "initSearchText",
  3148. value: function initSearchText() {
  3149. if (this.options.search) {
  3150. this.searchText = '';
  3151. if (this.options.searchText !== '') {
  3152. var $search = Utils.getSearchInput(this);
  3153. $search.val(this.options.searchText);
  3154. this.onSearch({
  3155. currentTarget: $search,
  3156. firedByInitSearchText: true
  3157. });
  3158. }
  3159. }
  3160. }
  3161. }, {
  3162. key: "getCaret",
  3163. value: function getCaret() {
  3164. var _this11 = this;
  3165. this.$header.find('th').each(function (i, th) {
  3166. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === _this11.options.sortName ? _this11.options.sortOrder : 'both');
  3167. });
  3168. }
  3169. }, {
  3170. key: "updateSelected",
  3171. value: function updateSelected() {
  3172. var checkAll = this.$selectItem.filter(':enabled').length && this.$selectItem.filter(':enabled').length === this.$selectItem.filter(':enabled').filter(':checked').length;
  3173. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  3174. this.$selectItem.each(function (i, el) {
  3175. $(el).closest('tr')[$(el).prop('checked') ? 'addClass' : 'removeClass']('selected');
  3176. });
  3177. }
  3178. }, {
  3179. key: "updateRows",
  3180. value: function updateRows() {
  3181. var _this12 = this;
  3182. this.$selectItem.each(function (i, el) {
  3183. _this12.data[$(el).data('index')][_this12.header.stateField] = $(el).prop('checked');
  3184. });
  3185. }
  3186. }, {
  3187. key: "resetRows",
  3188. value: function resetRows() {
  3189. var _iterator3 = _createForOfIteratorHelper(this.data),
  3190. _step3;
  3191. try {
  3192. for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
  3193. var row = _step3.value;
  3194. this.$selectAll.prop('checked', false);
  3195. this.$selectItem.prop('checked', false);
  3196. if (this.header.stateField) {
  3197. row[this.header.stateField] = false;
  3198. }
  3199. }
  3200. } catch (err) {
  3201. _iterator3.e(err);
  3202. } finally {
  3203. _iterator3.f();
  3204. }
  3205. this.initHiddenRows();
  3206. }
  3207. }, {
  3208. key: "trigger",
  3209. value: function trigger(_name) {
  3210. var _this$options, _this$options2;
  3211. var name = "".concat(_name, ".bs.table");
  3212. for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key4 = 1; _key4 < _len; _key4++) {
  3213. args[_key4 - 1] = arguments[_key4];
  3214. }
  3215. (_this$options = this.options)[BootstrapTable.EVENTS[name]].apply(_this$options, [].concat(args, [this]));
  3216. this.$el.trigger($.Event(name, {
  3217. sender: this
  3218. }), args);
  3219. (_this$options2 = this.options).onAll.apply(_this$options2, [name].concat([].concat(args, [this])));
  3220. this.$el.trigger($.Event('all.bs.table', {
  3221. sender: this
  3222. }), [name, args]);
  3223. }
  3224. }, {
  3225. key: "resetHeader",
  3226. value: function resetHeader() {
  3227. var _this13 = this;
  3228. // fix #61: the hidden table reset header bug.
  3229. // fix bug: get $el.css('width') error sometime (height = 500)
  3230. clearTimeout(this.timeoutId_);
  3231. this.timeoutId_ = setTimeout(function () {
  3232. return _this13.fitHeader();
  3233. }, this.$el.is(':hidden') ? 100 : 0);
  3234. }
  3235. }, {
  3236. key: "fitHeader",
  3237. value: function fitHeader() {
  3238. var _this14 = this;
  3239. if (this.$el.is(':hidden')) {
  3240. this.timeoutId_ = setTimeout(function () {
  3241. return _this14.fitHeader();
  3242. }, 100);
  3243. return;
  3244. }
  3245. var fixedBody = this.$tableBody.get(0);
  3246. var scrollWidth = this.hasScrollBar && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0;
  3247. this.$el.css('margin-top', -this.$header.outerHeight());
  3248. var focused = this.$tableHeader.find(':focus');
  3249. if (focused.length > 0) {
  3250. var $th = focused.parents('th');
  3251. if ($th.length > 0) {
  3252. var dataField = $th.attr('data-field');
  3253. if (dataField !== undefined) {
  3254. var $headerTh = this.$header.find("[data-field='".concat(dataField, "']"));
  3255. if ($headerTh.length > 0) {
  3256. $headerTh.find(':input').addClass('focus-temp');
  3257. }
  3258. }
  3259. }
  3260. }
  3261. this.$header_ = this.$header.clone(true, true);
  3262. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  3263. this.$tableHeader.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).html('').attr('class', this.$el.attr('class')).append(this.$header_);
  3264. this.$tableLoading.css('width', this.$el.outerWidth());
  3265. var focusedTemp = $('.focus-temp:visible:eq(0)');
  3266. if (focusedTemp.length > 0) {
  3267. focusedTemp.focus();
  3268. this.$header.find('.focus-temp').removeClass('focus-temp');
  3269. }
  3270. // fix bug: $.data() is not working as expected after $.append()
  3271. this.$header.find('th[data-field]').each(function (i, el) {
  3272. _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', $(el).data('field'))).data($(el).data());
  3273. });
  3274. var visibleFields = this.getVisibleFields();
  3275. var $ths = this.$header_.find('th');
  3276. var $tr = this.$body.find('>tr:not(.no-records-found,.virtual-scroll-top)').eq(0);
  3277. while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) {
  3278. $tr = $tr.next();
  3279. }
  3280. var trLength = $tr.find('> *').length;
  3281. $tr.find('> *').each(function (i, el) {
  3282. var $this = $(el);
  3283. if (Utils.hasDetailViewIcon(_this14.options)) {
  3284. if (i === 0 && _this14.options.detailViewAlign !== 'right' || i === trLength - 1 && _this14.options.detailViewAlign === 'right') {
  3285. var $thDetail = $ths.filter('.detail');
  3286. var _zoomWidth = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width();
  3287. $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth);
  3288. return;
  3289. }
  3290. }
  3291. var index = i - Utils.getDetailViewIndexOffset(_this14.options);
  3292. var $th = _this14.$header_.find(Utils.sprintf('th[data-field="%s"]', visibleFields[index]));
  3293. if ($th.length > 1) {
  3294. $th = $($ths[$this[0].cellIndex]);
  3295. }
  3296. var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width();
  3297. $th.find('.fht-cell').width($this.innerWidth() - zoomWidth);
  3298. });
  3299. this.horizontalScroll();
  3300. this.trigger('post-header');
  3301. }
  3302. }, {
  3303. key: "initFooter",
  3304. value: function initFooter() {
  3305. if (!this.options.showFooter || this.options.cardView) {
  3306. // do nothing
  3307. return;
  3308. }
  3309. var data = this.getData();
  3310. var html = [];
  3311. var detailTemplate = '';
  3312. if (Utils.hasDetailViewIcon(this.options)) {
  3313. detailTemplate = '<th class="detail"><div class="th-inner"></div><div class="fht-cell"></div></th>';
  3314. }
  3315. if (detailTemplate && this.options.detailViewAlign !== 'right') {
  3316. html.push(detailTemplate);
  3317. }
  3318. var _iterator4 = _createForOfIteratorHelper(this.columns),
  3319. _step4;
  3320. try {
  3321. for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
  3322. var column = _step4.value;
  3323. var falign = '';
  3324. var valign = '';
  3325. var csses = [];
  3326. var style = {};
  3327. var class_ = Utils.sprintf(' class="%s"', column['class']);
  3328. if (!column.visible || this.footerData && this.footerData.length > 0 && !(column.field in this.footerData[0])) {
  3329. continue;
  3330. }
  3331. if (this.options.cardView && !column.cardVisible) {
  3332. return;
  3333. }
  3334. falign = Utils.sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  3335. valign = Utils.sprintf('vertical-align: %s; ', column.valign);
  3336. style = Utils.calculateObjectValue(null, column.footerStyle || this.options.footerStyle, [column]);
  3337. if (style && style.css) {
  3338. for (var _i14 = 0, _Object$entries13 = Object.entries(style.css); _i14 < _Object$entries13.length; _i14++) {
  3339. var _Object$entries13$_i = _slicedToArray(_Object$entries13[_i14], 2),
  3340. key = _Object$entries13$_i[0],
  3341. _value3 = _Object$entries13$_i[1];
  3342. csses.push("".concat(key, ": ").concat(_value3));
  3343. }
  3344. }
  3345. if (style && style.classes) {
  3346. class_ = Utils.sprintf(' class="%s"', column['class'] ? [column['class'], style.classes].join(' ') : style.classes);
  3347. }
  3348. html.push('<th', class_, Utils.sprintf(' style="%s"', falign + valign + csses.concat().join('; ') || undefined));
  3349. var colspan = 0;
  3350. if (this.footerData && this.footerData.length > 0) {
  3351. colspan = this.footerData[0]["_".concat(column.field, "_colspan")] || 0;
  3352. }
  3353. if (colspan) {
  3354. html.push(" colspan=\"".concat(colspan, "\" "));
  3355. }
  3356. html.push('>');
  3357. html.push('<div class="th-inner">');
  3358. var value = '';
  3359. if (this.footerData && this.footerData.length > 0) {
  3360. value = this.footerData[0][column.field] || '';
  3361. }
  3362. html.push(Utils.calculateObjectValue(column, column.footerFormatter, [data, value], value));
  3363. html.push('</div>');
  3364. html.push('<div class="fht-cell"></div>');
  3365. html.push('</div>');
  3366. html.push('</th>');
  3367. }
  3368. } catch (err) {
  3369. _iterator4.e(err);
  3370. } finally {
  3371. _iterator4.f();
  3372. }
  3373. if (detailTemplate && this.options.detailViewAlign === 'right') {
  3374. html.push(detailTemplate);
  3375. }
  3376. if (!this.options.height && !this.$tableFooter.length) {
  3377. this.$el.append('<tfoot><tr></tr></tfoot>');
  3378. this.$tableFooter = this.$el.find('tfoot');
  3379. }
  3380. if (!this.$tableFooter.find('tr').length) {
  3381. this.$tableFooter.html('<table><thead><tr></tr></thead></table>');
  3382. }
  3383. this.$tableFooter.find('tr').html(html.join(''));
  3384. this.trigger('post-footer', this.$tableFooter);
  3385. }
  3386. }, {
  3387. key: "fitFooter",
  3388. value: function fitFooter() {
  3389. var _this15 = this;
  3390. if (this.$el.is(':hidden')) {
  3391. setTimeout(function () {
  3392. return _this15.fitFooter();
  3393. }, 100);
  3394. return;
  3395. }
  3396. var fixedBody = this.$tableBody.get(0);
  3397. var scrollWidth = this.hasScrollBar && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0;
  3398. this.$tableFooter.css('margin-right', scrollWidth).find('table').css('width', this.$el.outerWidth()).attr('class', this.$el.attr('class'));
  3399. var $ths = this.$tableFooter.find('th');
  3400. var $tr = this.$body.find('>tr:first-child:not(.no-records-found)');
  3401. $ths.find('.fht-cell').width('auto');
  3402. while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) {
  3403. $tr = $tr.next();
  3404. }
  3405. var trLength = $tr.find('> *').length;
  3406. $tr.find('> *').each(function (i, el) {
  3407. var $this = $(el);
  3408. if (Utils.hasDetailViewIcon(_this15.options)) {
  3409. if (i === 0 && _this15.options.detailViewAlign === 'left' || i === trLength - 1 && _this15.options.detailViewAlign === 'right') {
  3410. var $thDetail = $ths.filter('.detail');
  3411. var _zoomWidth2 = $thDetail.innerWidth() - $thDetail.find('.fht-cell').width();
  3412. $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth2);
  3413. return;
  3414. }
  3415. }
  3416. var $th = $ths.eq(i);
  3417. var zoomWidth = $th.innerWidth() - $th.find('.fht-cell').width();
  3418. $th.find('.fht-cell').width($this.innerWidth() - zoomWidth);
  3419. });
  3420. this.horizontalScroll();
  3421. }
  3422. }, {
  3423. key: "horizontalScroll",
  3424. value: function horizontalScroll() {
  3425. var _this16 = this;
  3426. // horizontal scroll event
  3427. // TODO: it's probably better improving the layout than binding to scroll event
  3428. this.$tableBody.off('scroll').on('scroll', function () {
  3429. var scrollLeft = _this16.$tableBody.scrollLeft();
  3430. if (_this16.options.showHeader && _this16.options.height) {
  3431. _this16.$tableHeader.scrollLeft(scrollLeft);
  3432. }
  3433. if (_this16.options.showFooter && !_this16.options.cardView) {
  3434. _this16.$tableFooter.scrollLeft(scrollLeft);
  3435. }
  3436. _this16.trigger('scroll-body', _this16.$tableBody);
  3437. });
  3438. }
  3439. }, {
  3440. key: "getVisibleFields",
  3441. value: function getVisibleFields() {
  3442. var visibleFields = [];
  3443. var _iterator5 = _createForOfIteratorHelper(this.header.fields),
  3444. _step5;
  3445. try {
  3446. for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
  3447. var field = _step5.value;
  3448. var column = this.columns[this.fieldsColumnsIndex[field]];
  3449. if (!column || !column.visible || this.options.cardView && !column.cardVisible) {
  3450. continue;
  3451. }
  3452. visibleFields.push(field);
  3453. }
  3454. } catch (err) {
  3455. _iterator5.e(err);
  3456. } finally {
  3457. _iterator5.f();
  3458. }
  3459. return visibleFields;
  3460. }
  3461. }, {
  3462. key: "initHiddenRows",
  3463. value: function initHiddenRows() {
  3464. this.hiddenRows = [];
  3465. }
  3466. // PUBLIC FUNCTION DEFINITION
  3467. // =======================
  3468. }, {
  3469. key: "getOptions",
  3470. value: function getOptions() {
  3471. // deep copy and remove data
  3472. var options = Utils.extend({}, this.options);
  3473. delete options.data;
  3474. return Utils.extend(true, {}, options);
  3475. }
  3476. }, {
  3477. key: "refreshOptions",
  3478. value: function refreshOptions(options) {
  3479. // If the objects are equivalent then avoid the call of destroy / init methods
  3480. if (Utils.compareObjects(this.options, options, true)) {
  3481. return;
  3482. }
  3483. this.options = Utils.extend(this.options, options);
  3484. this.trigger('refresh-options', this.options);
  3485. this.destroy();
  3486. this.init();
  3487. }
  3488. }, {
  3489. key: "getData",
  3490. value: function getData(params) {
  3491. var _this17 = this;
  3492. var data = this.options.data;
  3493. if ((this.searchText || this.options.customSearch || this.options.sortName !== undefined || this.enableCustomSort ||
  3494. // Fix #4616: this.enableCustomSort is for extensions
  3495. !Utils.isEmptyObject(this.filterColumns) || typeof this.options.filterOptions.filterAlgorithm === 'function' || !Utils.isEmptyObject(this.filterColumnsPartial)) && (!params || !params.unfiltered)) {
  3496. data = this.data;
  3497. }
  3498. if (params && !params.includeHiddenRows) {
  3499. var hiddenRows = this.getHiddenRows();
  3500. data = data.filter(function (row) {
  3501. return Utils.findIndex(hiddenRows, row) === -1;
  3502. });
  3503. }
  3504. if (params && params.useCurrentPage) {
  3505. data = data.slice(this.pageFrom - 1, this.pageTo);
  3506. }
  3507. if (params && params.formatted) {
  3508. return data.map(function (row) {
  3509. for (var _i15 = 0, _Object$entries14 = Object.entries(row); _i15 < _Object$entries14.length; _i15++) {
  3510. var _Object$entries14$_i = _slicedToArray(_Object$entries14[_i15], 2),
  3511. key = _Object$entries14$_i[0],
  3512. value = _Object$entries14$_i[1];
  3513. var column = _this17.columns[_this17.fieldsColumnsIndex[key]];
  3514. if (!column) {
  3515. continue;
  3516. }
  3517. return Utils.calculateObjectValue(column, _this17.header.formatters[column.fieldIndex], [value, row, row.index, column.field], value);
  3518. }
  3519. });
  3520. }
  3521. return data;
  3522. }
  3523. }, {
  3524. key: "getSelections",
  3525. value: function getSelections() {
  3526. var _this18 = this;
  3527. return (this.options.maintainMetaData ? this.options.data : this.data).filter(function (row) {
  3528. return row[_this18.header.stateField] === true;
  3529. });
  3530. }
  3531. }, {
  3532. key: "load",
  3533. value: function load(_data) {
  3534. var fixedScroll = false;
  3535. var data = _data;
  3536. // #431: support pagination
  3537. if (this.options.pagination && this.options.sidePagination === 'server') {
  3538. this.options.totalRows = data[this.options.totalField];
  3539. this.options.totalNotFiltered = data[this.options.totalNotFilteredField];
  3540. this.footerData = data[this.options.footerField] ? [data[this.options.footerField]] : undefined;
  3541. }
  3542. fixedScroll = this.options.fixedScroll || data.fixedScroll;
  3543. data = Array.isArray(data) ? data : data[this.options.dataField];
  3544. this.initData(data);
  3545. this.initSearch();
  3546. this.initPagination();
  3547. this.initBody(fixedScroll);
  3548. }
  3549. }, {
  3550. key: "append",
  3551. value: function append(data) {
  3552. this.initData(data, 'append');
  3553. this.initSearch();
  3554. this.initPagination();
  3555. this.initSort();
  3556. this.initBody(true);
  3557. }
  3558. }, {
  3559. key: "prepend",
  3560. value: function prepend(data) {
  3561. this.initData(data, 'prepend');
  3562. this.initSearch();
  3563. this.initPagination();
  3564. this.initSort();
  3565. this.initBody(true);
  3566. }
  3567. }, {
  3568. key: "remove",
  3569. value: function remove(params) {
  3570. var removed = 0;
  3571. for (var i = this.options.data.length - 1; i >= 0; i--) {
  3572. var row = this.options.data[i];
  3573. var value = Utils.getItemField(row, params.field, this.options.escape, row.escape);
  3574. if (value === undefined && params.field !== '$index') {
  3575. continue;
  3576. }
  3577. if (!row.hasOwnProperty(params.field) && params.field === '$index' && params.values.includes(i) || params.values.includes(value)) {
  3578. removed++;
  3579. this.options.data.splice(i, 1);
  3580. }
  3581. }
  3582. if (!removed) {
  3583. return;
  3584. }
  3585. if (this.options.sidePagination === 'server') {
  3586. this.options.totalRows -= removed;
  3587. this.data = _toConsumableArray(this.options.data);
  3588. }
  3589. this.initSearch();
  3590. this.initPagination();
  3591. this.initSort();
  3592. this.initBody(true);
  3593. }
  3594. }, {
  3595. key: "removeAll",
  3596. value: function removeAll() {
  3597. if (this.options.data.length > 0) {
  3598. this.options.data.splice(0, this.options.data.length);
  3599. this.initSearch();
  3600. this.initPagination();
  3601. this.initBody(true);
  3602. }
  3603. }
  3604. }, {
  3605. key: "insertRow",
  3606. value: function insertRow(params) {
  3607. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  3608. return;
  3609. }
  3610. this.options.data.splice(params.index, 0, params.row);
  3611. this.initSearch();
  3612. this.initPagination();
  3613. this.initSort();
  3614. this.initBody(true);
  3615. }
  3616. }, {
  3617. key: "updateRow",
  3618. value: function updateRow(params) {
  3619. var allParams = Array.isArray(params) ? params : [params];
  3620. var _iterator6 = _createForOfIteratorHelper(allParams),
  3621. _step6;
  3622. try {
  3623. for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
  3624. var _params = _step6.value;
  3625. if (!_params.hasOwnProperty('index') || !_params.hasOwnProperty('row')) {
  3626. continue;
  3627. }
  3628. if (_params.hasOwnProperty('replace') && _params.replace) {
  3629. this.options.data[_params.index] = _params.row;
  3630. } else {
  3631. Utils.extend(this.options.data[_params.index], _params.row);
  3632. }
  3633. }
  3634. } catch (err) {
  3635. _iterator6.e(err);
  3636. } finally {
  3637. _iterator6.f();
  3638. }
  3639. this.initSearch();
  3640. this.initPagination();
  3641. this.initSort();
  3642. this.initBody(true);
  3643. }
  3644. }, {
  3645. key: "getRowByUniqueId",
  3646. value: function getRowByUniqueId(_id) {
  3647. var uniqueId = this.options.uniqueId;
  3648. var len = this.options.data.length;
  3649. var id = _id;
  3650. var dataRow = null;
  3651. var i;
  3652. var row;
  3653. for (i = len - 1; i >= 0; i--) {
  3654. row = this.options.data[i];
  3655. var rowUniqueId = Utils.getItemField(row, uniqueId, this.options.escape, row.escape);
  3656. if (rowUniqueId === undefined) {
  3657. continue;
  3658. }
  3659. if (typeof rowUniqueId === 'string') {
  3660. id = _id.toString();
  3661. } else if (typeof rowUniqueId === 'number') {
  3662. if (Number(rowUniqueId) === rowUniqueId && rowUniqueId % 1 === 0) {
  3663. id = parseInt(_id, 10);
  3664. } else if (rowUniqueId === Number(rowUniqueId) && rowUniqueId !== 0) {
  3665. id = parseFloat(_id);
  3666. }
  3667. }
  3668. if (rowUniqueId === id) {
  3669. dataRow = row;
  3670. break;
  3671. }
  3672. }
  3673. return dataRow;
  3674. }
  3675. }, {
  3676. key: "updateByUniqueId",
  3677. value: function updateByUniqueId(params) {
  3678. var allParams = Array.isArray(params) ? params : [params];
  3679. var updatedUid = null;
  3680. var _iterator7 = _createForOfIteratorHelper(allParams),
  3681. _step7;
  3682. try {
  3683. for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
  3684. var _params2 = _step7.value;
  3685. if (!_params2.hasOwnProperty('id') || !_params2.hasOwnProperty('row')) {
  3686. continue;
  3687. }
  3688. var rowId = this.options.data.indexOf(this.getRowByUniqueId(_params2.id));
  3689. if (rowId === -1) {
  3690. continue;
  3691. }
  3692. if (_params2.hasOwnProperty('replace') && _params2.replace) {
  3693. this.options.data[rowId] = _params2.row;
  3694. } else {
  3695. Utils.extend(this.options.data[rowId], _params2.row);
  3696. }
  3697. updatedUid = _params2.id;
  3698. }
  3699. } catch (err) {
  3700. _iterator7.e(err);
  3701. } finally {
  3702. _iterator7.f();
  3703. }
  3704. this.initSearch();
  3705. this.initPagination();
  3706. this.initSort();
  3707. this.initBody(true, updatedUid);
  3708. }
  3709. }, {
  3710. key: "removeByUniqueId",
  3711. value: function removeByUniqueId(id) {
  3712. var len = this.options.data.length;
  3713. var row = this.getRowByUniqueId(id);
  3714. if (row) {
  3715. this.options.data.splice(this.options.data.indexOf(row), 1);
  3716. }
  3717. if (len === this.options.data.length) {
  3718. return;
  3719. }
  3720. if (this.options.sidePagination === 'server') {
  3721. this.options.totalRows -= 1;
  3722. this.data = _toConsumableArray(this.options.data);
  3723. }
  3724. this.initSearch();
  3725. this.initPagination();
  3726. this.initBody(true);
  3727. }
  3728. }, {
  3729. key: "_updateCellOnly",
  3730. value: function _updateCellOnly(field, index) {
  3731. var rowHtml = this.initRow(this.options.data[index], index);
  3732. var fieldIndex = this.getVisibleFields().indexOf(field);
  3733. if (fieldIndex === -1) {
  3734. return;
  3735. }
  3736. fieldIndex += Utils.getDetailViewIndexOffset(this.options);
  3737. this.$body.find(">tr[data-index=".concat(index, "]")).find(">td:eq(".concat(fieldIndex, ")")).replaceWith($(rowHtml).find(">td:eq(".concat(fieldIndex, ")")));
  3738. this.initBodyEvent();
  3739. this.initFooter();
  3740. this.resetView();
  3741. this.updateSelected();
  3742. }
  3743. }, {
  3744. key: "updateCell",
  3745. value: function updateCell(params) {
  3746. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) {
  3747. return;
  3748. }
  3749. this.options.data[params.index][params.field] = params.value;
  3750. if (params.reinit === false) {
  3751. this._updateCellOnly(params.field, params.index);
  3752. return;
  3753. }
  3754. this.initSort();
  3755. this.initBody(true);
  3756. }
  3757. }, {
  3758. key: "updateCellByUniqueId",
  3759. value: function updateCellByUniqueId(params) {
  3760. var _this19 = this;
  3761. var allParams = Array.isArray(params) ? params : [params];
  3762. allParams.forEach(function (_ref6) {
  3763. var id = _ref6.id,
  3764. field = _ref6.field,
  3765. value = _ref6.value;
  3766. var index = _this19.options.data.indexOf(_this19.getRowByUniqueId(id));
  3767. if (index === -1) {
  3768. return;
  3769. }
  3770. _this19.options.data[index][field] = value;
  3771. });
  3772. if (params.reinit === false) {
  3773. this._updateCellOnly(params.field, this.options.data.indexOf(this.getRowByUniqueId(params.id)));
  3774. return;
  3775. }
  3776. this.initSort();
  3777. this.initBody(true);
  3778. }
  3779. }, {
  3780. key: "showRow",
  3781. value: function showRow(params) {
  3782. this._toggleRow(params, true);
  3783. }
  3784. }, {
  3785. key: "hideRow",
  3786. value: function hideRow(params) {
  3787. this._toggleRow(params, false);
  3788. }
  3789. }, {
  3790. key: "_toggleRow",
  3791. value: function _toggleRow(params, visible) {
  3792. var row;
  3793. if (params.hasOwnProperty('index')) {
  3794. row = this.getData()[params.index];
  3795. } else if (params.hasOwnProperty('uniqueId')) {
  3796. row = this.getRowByUniqueId(params.uniqueId);
  3797. }
  3798. if (!row) {
  3799. return;
  3800. }
  3801. var index = Utils.findIndex(this.hiddenRows, row);
  3802. if (!visible && index === -1) {
  3803. this.hiddenRows.push(row);
  3804. } else if (visible && index > -1) {
  3805. this.hiddenRows.splice(index, 1);
  3806. }
  3807. this.initBody(true);
  3808. this.initPagination();
  3809. }
  3810. }, {
  3811. key: "getHiddenRows",
  3812. value: function getHiddenRows(show) {
  3813. if (show) {
  3814. this.initHiddenRows();
  3815. this.initBody(true);
  3816. this.initPagination();
  3817. return;
  3818. }
  3819. var data = this.getData();
  3820. var rows = [];
  3821. var _iterator8 = _createForOfIteratorHelper(data),
  3822. _step8;
  3823. try {
  3824. for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
  3825. var row = _step8.value;
  3826. if (this.hiddenRows.includes(row)) {
  3827. rows.push(row);
  3828. }
  3829. }
  3830. } catch (err) {
  3831. _iterator8.e(err);
  3832. } finally {
  3833. _iterator8.f();
  3834. }
  3835. this.hiddenRows = rows;
  3836. return rows;
  3837. }
  3838. }, {
  3839. key: "showColumn",
  3840. value: function showColumn(field) {
  3841. var _this20 = this;
  3842. var fields = Array.isArray(field) ? field : [field];
  3843. fields.forEach(function (field) {
  3844. _this20._toggleColumn(_this20.fieldsColumnsIndex[field], true, true);
  3845. });
  3846. }
  3847. }, {
  3848. key: "hideColumn",
  3849. value: function hideColumn(field) {
  3850. var _this21 = this;
  3851. var fields = Array.isArray(field) ? field : [field];
  3852. fields.forEach(function (field) {
  3853. _this21._toggleColumn(_this21.fieldsColumnsIndex[field], false, true);
  3854. });
  3855. }
  3856. }, {
  3857. key: "_toggleColumn",
  3858. value: function _toggleColumn(index, checked, needUpdate) {
  3859. if (index === undefined || this.columns[index].visible === checked) {
  3860. return;
  3861. }
  3862. this.columns[index].visible = checked;
  3863. this.initHeader();
  3864. this.initSearch();
  3865. this.initPagination();
  3866. this.initBody();
  3867. if (this.options.showColumns) {
  3868. var $items = this.$toolbar.find('.keep-open input:not(".toggle-all")').prop('disabled', false);
  3869. if (needUpdate) {
  3870. $items.filter(Utils.sprintf('[value="%s"]', index)).prop('checked', checked);
  3871. }
  3872. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  3873. $items.filter(':checked').prop('disabled', true);
  3874. }
  3875. }
  3876. }
  3877. }, {
  3878. key: "getVisibleColumns",
  3879. value: function getVisibleColumns() {
  3880. var _this22 = this;
  3881. return this.columns.filter(function (column) {
  3882. return column.visible && !_this22.isSelectionColumn(column);
  3883. });
  3884. }
  3885. }, {
  3886. key: "getHiddenColumns",
  3887. value: function getHiddenColumns() {
  3888. return this.columns.filter(function (_ref7) {
  3889. var visible = _ref7.visible;
  3890. return !visible;
  3891. });
  3892. }
  3893. }, {
  3894. key: "isSelectionColumn",
  3895. value: function isSelectionColumn(column) {
  3896. return column.radio || column.checkbox;
  3897. }
  3898. }, {
  3899. key: "showAllColumns",
  3900. value: function showAllColumns() {
  3901. this._toggleAllColumns(true);
  3902. }
  3903. }, {
  3904. key: "hideAllColumns",
  3905. value: function hideAllColumns() {
  3906. this._toggleAllColumns(false);
  3907. }
  3908. }, {
  3909. key: "_toggleAllColumns",
  3910. value: function _toggleAllColumns(visible) {
  3911. var _this23 = this;
  3912. var _iterator9 = _createForOfIteratorHelper(this.columns.slice().reverse()),
  3913. _step9;
  3914. try {
  3915. for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
  3916. var column = _step9.value;
  3917. if (column.switchable) {
  3918. if (!visible && this.options.showColumns && this.getVisibleColumns().filter(function (it) {
  3919. return it.switchable;
  3920. }).length === this.options.minimumCountColumns) {
  3921. continue;
  3922. }
  3923. column.visible = visible;
  3924. }
  3925. }
  3926. } catch (err) {
  3927. _iterator9.e(err);
  3928. } finally {
  3929. _iterator9.f();
  3930. }
  3931. this.initHeader();
  3932. this.initSearch();
  3933. this.initPagination();
  3934. this.initBody();
  3935. if (this.options.showColumns) {
  3936. var $items = this.$toolbar.find('.keep-open input[type="checkbox"]:not(".toggle-all")').prop('disabled', false);
  3937. if (visible) {
  3938. $items.prop('checked', visible);
  3939. } else {
  3940. $items.get().reverse().forEach(function (item) {
  3941. if ($items.filter(':checked').length > _this23.options.minimumCountColumns) {
  3942. $(item).prop('checked', visible);
  3943. }
  3944. });
  3945. }
  3946. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  3947. $items.filter(':checked').prop('disabled', true);
  3948. }
  3949. }
  3950. }
  3951. }, {
  3952. key: "mergeCells",
  3953. value: function mergeCells(options) {
  3954. var row = options.index;
  3955. var col = this.getVisibleFields().indexOf(options.field);
  3956. var rowspan = options.rowspan || 1;
  3957. var colspan = options.colspan || 1;
  3958. var i;
  3959. var j;
  3960. var $tr = this.$body.find('>tr[data-index]');
  3961. col += Utils.getDetailViewIndexOffset(this.options);
  3962. var $td = $tr.eq(row).find('>td').eq(col);
  3963. if (row < 0 || col < 0 || row >= this.data.length) {
  3964. return;
  3965. }
  3966. for (i = row; i < row + rowspan; i++) {
  3967. for (j = col; j < col + colspan; j++) {
  3968. $tr.eq(i).find('>td').eq(j).hide();
  3969. }
  3970. }
  3971. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  3972. }
  3973. }, {
  3974. key: "checkAll",
  3975. value: function checkAll() {
  3976. this._toggleCheckAll(true);
  3977. }
  3978. }, {
  3979. key: "uncheckAll",
  3980. value: function uncheckAll() {
  3981. this._toggleCheckAll(false);
  3982. }
  3983. }, {
  3984. key: "_toggleCheckAll",
  3985. value: function _toggleCheckAll(checked) {
  3986. var rowsBefore = this.getSelections();
  3987. this.$selectAll.add(this.$selectAll_).prop('checked', checked);
  3988. this.$selectItem.filter(':enabled').prop('checked', checked);
  3989. this.updateRows();
  3990. this.updateSelected();
  3991. var rowsAfter = this.getSelections();
  3992. if (checked) {
  3993. this.trigger('check-all', rowsAfter, rowsBefore);
  3994. return;
  3995. }
  3996. this.trigger('uncheck-all', rowsAfter, rowsBefore);
  3997. }
  3998. }, {
  3999. key: "checkInvert",
  4000. value: function checkInvert() {
  4001. var $items = this.$selectItem.filter(':enabled');
  4002. var checked = $items.filter(':checked');
  4003. $items.each(function (i, el) {
  4004. $(el).prop('checked', !$(el).prop('checked'));
  4005. });
  4006. this.updateRows();
  4007. this.updateSelected();
  4008. this.trigger('uncheck-some', checked);
  4009. checked = this.getSelections();
  4010. this.trigger('check-some', checked);
  4011. }
  4012. }, {
  4013. key: "check",
  4014. value: function check(index) {
  4015. this._toggleCheck(true, index);
  4016. }
  4017. }, {
  4018. key: "uncheck",
  4019. value: function uncheck(index) {
  4020. this._toggleCheck(false, index);
  4021. }
  4022. }, {
  4023. key: "_toggleCheck",
  4024. value: function _toggleCheck(checked, index) {
  4025. var $el = this.$selectItem.filter("[data-index=\"".concat(index, "\"]"));
  4026. var row = this.data[index];
  4027. if ($el.is(':radio') || this.options.singleSelect || this.options.multipleSelectRow && !this.multipleSelectRowCtrlKey && !this.multipleSelectRowShiftKey) {
  4028. var _iterator10 = _createForOfIteratorHelper(this.options.data),
  4029. _step10;
  4030. try {
  4031. for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
  4032. var r = _step10.value;
  4033. r[this.header.stateField] = false;
  4034. }
  4035. } catch (err) {
  4036. _iterator10.e(err);
  4037. } finally {
  4038. _iterator10.f();
  4039. }
  4040. this.$selectItem.filter(':checked').not($el).prop('checked', false);
  4041. }
  4042. row[this.header.stateField] = checked;
  4043. if (this.options.multipleSelectRow) {
  4044. if (this.multipleSelectRowShiftKey && this.multipleSelectRowLastSelectedIndex >= 0) {
  4045. var _ref8 = this.multipleSelectRowLastSelectedIndex < index ? [this.multipleSelectRowLastSelectedIndex, index] : [index, this.multipleSelectRowLastSelectedIndex],
  4046. _ref9 = _slicedToArray(_ref8, 2),
  4047. fromIndex = _ref9[0],
  4048. toIndex = _ref9[1];
  4049. for (var i = fromIndex + 1; i < toIndex; i++) {
  4050. this.data[i][this.header.stateField] = true;
  4051. this.$selectItem.filter("[data-index=\"".concat(i, "\"]")).prop('checked', true);
  4052. }
  4053. }
  4054. this.multipleSelectRowCtrlKey = false;
  4055. this.multipleSelectRowShiftKey = false;
  4056. this.multipleSelectRowLastSelectedIndex = checked ? index : -1;
  4057. }
  4058. $el.prop('checked', checked);
  4059. this.updateSelected();
  4060. this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
  4061. }
  4062. }, {
  4063. key: "checkBy",
  4064. value: function checkBy(obj) {
  4065. this._toggleCheckBy(true, obj);
  4066. }
  4067. }, {
  4068. key: "uncheckBy",
  4069. value: function uncheckBy(obj) {
  4070. this._toggleCheckBy(false, obj);
  4071. }
  4072. }, {
  4073. key: "_toggleCheckBy",
  4074. value: function _toggleCheckBy(checked, obj) {
  4075. var _this24 = this;
  4076. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  4077. return;
  4078. }
  4079. var rows = [];
  4080. this.data.forEach(function (row, i) {
  4081. if (!row.hasOwnProperty(obj.field)) {
  4082. return false;
  4083. }
  4084. if (obj.values.includes(row[obj.field])) {
  4085. var $el = _this24.$selectItem.filter(':enabled').filter(Utils.sprintf('[data-index="%s"]', i));
  4086. var onlyCurrentPage = obj.hasOwnProperty('onlyCurrentPage') ? obj.onlyCurrentPage : false;
  4087. $el = checked ? $el.not(':checked') : $el.filter(':checked');
  4088. if (!$el.length && onlyCurrentPage) {
  4089. return;
  4090. }
  4091. $el.prop('checked', checked);
  4092. row[_this24.header.stateField] = checked;
  4093. rows.push(row);
  4094. _this24.trigger(checked ? 'check' : 'uncheck', row, $el);
  4095. }
  4096. });
  4097. this.updateSelected();
  4098. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  4099. }
  4100. }, {
  4101. key: "refresh",
  4102. value: function refresh(params) {
  4103. if (params && params.url) {
  4104. this.options.url = params.url;
  4105. }
  4106. if (params && params.pageNumber) {
  4107. this.options.pageNumber = params.pageNumber;
  4108. }
  4109. if (params && params.pageSize) {
  4110. this.options.pageSize = params.pageSize;
  4111. }
  4112. this.trigger('refresh', this.initServer(params && params.silent, params && params.query, params && params.url));
  4113. }
  4114. }, {
  4115. key: "destroy",
  4116. value: function destroy() {
  4117. this.$el.insertBefore(this.$container);
  4118. $(this.options.toolbar).insertBefore(this.$el);
  4119. this.$container.next().remove();
  4120. this.$container.remove();
  4121. this.$el.html(this.$el_.html()).css('margin-top', '0').attr('class', this.$el_.attr('class') || ''); // reset the class
  4122. var resizeEvent = Utils.getEventName('resize.bootstrap-table', this.$el.attr('id'));
  4123. $(window).off(resizeEvent);
  4124. }
  4125. }, {
  4126. key: "resetView",
  4127. value: function resetView(params) {
  4128. var padding = 0;
  4129. if (params && params.height) {
  4130. this.options.height = params.height;
  4131. }
  4132. this.$tableContainer.toggleClass('has-card-view', this.options.cardView);
  4133. if (this.options.height) {
  4134. var fixedBody = this.$tableBody.get(0);
  4135. this.hasScrollBar = fixedBody.scrollWidth > fixedBody.clientWidth;
  4136. }
  4137. if (!this.options.cardView && this.options.showHeader && this.options.height) {
  4138. this.$tableHeader.show();
  4139. this.resetHeader();
  4140. padding += this.$header.outerHeight(true) + 1;
  4141. } else {
  4142. this.$tableHeader.hide();
  4143. this.trigger('post-header');
  4144. }
  4145. if (!this.options.cardView && this.options.showFooter) {
  4146. this.$tableFooter.show();
  4147. this.fitFooter();
  4148. if (this.options.height) {
  4149. padding += this.$tableFooter.outerHeight(true);
  4150. }
  4151. }
  4152. if (this.$container.hasClass('fullscreen')) {
  4153. this.$tableContainer.css('height', '');
  4154. this.$tableContainer.css('width', '');
  4155. } else if (this.options.height) {
  4156. if (this.$tableBorder) {
  4157. this.$tableBorder.css('width', '');
  4158. this.$tableBorder.css('height', '');
  4159. }
  4160. var toolbarHeight = this.$toolbar.outerHeight(true);
  4161. var paginationHeight = this.$pagination.outerHeight(true);
  4162. var height = this.options.height - toolbarHeight - paginationHeight;
  4163. var $bodyTable = this.$tableBody.find('>table');
  4164. var tableHeight = $bodyTable.outerHeight();
  4165. this.$tableContainer.css('height', "".concat(height, "px"));
  4166. if (this.$tableBorder && $bodyTable.is(':visible')) {
  4167. var tableBorderHeight = height - tableHeight - 2;
  4168. if (this.hasScrollBar) {
  4169. tableBorderHeight -= Utils.getScrollBarWidth();
  4170. }
  4171. this.$tableBorder.css('width', "".concat($bodyTable.outerWidth(), "px"));
  4172. this.$tableBorder.css('height', "".concat(tableBorderHeight, "px"));
  4173. }
  4174. }
  4175. if (this.options.cardView) {
  4176. // remove the element css
  4177. this.$el.css('margin-top', '0');
  4178. this.$tableContainer.css('padding-bottom', '0');
  4179. this.$tableFooter.hide();
  4180. } else {
  4181. // Assign the correct sortable arrow
  4182. this.getCaret();
  4183. this.$tableContainer.css('padding-bottom', "".concat(padding, "px"));
  4184. }
  4185. this.trigger('reset-view');
  4186. }
  4187. }, {
  4188. key: "showLoading",
  4189. value: function showLoading() {
  4190. this.$tableLoading.toggleClass('open', true);
  4191. var fontSize = this.options.loadingFontSize;
  4192. if (this.options.loadingFontSize === 'auto') {
  4193. fontSize = this.$tableLoading.width() * 0.04;
  4194. fontSize = Math.max(12, fontSize);
  4195. fontSize = Math.min(32, fontSize);
  4196. fontSize = "".concat(fontSize, "px");
  4197. }
  4198. this.$tableLoading.find('.loading-text').css('font-size', fontSize);
  4199. }
  4200. }, {
  4201. key: "hideLoading",
  4202. value: function hideLoading() {
  4203. this.$tableLoading.toggleClass('open', false);
  4204. }
  4205. }, {
  4206. key: "togglePagination",
  4207. value: function togglePagination() {
  4208. this.options.pagination = !this.options.pagination;
  4209. var icon = this.options.showButtonIcons ? this.options.pagination ? this.options.icons.paginationSwitchDown : this.options.icons.paginationSwitchUp : '';
  4210. var text = this.options.showButtonText ? this.options.pagination ? this.options.formatPaginationSwitchUp() : this.options.formatPaginationSwitchDown() : '';
  4211. this.$toolbar.find('button[name="paginationSwitch"]').html("".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon), " ").concat(text));
  4212. this.updatePagination();
  4213. this.trigger('toggle-pagination', this.options.pagination);
  4214. }
  4215. }, {
  4216. key: "toggleFullscreen",
  4217. value: function toggleFullscreen() {
  4218. this.$el.closest('.bootstrap-table').toggleClass('fullscreen');
  4219. this.resetView();
  4220. }
  4221. }, {
  4222. key: "toggleView",
  4223. value: function toggleView() {
  4224. this.options.cardView = !this.options.cardView;
  4225. this.initHeader();
  4226. var icon = this.options.showButtonIcons ? this.options.cardView ? this.options.icons.toggleOn : this.options.icons.toggleOff : '';
  4227. var text = this.options.showButtonText ? this.options.cardView ? this.options.formatToggleOff() : this.options.formatToggleOn() : '';
  4228. this.$toolbar.find('button[name="toggle"]').html("".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon), " ").concat(text)).attr('aria-label', text).attr('title', text);
  4229. this.initBody();
  4230. this.trigger('toggle', this.options.cardView);
  4231. }
  4232. }, {
  4233. key: "resetSearch",
  4234. value: function resetSearch(text) {
  4235. var $search = Utils.getSearchInput(this);
  4236. var textToUse = text || '';
  4237. $search.val(textToUse);
  4238. this.searchText = textToUse;
  4239. this.onSearch({
  4240. currentTarget: $search
  4241. }, false);
  4242. }
  4243. }, {
  4244. key: "filterBy",
  4245. value: function filterBy(columns, options) {
  4246. this.filterOptions = Utils.isEmptyObject(options) ? this.options.filterOptions : Utils.extend(this.options.filterOptions, options);
  4247. this.filterColumns = Utils.isEmptyObject(columns) ? {} : columns;
  4248. this.options.pageNumber = 1;
  4249. this.initSearch();
  4250. this.updatePagination();
  4251. }
  4252. }, {
  4253. key: "scrollTo",
  4254. value: function scrollTo(params) {
  4255. var options = {
  4256. unit: 'px',
  4257. value: 0
  4258. };
  4259. if (_typeof(params) === 'object') {
  4260. options = Object.assign(options, params);
  4261. } else if (typeof params === 'string' && params === 'bottom') {
  4262. options.value = this.$tableBody[0].scrollHeight;
  4263. } else if (typeof params === 'string' || typeof params === 'number') {
  4264. options.value = params;
  4265. }
  4266. var scrollTo = options.value;
  4267. if (options.unit === 'rows') {
  4268. scrollTo = 0;
  4269. this.$body.find("> tr:lt(".concat(options.value, ")")).each(function (i, el) {
  4270. scrollTo += $(el).outerHeight(true);
  4271. });
  4272. }
  4273. this.$tableBody.scrollTop(scrollTo);
  4274. }
  4275. }, {
  4276. key: "getScrollPosition",
  4277. value: function getScrollPosition() {
  4278. return this.$tableBody.scrollTop();
  4279. }
  4280. }, {
  4281. key: "selectPage",
  4282. value: function selectPage(page) {
  4283. if (page > 0 && page <= this.options.totalPages) {
  4284. this.options.pageNumber = page;
  4285. this.updatePagination();
  4286. }
  4287. }
  4288. }, {
  4289. key: "prevPage",
  4290. value: function prevPage() {
  4291. if (this.options.pageNumber > 1) {
  4292. this.options.pageNumber--;
  4293. this.updatePagination();
  4294. }
  4295. }
  4296. }, {
  4297. key: "nextPage",
  4298. value: function nextPage() {
  4299. if (this.options.pageNumber < this.options.totalPages) {
  4300. this.options.pageNumber++;
  4301. this.updatePagination();
  4302. }
  4303. }
  4304. }, {
  4305. key: "toggleDetailView",
  4306. value: function toggleDetailView(index, _columnDetailFormatter) {
  4307. var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', index));
  4308. if ($tr.next().is('tr.detail-view')) {
  4309. this.collapseRow(index);
  4310. } else {
  4311. this.expandRow(index, _columnDetailFormatter);
  4312. }
  4313. this.resetView();
  4314. }
  4315. }, {
  4316. key: "expandRow",
  4317. value: function expandRow(index, _columnDetailFormatter) {
  4318. var row = this.data[index];
  4319. var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index));
  4320. if (this.options.detailViewIcon) {
  4321. $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailClose));
  4322. }
  4323. if ($tr.next().is('tr.detail-view')) {
  4324. return;
  4325. }
  4326. $tr.after(Utils.sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.children('td').length));
  4327. var $element = $tr.next().find('td');
  4328. var detailFormatter = _columnDetailFormatter || this.options.detailFormatter;
  4329. var content = Utils.calculateObjectValue(this.options, detailFormatter, [index, row, $element], '');
  4330. if ($element.length === 1) {
  4331. $element.append(content);
  4332. }
  4333. this.trigger('expand-row', index, row, $element);
  4334. }
  4335. }, {
  4336. key: "expandRowByUniqueId",
  4337. value: function expandRowByUniqueId(uniqueId) {
  4338. var row = this.getRowByUniqueId(uniqueId);
  4339. if (!row) {
  4340. return;
  4341. }
  4342. this.expandRow(this.data.indexOf(row));
  4343. }
  4344. }, {
  4345. key: "collapseRow",
  4346. value: function collapseRow(index) {
  4347. var row = this.data[index];
  4348. var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"][data-has-detail-view]', index));
  4349. if (!$tr.next().is('tr.detail-view')) {
  4350. return;
  4351. }
  4352. if (this.options.detailViewIcon) {
  4353. $tr.find('a.detail-icon').html(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, this.options.icons.detailOpen));
  4354. }
  4355. this.trigger('collapse-row', index, row, $tr.next());
  4356. $tr.next().remove();
  4357. }
  4358. }, {
  4359. key: "collapseRowByUniqueId",
  4360. value: function collapseRowByUniqueId(uniqueId) {
  4361. var row = this.getRowByUniqueId(uniqueId);
  4362. if (!row) {
  4363. return;
  4364. }
  4365. this.collapseRow(this.data.indexOf(row));
  4366. }
  4367. }, {
  4368. key: "expandAllRows",
  4369. value: function expandAllRows() {
  4370. var trs = this.$body.find('> tr[data-index][data-has-detail-view]');
  4371. for (var i = 0; i < trs.length; i++) {
  4372. this.expandRow($(trs[i]).data('index'));
  4373. }
  4374. }
  4375. }, {
  4376. key: "collapseAllRows",
  4377. value: function collapseAllRows() {
  4378. var trs = this.$body.find('> tr[data-index][data-has-detail-view]');
  4379. for (var i = 0; i < trs.length; i++) {
  4380. this.collapseRow($(trs[i]).data('index'));
  4381. }
  4382. }
  4383. }, {
  4384. key: "updateColumnTitle",
  4385. value: function updateColumnTitle(params) {
  4386. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) {
  4387. return;
  4388. }
  4389. this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape && this.options.escapeTitle ? Utils.escapeHTML(params.title) : params.title;
  4390. if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
  4391. this.$header.find('th[data-field]').each(function (i, el) {
  4392. if ($(el).data('field') === params.field) {
  4393. $($(el).find('.th-inner')[0]).html(params.title);
  4394. return false;
  4395. }
  4396. });
  4397. this.resetView();
  4398. }
  4399. }
  4400. }, {
  4401. key: "updateFormatText",
  4402. value: function updateFormatText(formatName, text) {
  4403. if (!/^format/.test(formatName) || !this.options[formatName]) {
  4404. return;
  4405. }
  4406. if (typeof text === 'string') {
  4407. this.options[formatName] = function () {
  4408. return text;
  4409. };
  4410. } else if (typeof text === 'function') {
  4411. this.options[formatName] = text;
  4412. }
  4413. this.initToolbar();
  4414. this.initPagination();
  4415. this.initBody();
  4416. }
  4417. }]);
  4418. }();
  4419. BootstrapTable.VERSION = Constants.VERSION;
  4420. BootstrapTable.DEFAULTS = Constants.DEFAULTS;
  4421. BootstrapTable.LOCALES = Constants.LOCALES;
  4422. BootstrapTable.COLUMN_DEFAULTS = Constants.COLUMN_DEFAULTS;
  4423. BootstrapTable.METHODS = Constants.METHODS;
  4424. BootstrapTable.EVENTS = Constants.EVENTS;
  4425. // BOOTSTRAP TABLE PLUGIN DEFINITION
  4426. // =======================
  4427. $.BootstrapTable = BootstrapTable;
  4428. $.fn.bootstrapTable = function (option) {
  4429. for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key5 = 1; _key5 < _len2; _key5++) {
  4430. args[_key5 - 1] = arguments[_key5];
  4431. }
  4432. var value;
  4433. this.each(function (i, el) {
  4434. var data = $(el).data('bootstrap.table');
  4435. if (typeof option === 'string') {
  4436. var _data2;
  4437. if (!Constants.METHODS.includes(option)) {
  4438. throw new Error("Unknown method: ".concat(option));
  4439. }
  4440. if (!data) {
  4441. return;
  4442. }
  4443. value = (_data2 = data)[option].apply(_data2, args);
  4444. if (option === 'destroy') {
  4445. $(el).removeData('bootstrap.table');
  4446. }
  4447. return;
  4448. }
  4449. if (data) {
  4450. console.warn('You cannot initialize the table more than once!');
  4451. return;
  4452. }
  4453. var options = Utils.extend(true, {}, BootstrapTable.DEFAULTS, $(el).data(), _typeof(option) === 'object' && option);
  4454. data = new $.BootstrapTable(el, options);
  4455. $(el).data('bootstrap.table', data);
  4456. data.init();
  4457. });
  4458. return typeof value === 'undefined' ? this : value;
  4459. };
  4460. $.fn.bootstrapTable.Constructor = BootstrapTable;
  4461. $.fn.bootstrapTable.theme = Constants.THEME;
  4462. $.fn.bootstrapTable.VERSION = Constants.VERSION;
  4463. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  4464. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  4465. $.fn.bootstrapTable.events = BootstrapTable.EVENTS;
  4466. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  4467. $.fn.bootstrapTable.methods = BootstrapTable.METHODS;
  4468. $.fn.bootstrapTable.utils = Utils;
  4469. // BOOTSTRAP TABLE INIT
  4470. // =======================
  4471. $(function () {
  4472. $('[data-toggle="table"]').bootstrapTable();
  4473. });
  4474. return BootstrapTable;
  4475. }));