bootstrap-table.js 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854
  1. (function (global, factory) {
  2. if (typeof define === "function" && define.amd) {
  3. define([], factory);
  4. } else if (typeof exports !== "undefined") {
  5. factory();
  6. } else {
  7. var mod = {
  8. exports: {}
  9. };
  10. factory();
  11. global.bootstrapTable = mod.exports;
  12. }
  13. })(this, function () {
  14. 'use strict';
  15. function _classCallCheck(instance, Constructor) {
  16. if (!(instance instanceof Constructor)) {
  17. throw new TypeError("Cannot call a class as a function");
  18. }
  19. }
  20. var _createClass = function () {
  21. function defineProperties(target, props) {
  22. for (var i = 0; i < props.length; i++) {
  23. var descriptor = props[i];
  24. descriptor.enumerable = descriptor.enumerable || false;
  25. descriptor.configurable = true;
  26. if ("value" in descriptor) descriptor.writable = true;
  27. Object.defineProperty(target, descriptor.key, descriptor);
  28. }
  29. }
  30. return function (Constructor, protoProps, staticProps) {
  31. if (protoProps) defineProperties(Constructor.prototype, protoProps);
  32. if (staticProps) defineProperties(Constructor, staticProps);
  33. return Constructor;
  34. };
  35. }();
  36. var _slicedToArray = function () {
  37. function sliceIterator(arr, i) {
  38. var _arr = [];
  39. var _n = true;
  40. var _d = false;
  41. var _e = undefined;
  42. try {
  43. for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
  44. _arr.push(_s.value);
  45. if (i && _arr.length === i) break;
  46. }
  47. } catch (err) {
  48. _d = true;
  49. _e = err;
  50. } finally {
  51. try {
  52. if (!_n && _i["return"]) _i["return"]();
  53. } finally {
  54. if (_d) throw _e;
  55. }
  56. }
  57. return _arr;
  58. }
  59. return function (arr, i) {
  60. if (Array.isArray(arr)) {
  61. return arr;
  62. } else if (Symbol.iterator in Object(arr)) {
  63. return sliceIterator(arr, i);
  64. } else {
  65. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  66. }
  67. };
  68. }();
  69. function _toConsumableArray(arr) {
  70. if (Array.isArray(arr)) {
  71. for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
  72. arr2[i] = arr[i];
  73. }
  74. return arr2;
  75. } else {
  76. return Array.from(arr);
  77. }
  78. }
  79. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
  80. return typeof obj;
  81. } : function (obj) {
  82. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  83. };
  84. /**
  85. * @author zhixin wen <wenzhixin2010@gmail.com>
  86. * version: 1.13.4
  87. * https://github.com/wenzhixin/bootstrap-table/
  88. */
  89. (function ($) {
  90. // TOOLS DEFINITION
  91. // ======================
  92. var bootstrapVersion = 3;
  93. try {
  94. var rawVersion = $.fn.dropdown.Constructor.VERSION;
  95. // Only try to parse VERSION if is is defined.
  96. // It is undefined in older versions of Bootstrap (tested with 3.1.1).
  97. if (rawVersion !== undefined) {
  98. bootstrapVersion = parseInt(rawVersion, 10);
  99. }
  100. } catch (e) {
  101. // ignore
  102. }
  103. var bootstrap = {
  104. 3: {
  105. iconsPrefix: 'glyphicon',
  106. icons: {
  107. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  108. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  109. refresh: 'glyphicon-refresh icon-refresh',
  110. toggleOff: 'glyphicon-list-alt icon-list-alt',
  111. toggleOn: 'glyphicon-list-alt icon-list-alt',
  112. columns: 'glyphicon-th icon-th',
  113. detailOpen: 'glyphicon-plus icon-plus',
  114. detailClose: 'glyphicon-minus icon-minus',
  115. fullscreen: 'glyphicon-fullscreen'
  116. },
  117. classes: {
  118. buttons: 'default',
  119. pull: 'pull'
  120. },
  121. html: {
  122. toobarDropdow: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  123. toobarDropdowItem: '<li role="menuitem"><label>%s</label></li>',
  124. pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  125. pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>'
  126. }
  127. },
  128. 4: {
  129. iconsPrefix: 'fa',
  130. icons: {
  131. paginationSwitchDown: 'fa-caret-square-down',
  132. paginationSwitchUp: 'fa-caret-square-up',
  133. refresh: 'fa-sync',
  134. toggleOff: 'fa-toggle-off',
  135. toggleOn: 'fa-toggle-on',
  136. columns: 'fa-th-list',
  137. detailOpen: 'fa-plus',
  138. detailClose: 'fa-minus',
  139. fullscreen: 'fa-arrows-alt'
  140. },
  141. classes: {
  142. buttons: 'secondary',
  143. pull: 'float'
  144. },
  145. html: {
  146. toobarDropdow: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'],
  147. toobarDropdowItem: '<label class="dropdown-item">%s</label>',
  148. pageDropdown: ['<div class="dropdown-menu">', '</div>'],
  149. pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>'
  150. }
  151. }
  152. }[bootstrapVersion];
  153. var Utils = {
  154. bootstrapVersion: bootstrapVersion,
  155. sprintf: function sprintf(_str) {
  156. for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
  157. args[_key - 1] = arguments[_key];
  158. }
  159. var flag = true;
  160. var i = 0;
  161. var str = _str.replace(/%s/g, function () {
  162. var arg = args[i++];
  163. if (typeof arg === 'undefined') {
  164. flag = false;
  165. return '';
  166. }
  167. return arg;
  168. });
  169. return flag ? str : '';
  170. },
  171. getFieldTitle: function getFieldTitle(list, value) {
  172. var _iteratorNormalCompletion = true;
  173. var _didIteratorError = false;
  174. var _iteratorError = undefined;
  175. try {
  176. for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  177. var item = _step.value;
  178. if (item.field === value) {
  179. return item.title;
  180. }
  181. }
  182. } catch (err) {
  183. _didIteratorError = true;
  184. _iteratorError = err;
  185. } finally {
  186. try {
  187. if (!_iteratorNormalCompletion && _iterator.return) {
  188. _iterator.return();
  189. }
  190. } finally {
  191. if (_didIteratorError) {
  192. throw _iteratorError;
  193. }
  194. }
  195. }
  196. return '';
  197. },
  198. setFieldIndex: function setFieldIndex(columns) {
  199. var totalCol = 0;
  200. var flag = [];
  201. var _iteratorNormalCompletion2 = true;
  202. var _didIteratorError2 = false;
  203. var _iteratorError2 = undefined;
  204. try {
  205. for (var _iterator2 = columns[0][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  206. var column = _step2.value;
  207. totalCol += column.colspan || 1;
  208. }
  209. } catch (err) {
  210. _didIteratorError2 = true;
  211. _iteratorError2 = err;
  212. } finally {
  213. try {
  214. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  215. _iterator2.return();
  216. }
  217. } finally {
  218. if (_didIteratorError2) {
  219. throw _iteratorError2;
  220. }
  221. }
  222. }
  223. for (var i = 0; i < columns.length; i++) {
  224. flag[i] = [];
  225. for (var j = 0; j < totalCol; j++) {
  226. flag[i][j] = false;
  227. }
  228. }
  229. for (var _i = 0; _i < columns.length; _i++) {
  230. var _iteratorNormalCompletion3 = true;
  231. var _didIteratorError3 = false;
  232. var _iteratorError3 = undefined;
  233. try {
  234. for (var _iterator3 = columns[_i][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
  235. var r = _step3.value;
  236. var rowspan = r.rowspan || 1;
  237. var colspan = r.colspan || 1;
  238. var index = flag[_i].indexOf(false);
  239. if (colspan === 1) {
  240. r.fieldIndex = index;
  241. // when field is undefined, use index instead
  242. if (typeof r.field === 'undefined') {
  243. r.field = index;
  244. }
  245. }
  246. for (var k = 0; k < rowspan; k++) {
  247. flag[_i + k][index] = true;
  248. }
  249. for (var _k = 0; _k < colspan; _k++) {
  250. flag[_i][index + _k] = true;
  251. }
  252. }
  253. } catch (err) {
  254. _didIteratorError3 = true;
  255. _iteratorError3 = err;
  256. } finally {
  257. try {
  258. if (!_iteratorNormalCompletion3 && _iterator3.return) {
  259. _iterator3.return();
  260. }
  261. } finally {
  262. if (_didIteratorError3) {
  263. throw _iteratorError3;
  264. }
  265. }
  266. }
  267. }
  268. },
  269. getScrollBarWidth: function getScrollBarWidth() {
  270. if (this.cachedWidth === undefined) {
  271. var $inner = $('<div/>').addClass('fixed-table-scroll-inner');
  272. var $outer = $('<div/>').addClass('fixed-table-scroll-outer');
  273. $outer.append($inner);
  274. $('body').append($outer);
  275. var w1 = $inner[0].offsetWidth;
  276. $outer.css('overflow', 'scroll');
  277. var w2 = $inner[0].offsetWidth;
  278. if (w1 === w2) {
  279. w2 = $outer[0].clientWidth;
  280. }
  281. $outer.remove();
  282. this.cachedWidth = w1 - w2;
  283. }
  284. return this.cachedWidth;
  285. },
  286. calculateObjectValue: function calculateObjectValue(self, name, args, defaultValue) {
  287. var func = name;
  288. if (typeof name === 'string') {
  289. // support obj.func1.func2
  290. var names = name.split('.');
  291. if (names.length > 1) {
  292. func = window;
  293. var _iteratorNormalCompletion4 = true;
  294. var _didIteratorError4 = false;
  295. var _iteratorError4 = undefined;
  296. try {
  297. for (var _iterator4 = names[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
  298. var f = _step4.value;
  299. func = func[f];
  300. }
  301. } catch (err) {
  302. _didIteratorError4 = true;
  303. _iteratorError4 = err;
  304. } finally {
  305. try {
  306. if (!_iteratorNormalCompletion4 && _iterator4.return) {
  307. _iterator4.return();
  308. }
  309. } finally {
  310. if (_didIteratorError4) {
  311. throw _iteratorError4;
  312. }
  313. }
  314. }
  315. } else {
  316. func = window[name];
  317. }
  318. }
  319. if (func !== null && (typeof func === 'undefined' ? 'undefined' : _typeof(func)) === 'object') {
  320. return func;
  321. }
  322. if (typeof func === 'function') {
  323. return func.apply(self, args || []);
  324. }
  325. if (!func && typeof name === 'string' && this.sprintf.apply(this, [name].concat(_toConsumableArray(args)))) {
  326. return this.sprintf.apply(this, [name].concat(_toConsumableArray(args)));
  327. }
  328. return defaultValue;
  329. },
  330. compareObjects: function compareObjects(objectA, objectB, compareLength) {
  331. var aKeys = Object.keys(objectA);
  332. var bKeys = Object.keys(objectB);
  333. if (compareLength && aKeys.length !== bKeys.length) {
  334. return false;
  335. }
  336. var _iteratorNormalCompletion5 = true;
  337. var _didIteratorError5 = false;
  338. var _iteratorError5 = undefined;
  339. try {
  340. for (var _iterator5 = aKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
  341. var key = _step5.value;
  342. if (bKeys.includes(key) && objectA[key] !== objectB[key]) {
  343. return false;
  344. }
  345. }
  346. } catch (err) {
  347. _didIteratorError5 = true;
  348. _iteratorError5 = err;
  349. } finally {
  350. try {
  351. if (!_iteratorNormalCompletion5 && _iterator5.return) {
  352. _iterator5.return();
  353. }
  354. } finally {
  355. if (_didIteratorError5) {
  356. throw _iteratorError5;
  357. }
  358. }
  359. }
  360. return true;
  361. },
  362. escapeHTML: function escapeHTML(text) {
  363. if (typeof text === 'string') {
  364. return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;').replace(/`/g, '&#x60;');
  365. }
  366. return text;
  367. },
  368. getRealDataAttr: function getRealDataAttr(dataAttr) {
  369. var _iteratorNormalCompletion6 = true;
  370. var _didIteratorError6 = false;
  371. var _iteratorError6 = undefined;
  372. try {
  373. for (var _iterator6 = Object.entries(dataAttr)[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
  374. var _ref = _step6.value;
  375. var _ref2 = _slicedToArray(_ref, 2);
  376. var attr = _ref2[0];
  377. var value = _ref2[1];
  378. var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
  379. if (auxAttr !== attr) {
  380. dataAttr[auxAttr] = value;
  381. delete dataAttr[attr];
  382. }
  383. }
  384. } catch (err) {
  385. _didIteratorError6 = true;
  386. _iteratorError6 = err;
  387. } finally {
  388. try {
  389. if (!_iteratorNormalCompletion6 && _iterator6.return) {
  390. _iterator6.return();
  391. }
  392. } finally {
  393. if (_didIteratorError6) {
  394. throw _iteratorError6;
  395. }
  396. }
  397. }
  398. return dataAttr;
  399. },
  400. getItemField: function getItemField(item, field, escape) {
  401. var value = item;
  402. if (typeof field !== 'string' || item.hasOwnProperty(field)) {
  403. return escape ? this.escapeHTML(item[field]) : item[field];
  404. }
  405. var props = field.split('.');
  406. var _iteratorNormalCompletion7 = true;
  407. var _didIteratorError7 = false;
  408. var _iteratorError7 = undefined;
  409. try {
  410. for (var _iterator7 = props[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
  411. var p = _step7.value;
  412. value = value && value[p];
  413. }
  414. } catch (err) {
  415. _didIteratorError7 = true;
  416. _iteratorError7 = err;
  417. } finally {
  418. try {
  419. if (!_iteratorNormalCompletion7 && _iterator7.return) {
  420. _iterator7.return();
  421. }
  422. } finally {
  423. if (_didIteratorError7) {
  424. throw _iteratorError7;
  425. }
  426. }
  427. }
  428. return escape ? this.escapeHTML(value) : value;
  429. },
  430. isIEBrowser: function isIEBrowser() {
  431. return navigator.userAgent.includes('MSIE ') || /Trident.*rv:11\./.test(navigator.userAgent);
  432. },
  433. findIndex: function findIndex(items, item) {
  434. var _iteratorNormalCompletion8 = true;
  435. var _didIteratorError8 = false;
  436. var _iteratorError8 = undefined;
  437. try {
  438. for (var _iterator8 = items.entries()[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
  439. var _ref3 = _step8.value;
  440. var _ref4 = _slicedToArray(_ref3, 2);
  441. var i = _ref4[0];
  442. var it = _ref4[1];
  443. if (JSON.stringify(it) === JSON.stringify(item)) {
  444. return i;
  445. }
  446. }
  447. } catch (err) {
  448. _didIteratorError8 = true;
  449. _iteratorError8 = err;
  450. } finally {
  451. try {
  452. if (!_iteratorNormalCompletion8 && _iterator8.return) {
  453. _iterator8.return();
  454. }
  455. } finally {
  456. if (_didIteratorError8) {
  457. throw _iteratorError8;
  458. }
  459. }
  460. }
  461. return -1;
  462. }
  463. };
  464. // BOOTSTRAP TABLE CLASS DEFINITION
  465. // ======================
  466. var DEFAULTS = {
  467. height: undefined,
  468. classes: 'table table-bordered table-hover',
  469. theadClasses: '',
  470. rowStyle: function rowStyle(row, index) {
  471. return {};
  472. },
  473. rowAttributes: function rowAttributes(row, index) {
  474. return {};
  475. },
  476. undefinedText: '-',
  477. locale: undefined,
  478. sortable: true,
  479. sortClass: undefined,
  480. silentSort: true,
  481. sortName: undefined,
  482. sortOrder: 'asc',
  483. sortStable: false,
  484. rememberOrder: false,
  485. customSort: undefined,
  486. columns: [[]],
  487. data: [],
  488. url: undefined,
  489. method: 'get',
  490. cache: true,
  491. contentType: 'application/json',
  492. dataType: 'json',
  493. ajax: undefined,
  494. ajaxOptions: {},
  495. queryParams: function queryParams(params) {
  496. return params;
  497. },
  498. queryParamsType: 'limit', responseHandler: function responseHandler(res) {
  499. return res;
  500. },
  501. totalField: 'total',
  502. dataField: 'rows',
  503. pagination: false,
  504. onlyInfoPagination: false,
  505. paginationLoop: true,
  506. sidePagination: 'client', // client or server
  507. totalRows: 0,
  508. pageNumber: 1,
  509. pageSize: 10,
  510. pageList: [10, 25, 50, 100],
  511. paginationHAlign: 'right', // right, left
  512. paginationVAlign: 'bottom', // bottom, top, both
  513. paginationDetailHAlign: 'left', // right, left
  514. paginationPreText: '&lsaquo;',
  515. paginationNextText: '&rsaquo;',
  516. paginationSuccessivelySize: 5, // Maximum successively number of pages in a row
  517. paginationPagesBySide: 1, // Number of pages on each side (right, left) of the current page.
  518. paginationUseIntermediate: false, // Calculate intermediate pages for quick access
  519. search: false,
  520. searchOnEnterKey: false,
  521. strictSearch: false,
  522. trimOnSearch: true,
  523. searchAlign: 'right',
  524. searchTimeOut: 500,
  525. searchText: '',
  526. customSearch: undefined,
  527. showHeader: true,
  528. showFooter: false,
  529. footerStyle: function footerStyle(row, index) {
  530. return {};
  531. },
  532. showColumns: false,
  533. minimumCountColumns: 1,
  534. showPaginationSwitch: false,
  535. showRefresh: false,
  536. showToggle: false,
  537. showFullscreen: false,
  538. smartDisplay: true,
  539. escape: false,
  540. idField: undefined,
  541. uniqueId: undefined,
  542. cardView: false,
  543. detailView: false,
  544. detailFormatter: function detailFormatter(index, row) {
  545. return '';
  546. },
  547. detailFilter: function detailFilter(index, row) {
  548. return true;
  549. },
  550. selectItemName: 'btSelectItem',
  551. clickToSelect: false,
  552. ignoreClickToSelectOn: function ignoreClickToSelectOn(_ref5) {
  553. var tagName = _ref5.tagName;
  554. return ['A', 'BUTTON'].includes(tagName);
  555. },
  556. singleSelect: false,
  557. checkboxHeader: true,
  558. maintainSelected: false,
  559. toolbar: undefined,
  560. toolbarAlign: 'left',
  561. buttonsToolbar: undefined,
  562. buttonsAlign: 'right',
  563. buttonsClass: bootstrap.classes.buttons,
  564. icons: bootstrap.icons,
  565. iconSize: undefined,
  566. iconsPrefix: bootstrap.iconsPrefix, onAll: function onAll(name, args) {
  567. return false;
  568. },
  569. onClickCell: function onClickCell(field, value, row, $element) {
  570. return false;
  571. },
  572. onDblClickCell: function onDblClickCell(field, value, row, $element) {
  573. return false;
  574. },
  575. onClickRow: function onClickRow(item, $element) {
  576. return false;
  577. },
  578. onDblClickRow: function onDblClickRow(item, $element) {
  579. return false;
  580. },
  581. onSort: function onSort(name, order) {
  582. return false;
  583. },
  584. onCheck: function onCheck(row) {
  585. return false;
  586. },
  587. onUncheck: function onUncheck(row) {
  588. return false;
  589. },
  590. onCheckAll: function onCheckAll(rows) {
  591. return false;
  592. },
  593. onUncheckAll: function onUncheckAll(rows) {
  594. return false;
  595. },
  596. onCheckSome: function onCheckSome(rows) {
  597. return false;
  598. },
  599. onUncheckSome: function onUncheckSome(rows) {
  600. return false;
  601. },
  602. onLoadSuccess: function onLoadSuccess(data) {
  603. return false;
  604. },
  605. onLoadError: function onLoadError(status) {
  606. return false;
  607. },
  608. onColumnSwitch: function onColumnSwitch(field, checked) {
  609. return false;
  610. },
  611. onPageChange: function onPageChange(number, size) {
  612. return false;
  613. },
  614. onSearch: function onSearch(text) {
  615. return false;
  616. },
  617. onToggle: function onToggle(cardView) {
  618. return false;
  619. },
  620. onPreBody: function onPreBody(data) {
  621. return false;
  622. },
  623. onPostBody: function onPostBody() {
  624. return false;
  625. },
  626. onPostHeader: function onPostHeader() {
  627. return false;
  628. },
  629. onExpandRow: function onExpandRow(index, row, $detail) {
  630. return false;
  631. },
  632. onCollapseRow: function onCollapseRow(index, row) {
  633. return false;
  634. },
  635. onRefreshOptions: function onRefreshOptions(options) {
  636. return false;
  637. },
  638. onRefresh: function onRefresh(params) {
  639. return false;
  640. },
  641. onResetView: function onResetView() {
  642. return false;
  643. },
  644. onScrollBody: function onScrollBody() {
  645. return false;
  646. }
  647. };
  648. var LOCALES = {};
  649. LOCALES['en-US'] = LOCALES.en = {
  650. formatLoadingMessage: function formatLoadingMessage() {
  651. return 'Loading, please wait...';
  652. },
  653. formatRecordsPerPage: function formatRecordsPerPage(pageNumber) {
  654. return Utils.sprintf('%s rows per page', pageNumber);
  655. },
  656. formatShowingRows: function formatShowingRows(pageFrom, pageTo, totalRows) {
  657. return Utils.sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
  658. },
  659. formatDetailPagination: function formatDetailPagination(totalRows) {
  660. return Utils.sprintf('Showing %s rows', totalRows);
  661. },
  662. formatSearch: function formatSearch() {
  663. return 'Search';
  664. },
  665. formatNoMatches: function formatNoMatches() {
  666. return 'No matching records found';
  667. },
  668. formatPaginationSwitch: function formatPaginationSwitch() {
  669. return 'Hide/Show pagination';
  670. },
  671. formatRefresh: function formatRefresh() {
  672. return 'Refresh';
  673. },
  674. formatToggle: function formatToggle() {
  675. return 'Toggle';
  676. },
  677. formatFullscreen: function formatFullscreen() {
  678. return 'Fullscreen';
  679. },
  680. formatColumns: function formatColumns() {
  681. return 'Columns';
  682. },
  683. formatAllRows: function formatAllRows() {
  684. return 'All';
  685. }
  686. };
  687. $.extend(DEFAULTS, LOCALES['en-US']);
  688. var COLUMN_DEFAULTS = {
  689. radio: false,
  690. checkbox: false,
  691. checkboxEnabled: true,
  692. field: undefined,
  693. title: undefined,
  694. titleTooltip: undefined,
  695. 'class': undefined,
  696. align: undefined, // left, right, center
  697. halign: undefined, // left, right, center
  698. falign: undefined, // left, right, center
  699. valign: undefined, // top, middle, bottom
  700. width: undefined,
  701. sortable: false,
  702. order: 'asc', // asc, desc
  703. visible: true,
  704. switchable: true,
  705. clickToSelect: true,
  706. formatter: undefined,
  707. footerFormatter: undefined,
  708. events: undefined,
  709. sorter: undefined,
  710. sortName: undefined,
  711. cellStyle: undefined,
  712. searchable: true,
  713. searchFormatter: true,
  714. cardVisible: true,
  715. escape: false,
  716. showSelectTitle: false
  717. };
  718. var EVENTS = {
  719. 'all.bs.table': 'onAll',
  720. 'click-cell.bs.table': 'onClickCell',
  721. 'dbl-click-cell.bs.table': 'onDblClickCell',
  722. 'click-row.bs.table': 'onClickRow',
  723. 'dbl-click-row.bs.table': 'onDblClickRow',
  724. 'sort.bs.table': 'onSort',
  725. 'check.bs.table': 'onCheck',
  726. 'uncheck.bs.table': 'onUncheck',
  727. 'check-all.bs.table': 'onCheckAll',
  728. 'uncheck-all.bs.table': 'onUncheckAll',
  729. 'check-some.bs.table': 'onCheckSome',
  730. 'uncheck-some.bs.table': 'onUncheckSome',
  731. 'load-success.bs.table': 'onLoadSuccess',
  732. 'load-error.bs.table': 'onLoadError',
  733. 'column-switch.bs.table': 'onColumnSwitch',
  734. 'page-change.bs.table': 'onPageChange',
  735. 'search.bs.table': 'onSearch',
  736. 'toggle.bs.table': 'onToggle',
  737. 'pre-body.bs.table': 'onPreBody',
  738. 'post-body.bs.table': 'onPostBody',
  739. 'post-header.bs.table': 'onPostHeader',
  740. 'expand-row.bs.table': 'onExpandRow',
  741. 'collapse-row.bs.table': 'onCollapseRow',
  742. 'refresh-options.bs.table': 'onRefreshOptions',
  743. 'reset-view.bs.table': 'onResetView',
  744. 'refresh.bs.table': 'onRefresh',
  745. 'scroll-body.bs.table': 'onScrollBody'
  746. };
  747. var BootstrapTable = function () {
  748. function BootstrapTable(el, options) {
  749. _classCallCheck(this, BootstrapTable);
  750. this.options = options;
  751. this.$el = $(el);
  752. this.$el_ = this.$el.clone();
  753. this.timeoutId_ = 0;
  754. this.timeoutFooter_ = 0;
  755. this.init();
  756. }
  757. _createClass(BootstrapTable, [{
  758. key: 'init',
  759. value: function init() {
  760. this.initLocale();
  761. this.initContainer();
  762. this.initTable();
  763. this.initHeader();
  764. this.initData();
  765. this.initHiddenRows();
  766. this.initFooter();
  767. this.initToolbar();
  768. this.initPagination();
  769. this.initBody();
  770. this.initSearchText();
  771. this.initServer();
  772. }
  773. }, {
  774. key: 'initLocale',
  775. value: function initLocale() {
  776. if (this.options.locale) {
  777. var locales = $.fn.bootstrapTable.locales;
  778. var parts = this.options.locale.split(/-|_/);
  779. parts[0] = parts[0].toLowerCase();
  780. if (parts[1]) {
  781. parts[1] = parts[1].toUpperCase();
  782. }
  783. if (locales[this.options.locale]) {
  784. $.extend(this.options, locales[this.options.locale]);
  785. } else if (locales[parts.join('-')]) {
  786. $.extend(this.options, locales[parts.join('-')]);
  787. } else if (locales[parts[0]]) {
  788. $.extend(this.options, locales[parts[0]]);
  789. }
  790. }
  791. }
  792. }, {
  793. key: 'initContainer',
  794. value: function initContainer() {
  795. var topPagination = ['top', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination clearfix"></div>' : '';
  796. var bottomPagination = ['bottom', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination"></div>' : '';
  797. this.$container = $('\n <div class="bootstrap-table">\n <div class="fixed-table-toolbar"></div>\n ' + 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 ' + this.options.formatLoadingMessage() + '\n </div>\n </div>\n <div class="fixed-table-footer"><table><tr></tr></table></div>\n </div>\n ' + bottomPagination + '\n </div>\n ');
  798. this.$container.insertAfter(this.$el);
  799. this.$tableContainer = this.$container.find('.fixed-table-container');
  800. this.$tableHeader = this.$container.find('.fixed-table-header');
  801. this.$tableBody = this.$container.find('.fixed-table-body');
  802. this.$tableLoading = this.$container.find('.fixed-table-loading');
  803. this.$tableFooter = this.$container.find('.fixed-table-footer');
  804. // checking if custom table-toolbar exists or not
  805. if (this.options.buttonsToolbar) {
  806. this.$toolbar = $('body').find(this.options.buttonsToolbar);
  807. } else {
  808. this.$toolbar = this.$container.find('.fixed-table-toolbar');
  809. }
  810. this.$pagination = this.$container.find('.fixed-table-pagination');
  811. this.$tableBody.append(this.$el);
  812. this.$container.after('<div class="clearfix"></div>');
  813. this.$el.addClass(this.options.classes);
  814. if (this.options.height) {
  815. this.$tableContainer.addClass('fixed-height');
  816. if (this.options.classes.split(' ').includes('table-bordered')) {
  817. this.$tableBody.append('<div class="fixed-table-border"></div>');
  818. this.$tableBorder = this.$tableBody.find('.fixed-table-border');
  819. this.$tableLoading.addClass('fixed-table-border');
  820. }
  821. }
  822. }
  823. }, {
  824. key: 'initTable',
  825. value: function initTable() {
  826. var _this = this;
  827. var columns = [];
  828. var data = [];
  829. this.$header = this.$el.find('>thead');
  830. if (!this.$header.length) {
  831. this.$header = $('<thead class="' + this.options.theadClasses + '"></thead>').appendTo(this.$el);
  832. } else if (this.options.theadClasses) {
  833. this.$header.addClass(this.options.theadClasses);
  834. }
  835. this.$header.find('tr').each(function (i, el) {
  836. var column = [];
  837. $(el).find('th').each(function (i, el) {
  838. // #2014: getFieldIndex and elsewhere assume this is string, causes issues if not
  839. if (typeof $(el).data('field') !== 'undefined') {
  840. $(el).data('field', '' + $(el).data('field'));
  841. }
  842. column.push($.extend({}, {
  843. title: $(el).html(),
  844. 'class': $(el).attr('class'),
  845. titleTooltip: $(el).attr('title'),
  846. rowspan: $(el).attr('rowspan') ? +$(el).attr('rowspan') : undefined,
  847. colspan: $(el).attr('colspan') ? +$(el).attr('colspan') : undefined
  848. }, $(el).data()));
  849. });
  850. columns.push(column);
  851. });
  852. if (!Array.isArray(this.options.columns[0])) {
  853. this.options.columns = [this.options.columns];
  854. }
  855. this.options.columns = $.extend(true, [], columns, this.options.columns);
  856. this.columns = [];
  857. this.fieldsColumnsIndex = [];
  858. Utils.setFieldIndex(this.options.columns);
  859. this.options.columns.forEach(function (columns, i) {
  860. columns.forEach(function (_column, j) {
  861. var column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, _column);
  862. if (typeof column.fieldIndex !== 'undefined') {
  863. _this.columns[column.fieldIndex] = column;
  864. _this.fieldsColumnsIndex[column.field] = column.fieldIndex;
  865. }
  866. _this.options.columns[i][j] = column;
  867. });
  868. });
  869. // if options.data is setting, do not process tbody data
  870. if (this.options.data.length) {
  871. return;
  872. }
  873. var m = [];
  874. this.$el.find('>tbody>tr').each(function (y, el) {
  875. var row = {};
  876. // save tr's id, class and data-* attributes
  877. row._id = $(el).attr('id');
  878. row._class = $(el).attr('class');
  879. row._data = Utils.getRealDataAttr($(el).data());
  880. $(el).find('>td').each(function (_x, el) {
  881. var cspan = +$(el).attr('colspan') || 1;
  882. var rspan = +$(el).attr('rowspan') || 1;
  883. var x = _x;
  884. // skip already occupied cells in current row
  885. for (; m[y] && m[y][x]; x++) {}
  886. // ignore
  887. // mark matrix elements occupied by current cell with true
  888. for (var tx = x; tx < x + cspan; tx++) {
  889. for (var ty = y; ty < y + rspan; ty++) {
  890. if (!m[ty]) {
  891. // fill missing rows
  892. m[ty] = [];
  893. }
  894. m[ty][tx] = true;
  895. }
  896. }
  897. var field = _this.columns[x].field;
  898. row[field] = $(el).html();
  899. // save td's id, class and data-* attributes
  900. row['_' + field + '_id'] = $(el).attr('id');
  901. row['_' + field + '_class'] = $(el).attr('class');
  902. row['_' + field + '_rowspan'] = $(el).attr('rowspan');
  903. row['_' + field + '_colspan'] = $(el).attr('colspan');
  904. row['_' + field + '_title'] = $(el).attr('title');
  905. row['_' + field + '_data'] = Utils.getRealDataAttr($(el).data());
  906. });
  907. data.push(row);
  908. });
  909. this.options.data = data;
  910. if (data.length) {
  911. this.fromHtml = true;
  912. }
  913. }
  914. }, {
  915. key: 'initHeader',
  916. value: function initHeader() {
  917. var _this2 = this;
  918. var visibleColumns = {};
  919. var html = [];
  920. this.header = {
  921. fields: [],
  922. styles: [],
  923. classes: [],
  924. formatters: [],
  925. events: [],
  926. sorters: [],
  927. sortNames: [],
  928. cellStyles: [],
  929. searchables: []
  930. };
  931. this.options.columns.forEach(function (columns, i) {
  932. html.push('<tr>');
  933. if (i === 0 && !_this2.options.cardView && _this2.options.detailView) {
  934. html.push('<th class="detail" rowspan="' + _this2.options.columns.length + '">\n <div class="fht-cell"></div>\n </th>\n ');
  935. }
  936. columns.forEach(function (column, j) {
  937. var text = '';
  938. var halign = ''; // header align style
  939. var align = ''; // body align style
  940. var style = '';
  941. var class_ = Utils.sprintf(' class="%s"', column['class']);
  942. var unitWidth = 'px';
  943. var width = column.width;
  944. if (column.width !== undefined && !_this2.options.cardView) {
  945. if (typeof column.width === 'string') {
  946. if (column.width.includes('%')) {
  947. unitWidth = '%';
  948. }
  949. }
  950. }
  951. if (column.width && typeof column.width === 'string') {
  952. width = column.width.replace('%', '').replace('px', '');
  953. }
  954. halign = Utils.sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  955. align = Utils.sprintf('text-align: %s; ', column.align);
  956. style = Utils.sprintf('vertical-align: %s; ', column.valign);
  957. style += Utils.sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? !column.showSelectTitle ? '36px' : undefined : width ? width + unitWidth : undefined);
  958. if (typeof column.fieldIndex !== 'undefined') {
  959. _this2.header.fields[column.fieldIndex] = column.field;
  960. _this2.header.styles[column.fieldIndex] = align + style;
  961. _this2.header.classes[column.fieldIndex] = class_;
  962. _this2.header.formatters[column.fieldIndex] = column.formatter;
  963. _this2.header.events[column.fieldIndex] = column.events;
  964. _this2.header.sorters[column.fieldIndex] = column.sorter;
  965. _this2.header.sortNames[column.fieldIndex] = column.sortName;
  966. _this2.header.cellStyles[column.fieldIndex] = column.cellStyle;
  967. _this2.header.searchables[column.fieldIndex] = column.searchable;
  968. if (!column.visible) {
  969. return;
  970. }
  971. if (_this2.options.cardView && !column.cardVisible) {
  972. return;
  973. }
  974. visibleColumns[column.field] = column;
  975. }
  976. html.push('<th' + Utils.sprintf(' title="%s"', column.titleTooltip), column.checkbox || column.radio ? Utils.sprintf(' class="bs-checkbox %s"', column['class'] || '') : class_, Utils.sprintf(' style="%s"', halign + style), Utils.sprintf(' rowspan="%s"', column.rowspan), Utils.sprintf(' colspan="%s"', column.colspan), Utils.sprintf(' data-field="%s"', column.field),
  977. // If `column` is not the first element of `this.options.columns[0]`, then className 'data-not-first-th' should be added.
  978. j === 0 && i > 0 ? ' data-not-first-th' : '', '>');
  979. html.push(Utils.sprintf('<div class="th-inner %s">', _this2.options.sortable && column.sortable ? 'sortable both' : ''));
  980. text = _this2.options.escape ? Utils.escapeHTML(column.title) : column.title;
  981. var title = text;
  982. if (column.checkbox) {
  983. text = '';
  984. if (!_this2.options.singleSelect && _this2.options.checkboxHeader) {
  985. text = '<input name="btSelectAll" type="checkbox" />';
  986. }
  987. _this2.header.stateField = column.field;
  988. }
  989. if (column.radio) {
  990. text = '';
  991. _this2.header.stateField = column.field;
  992. _this2.options.singleSelect = true;
  993. }
  994. if (!text && column.showSelectTitle) {
  995. text += title;
  996. }
  997. html.push(text);
  998. html.push('</div>');
  999. html.push('<div class="fht-cell"></div>');
  1000. html.push('</div>');
  1001. html.push('</th>');
  1002. });
  1003. html.push('</tr>');
  1004. });
  1005. this.$header.html(html.join(''));
  1006. this.$header.find('th[data-field]').each(function (i, el) {
  1007. $(el).data(visibleColumns[$(el).data('field')]);
  1008. });
  1009. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (e) {
  1010. var $this = $(e.currentTarget);
  1011. if (_this2.options.detailView && !$this.parent().hasClass('bs-checkbox')) {
  1012. if ($this.closest('.bootstrap-table')[0] !== _this2.$container[0]) {
  1013. return false;
  1014. }
  1015. }
  1016. if (_this2.options.sortable && $this.parent().data().sortable) {
  1017. _this2.onSort(e);
  1018. }
  1019. });
  1020. this.$header.children().children().off('keypress').on('keypress', function (e) {
  1021. if (_this2.options.sortable && $(e.currentTarget).data().sortable) {
  1022. var code = e.keyCode || e.which;
  1023. if (code === 13) {
  1024. // Enter keycode
  1025. _this2.onSort(e);
  1026. }
  1027. }
  1028. });
  1029. $(window).off('resize.bootstrap-table');
  1030. if (!this.options.showHeader || this.options.cardView) {
  1031. this.$header.hide();
  1032. this.$tableHeader.hide();
  1033. this.$tableLoading.css('top', 0);
  1034. } else {
  1035. this.$header.show();
  1036. this.$tableHeader.show();
  1037. this.$tableLoading.css('top', this.$header.outerHeight() + 1);
  1038. // Assign the correct sortable arrow
  1039. this.getCaret();
  1040. $(window).on('resize.bootstrap-table', $.proxy(this.resetWidth, this));
  1041. }
  1042. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  1043. this.$selectAll.off('click').on('click', function (_ref6) {
  1044. var currentTarget = _ref6.currentTarget;
  1045. var checked = $(currentTarget).prop('checked');
  1046. _this2[checked ? 'checkAll' : 'uncheckAll']();
  1047. _this2.updateSelected();
  1048. });
  1049. }
  1050. }, {
  1051. key: 'initFooter',
  1052. value: function initFooter() {
  1053. if (!this.options.showFooter || this.options.cardView) {
  1054. this.$tableFooter.hide();
  1055. } else {
  1056. this.$tableFooter.show();
  1057. }
  1058. }
  1059. }, {
  1060. key: 'initData',
  1061. value: function initData(data, type) {
  1062. if (type === 'append') {
  1063. this.options.data = this.options.data.concat(data);
  1064. } else if (type === 'prepend') {
  1065. this.options.data = [].concat(data).concat(this.options.data);
  1066. } else {
  1067. this.options.data = data || this.options.data;
  1068. }
  1069. this.data = this.options.data;
  1070. if (this.options.sidePagination === 'server') {
  1071. return;
  1072. }
  1073. this.initSort();
  1074. }
  1075. }, {
  1076. key: 'initSort',
  1077. value: function initSort() {
  1078. var _this3 = this;
  1079. var name = this.options.sortName;
  1080. var order = this.options.sortOrder === 'desc' ? -1 : 1;
  1081. var index = this.header.fields.indexOf(this.options.sortName);
  1082. var timeoutId = 0;
  1083. if (index !== -1) {
  1084. if (this.options.sortStable) {
  1085. this.data.forEach(function (row, i) {
  1086. if (!row.hasOwnProperty('_position')) {
  1087. row._position = i;
  1088. }
  1089. });
  1090. }
  1091. if (this.options.customSort) {
  1092. Utils.calculateObjectValue(this.options, this.options.customSort, [this.options.sortName, this.options.sortOrder, this.data]);
  1093. } else {
  1094. this.data.sort(function (a, b) {
  1095. if (_this3.header.sortNames[index]) {
  1096. name = _this3.header.sortNames[index];
  1097. }
  1098. var aa = Utils.getItemField(a, name, _this3.options.escape);
  1099. var bb = Utils.getItemField(b, name, _this3.options.escape);
  1100. var value = Utils.calculateObjectValue(_this3.header, _this3.header.sorters[index], [aa, bb, a, b]);
  1101. if (value !== undefined) {
  1102. if (_this3.options.sortStable && value === 0) {
  1103. return order * (a._position - b._position);
  1104. }
  1105. return order * value;
  1106. }
  1107. // Fix #161: undefined or null string sort bug.
  1108. if (aa === undefined || aa === null) {
  1109. aa = '';
  1110. }
  1111. if (bb === undefined || bb === null) {
  1112. bb = '';
  1113. }
  1114. if (_this3.options.sortStable && aa === bb) {
  1115. aa = a._position;
  1116. bb = b._position;
  1117. }
  1118. // IF both values are numeric, do a numeric comparison
  1119. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  1120. // Convert numerical values form string to float.
  1121. aa = parseFloat(aa);
  1122. bb = parseFloat(bb);
  1123. if (aa < bb) {
  1124. return order * -1;
  1125. }
  1126. if (aa > bb) {
  1127. return order;
  1128. }
  1129. return 0;
  1130. }
  1131. if (aa === bb) {
  1132. return 0;
  1133. }
  1134. // If value is not a string, convert to string
  1135. if (typeof aa !== 'string') {
  1136. aa = aa.toString();
  1137. }
  1138. if (aa.localeCompare(bb) === -1) {
  1139. return order * -1;
  1140. }
  1141. return order;
  1142. });
  1143. }
  1144. if (this.options.sortClass !== undefined) {
  1145. clearTimeout(timeoutId);
  1146. timeoutId = setTimeout(function () {
  1147. _this3.$el.removeClass(_this3.options.sortClass);
  1148. var index = _this3.$header.find('[data-field="' + _this3.options.sortName + '"]').index();
  1149. _this3.$el.find('tr td:nth-child(' + (index + 1) + ')').addClass(_this3.options.sortClass);
  1150. }, 250);
  1151. }
  1152. }
  1153. }
  1154. }, {
  1155. key: 'onSort',
  1156. value: function onSort(_ref7) {
  1157. var type = _ref7.type,
  1158. currentTarget = _ref7.currentTarget;
  1159. var $this = type === 'keypress' ? $(currentTarget) : $(currentTarget).parent();
  1160. var $this_ = this.$header.find('th').eq($this.index());
  1161. this.$header.add(this.$header_).find('span.order').remove();
  1162. if (this.options.sortName === $this.data('field')) {
  1163. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  1164. } else {
  1165. this.options.sortName = $this.data('field');
  1166. if (this.options.rememberOrder) {
  1167. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  1168. } else {
  1169. this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].order;
  1170. }
  1171. }
  1172. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  1173. $this.add($this_).data('order', this.options.sortOrder);
  1174. // Assign the correct sortable arrow
  1175. this.getCaret();
  1176. if (this.options.sidePagination === 'server') {
  1177. this.initServer(this.options.silentSort);
  1178. return;
  1179. }
  1180. this.initSort();
  1181. this.initBody();
  1182. }
  1183. }, {
  1184. key: 'initToolbar',
  1185. value: function initToolbar() {
  1186. var _this4 = this;
  1187. var html = [];
  1188. var timeoutId = 0;
  1189. var $keepOpen = void 0;
  1190. var $search = void 0;
  1191. var switchableCount = 0;
  1192. if (this.$toolbar.find('.bs-bars').children().length) {
  1193. $('body').append($(this.options.toolbar));
  1194. }
  1195. this.$toolbar.html('');
  1196. if (typeof this.options.toolbar === 'string' || _typeof(this.options.toolbar) === 'object') {
  1197. $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', bootstrap.classes.pull, this.options.toolbarAlign)).appendTo(this.$toolbar).append($(this.options.toolbar));
  1198. }
  1199. // showColumns, showToggle, showRefresh
  1200. html = [Utils.sprintf('<div class="columns columns-%s btn-group %s-%s">', this.options.buttonsAlign, bootstrap.classes.pull, this.options.buttonsAlign)];
  1201. if (typeof this.options.icons === 'string') {
  1202. this.options.icons = Utils.calculateObjectValue(null, this.options.icons);
  1203. }
  1204. if (this.options.showPaginationSwitch) {
  1205. html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="paginationSwitch" aria-label="pagination Switch" title="%s">', this.options.formatPaginationSwitch()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown), '</button>');
  1206. }
  1207. if (this.options.showFullscreen) {
  1208. this.$toolbar.find('button[name="fullscreen"]').off('click').on('click', $.proxy(this.toggleFullscreen, this));
  1209. }
  1210. if (this.options.showRefresh) {
  1211. html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="refresh" aria-label="refresh" title="%s">', this.options.formatRefresh()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh), '</button>');
  1212. }
  1213. if (this.options.showToggle) {
  1214. html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="toggle" aria-label="toggle" title="%s">', this.options.formatToggle()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggleOff), '</button>');
  1215. }
  1216. if (this.options.showFullscreen) {
  1217. html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="fullscreen" aria-label="fullscreen" title="%s">', this.options.formatFullscreen()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.fullscreen), '</button>');
  1218. }
  1219. if (this.options.showColumns) {
  1220. html.push(Utils.sprintf('<div class="keep-open btn-group" title="%s">', this.options.formatColumns()), '<button type="button" aria-label="columns" class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">', Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns), ' <span class="caret"></span>', '</button>', bootstrap.html.toobarDropdow[0]);
  1221. this.columns.forEach(function (column, i) {
  1222. if (column.radio || column.checkbox) {
  1223. return;
  1224. }
  1225. if (_this4.options.cardView && !column.cardVisible) {
  1226. return;
  1227. }
  1228. var checked = column.visible ? ' checked="checked"' : '';
  1229. if (column.switchable) {
  1230. html.push(Utils.sprintf(bootstrap.html.toobarDropdowItem, Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s> %s', column.field, i, checked, column.title)));
  1231. switchableCount++;
  1232. }
  1233. });
  1234. html.push(bootstrap.html.toobarDropdow[1], '</div>');
  1235. }
  1236. html.push('</div>');
  1237. // Fix #188: this.showToolbar is for extensions
  1238. if (this.showToolbar || html.length > 2) {
  1239. this.$toolbar.append(html.join(''));
  1240. }
  1241. if (this.options.showPaginationSwitch) {
  1242. this.$toolbar.find('button[name="paginationSwitch"]').off('click').on('click', $.proxy(this.togglePagination, this));
  1243. }
  1244. if (this.options.showRefresh) {
  1245. this.$toolbar.find('button[name="refresh"]').off('click').on('click', $.proxy(this.refresh, this));
  1246. }
  1247. if (this.options.showToggle) {
  1248. this.$toolbar.find('button[name="toggle"]').off('click').on('click', function () {
  1249. _this4.toggleView();
  1250. });
  1251. }
  1252. if (this.options.showColumns) {
  1253. $keepOpen = this.$toolbar.find('.keep-open');
  1254. if (switchableCount <= this.options.minimumCountColumns) {
  1255. $keepOpen.find('input').prop('disabled', true);
  1256. }
  1257. $keepOpen.find('li').off('click').on('click', function (e) {
  1258. e.stopImmediatePropagation();
  1259. });
  1260. $keepOpen.find('input').off('click').on('click', function (_ref8) {
  1261. var currentTarget = _ref8.currentTarget;
  1262. var $this = $(currentTarget);
  1263. _this4.toggleColumn($this.val(), $this.prop('checked'), false);
  1264. _this4.trigger('column-switch', $this.data('field'), $this.prop('checked'));
  1265. });
  1266. }
  1267. if (this.options.search) {
  1268. html = [];
  1269. html.push(Utils.sprintf('<div class="%s-%s search">', bootstrap.classes.pull, this.options.searchAlign), Utils.sprintf('<input class="form-control' + Utils.sprintf(' input-%s', this.options.iconSize) + '" type="text" placeholder="%s">', this.options.formatSearch()), '</div>');
  1270. this.$toolbar.append(html.join(''));
  1271. $search = this.$toolbar.find('.search input');
  1272. $search.off('keyup drop blur').on('keyup drop blur', function (event) {
  1273. if (_this4.options.searchOnEnterKey && event.keyCode !== 13) {
  1274. return;
  1275. }
  1276. if ([37, 38, 39, 40].includes(event.keyCode)) {
  1277. return;
  1278. }
  1279. clearTimeout(timeoutId); // doesn't matter if it's 0
  1280. timeoutId = setTimeout(function () {
  1281. _this4.onSearch(event);
  1282. }, _this4.options.searchTimeOut);
  1283. });
  1284. if (Utils.isIEBrowser()) {
  1285. $search.off('mouseup').on('mouseup', function (event) {
  1286. clearTimeout(timeoutId); // doesn't matter if it's 0
  1287. timeoutId = setTimeout(function () {
  1288. _this4.onSearch(event);
  1289. }, _this4.options.searchTimeOut);
  1290. });
  1291. }
  1292. }
  1293. }
  1294. }, {
  1295. key: 'onSearch',
  1296. value: function onSearch(_ref9) {
  1297. var currentTarget = _ref9.currentTarget,
  1298. firedByInitSearchText = _ref9.firedByInitSearchText;
  1299. var text = $.trim($(currentTarget).val());
  1300. // trim search input
  1301. if (this.options.trimOnSearch && $(currentTarget).val() !== text) {
  1302. $(currentTarget).val(text);
  1303. }
  1304. if (text === this.searchText) {
  1305. return;
  1306. }
  1307. this.searchText = text;
  1308. this.options.searchText = text;
  1309. if (!firedByInitSearchText) {
  1310. this.options.pageNumber = 1;
  1311. }
  1312. this.initSearch();
  1313. if (firedByInitSearchText) {
  1314. if (this.options.sidePagination === 'client') {
  1315. this.updatePagination();
  1316. }
  1317. } else {
  1318. this.updatePagination();
  1319. }
  1320. this.trigger('search', text);
  1321. }
  1322. }, {
  1323. key: 'initSearch',
  1324. value: function initSearch() {
  1325. var _this5 = this;
  1326. if (this.options.sidePagination !== 'server') {
  1327. if (this.options.customSearch) {
  1328. Utils.calculateObjectValue(this.options, this.options.customSearch, [this.searchText]);
  1329. return;
  1330. }
  1331. var s = this.searchText && (this.options.escape ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase();
  1332. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  1333. // Check filter
  1334. this.data = f ? this.options.data.filter(function (item, i) {
  1335. for (var key in f) {
  1336. if (Array.isArray(f[key]) && !f[key].includes(item[key]) || !Array.isArray(f[key]) && item[key] !== f[key]) {
  1337. return false;
  1338. }
  1339. }
  1340. return true;
  1341. }) : this.options.data;
  1342. this.data = s ? this.data.filter(function (item, i) {
  1343. for (var j = 0; j < _this5.header.fields.length; j++) {
  1344. if (!_this5.header.searchables[j]) {
  1345. continue;
  1346. }
  1347. var key = $.isNumeric(_this5.header.fields[j]) ? parseInt(_this5.header.fields[j], 10) : _this5.header.fields[j];
  1348. var column = _this5.columns[_this5.fieldsColumnsIndex[key]];
  1349. var value = void 0;
  1350. if (typeof key === 'string') {
  1351. value = item;
  1352. var props = key.split('.');
  1353. for (var _i2 = 0; _i2 < props.length; _i2++) {
  1354. if (value[props[_i2]] !== null) {
  1355. value = value[props[_i2]];
  1356. }
  1357. }
  1358. } else {
  1359. value = item[key];
  1360. }
  1361. // Fix #142: respect searchForamtter boolean
  1362. if (column && column.searchFormatter) {
  1363. value = Utils.calculateObjectValue(column, _this5.header.formatters[j], [value, item, i], value);
  1364. }
  1365. if (typeof value === 'string' || typeof value === 'number') {
  1366. if (_this5.options.strictSearch) {
  1367. if (('' + value).toLowerCase() === s) {
  1368. return true;
  1369. }
  1370. } else {
  1371. if (('' + value).toLowerCase().includes(s)) {
  1372. return true;
  1373. }
  1374. }
  1375. }
  1376. }
  1377. return false;
  1378. }) : this.data;
  1379. }
  1380. }
  1381. }, {
  1382. key: 'initPagination',
  1383. value: function initPagination() {
  1384. var _this6 = this;
  1385. if (!this.options.pagination) {
  1386. this.$pagination.hide();
  1387. return;
  1388. }
  1389. this.$pagination.show();
  1390. var html = [];
  1391. var $allSelected = false;
  1392. var i = void 0;
  1393. var from = void 0;
  1394. var to = void 0;
  1395. var $pageList = void 0;
  1396. var $pre = void 0;
  1397. var $next = void 0;
  1398. var $number = void 0;
  1399. var data = this.getData();
  1400. var pageList = this.options.pageList;
  1401. if (this.options.sidePagination !== 'server') {
  1402. this.options.totalRows = data.length;
  1403. }
  1404. this.totalPages = 0;
  1405. if (this.options.totalRows) {
  1406. if (this.options.pageSize === this.options.formatAllRows()) {
  1407. this.options.pageSize = this.options.totalRows;
  1408. $allSelected = true;
  1409. } else if (this.options.pageSize === this.options.totalRows) {
  1410. // Fix #667 Table with pagination,
  1411. // multiple pages and a search this matches to one page throws exception
  1412. var pageLst = typeof this.options.pageList === 'string' ? this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
  1413. if (pageLst.includes(this.options.formatAllRows().toLowerCase())) {
  1414. $allSelected = true;
  1415. }
  1416. }
  1417. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  1418. this.options.totalPages = this.totalPages;
  1419. }
  1420. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  1421. this.options.pageNumber = this.totalPages;
  1422. }
  1423. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  1424. this.pageTo = this.options.pageNumber * this.options.pageSize;
  1425. if (this.pageTo > this.options.totalRows) {
  1426. this.pageTo = this.options.totalRows;
  1427. }
  1428. html.push(Utils.sprintf('<div class="%s-%s pagination-detail">', bootstrap.classes.pull, this.options.paginationDetailHAlign), '<span class="pagination-info">', this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) : this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows), '</span>');
  1429. if (!this.options.onlyInfoPagination) {
  1430. html.push('<span class="page-list">');
  1431. var pageNumber = [Utils.sprintf('<span class="btn-group %s">', this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ? 'dropdown' : 'dropup'), '<button type="button" class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">', '<span class="page-size">', $allSelected ? this.options.formatAllRows() : this.options.pageSize, '</span>', ' <span class="caret"></span>', '</button>', bootstrap.html.pageDropdown[0]];
  1432. if (typeof this.options.pageList === 'string') {
  1433. var list = this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').split(',');
  1434. pageList = [];
  1435. var _iteratorNormalCompletion9 = true;
  1436. var _didIteratorError9 = false;
  1437. var _iteratorError9 = undefined;
  1438. try {
  1439. for (var _iterator9 = list[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
  1440. var value = _step9.value;
  1441. pageList.push(value.toUpperCase() === this.options.formatAllRows().toUpperCase() || value.toUpperCase() === 'UNLIMITED' ? this.options.formatAllRows() : +value);
  1442. }
  1443. } catch (err) {
  1444. _didIteratorError9 = true;
  1445. _iteratorError9 = err;
  1446. } finally {
  1447. try {
  1448. if (!_iteratorNormalCompletion9 && _iterator9.return) {
  1449. _iterator9.return();
  1450. }
  1451. } finally {
  1452. if (_didIteratorError9) {
  1453. throw _iteratorError9;
  1454. }
  1455. }
  1456. }
  1457. }
  1458. pageList.forEach(function (page, i) {
  1459. if (!_this6.options.smartDisplay || i === 0 || pageList[i - 1] < _this6.options.totalRows) {
  1460. var active = void 0;
  1461. if ($allSelected) {
  1462. active = page === _this6.options.formatAllRows() ? 'active' : '';
  1463. } else {
  1464. active = page === _this6.options.pageSize ? 'active' : '';
  1465. }
  1466. pageNumber.push(Utils.sprintf(bootstrap.html.pageDropdownItem, active, page));
  1467. }
  1468. });
  1469. pageNumber.push(bootstrap.html.pageDropdown[1] + '</span>');
  1470. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  1471. html.push('</span>');
  1472. html.push('</div>', Utils.sprintf('<div class="%s-%s pagination">', bootstrap.classes.pull, this.options.paginationHAlign), '<ul class="pagination' + Utils.sprintf(' pagination-%s', this.options.iconSize) + '">', Utils.sprintf('<li class="page-item page-pre"><a class="page-link" href="#">%s</a></li>', this.options.paginationPreText));
  1473. if (this.totalPages < this.options.paginationSuccessivelySize) {
  1474. from = 1;
  1475. to = this.totalPages;
  1476. } else {
  1477. from = this.options.pageNumber - this.options.paginationPagesBySide;
  1478. to = from + this.options.paginationPagesBySide * 2;
  1479. }
  1480. if (this.options.pageNumber < this.options.paginationSuccessivelySize - 1) {
  1481. to = this.options.paginationSuccessivelySize;
  1482. }
  1483. if (to > this.totalPages) {
  1484. to = this.totalPages;
  1485. }
  1486. if (this.options.paginationSuccessivelySize > this.totalPages - from) {
  1487. from = from - (this.options.paginationSuccessivelySize - (this.totalPages - from)) + 1;
  1488. }
  1489. if (from < 1) {
  1490. from = 1;
  1491. }
  1492. if (to > this.totalPages) {
  1493. to = this.totalPages;
  1494. }
  1495. var middleSize = Math.round(this.options.paginationPagesBySide / 2);
  1496. var pageItem = function pageItem(i) {
  1497. var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
  1498. return '\n <li class="page-item' + classes + (i === _this6.options.pageNumber ? ' active' : '') + '">\n <a class="page-link" href="#">' + i + '</a>\n </li>\n ';
  1499. };
  1500. if (from > 1) {
  1501. var max = this.options.paginationPagesBySide;
  1502. if (max >= from) max = from - 1;
  1503. for (i = 1; i <= max; i++) {
  1504. html.push(pageItem(i));
  1505. }
  1506. if (from - 1 === max + 1) {
  1507. i = from - 1;
  1508. html.push(pageItem(i));
  1509. } else {
  1510. if (from - 1 > max) {
  1511. if (from - this.options.paginationPagesBySide * 2 > this.options.paginationPagesBySide && this.options.paginationUseIntermediate) {
  1512. i = Math.round((from - middleSize) / 2 + middleSize);
  1513. html.push(pageItem(i, ' page-intermediate'));
  1514. } else {
  1515. html.push('\n <li class="page-item page-first-separator disabled">\n <a class="page-link" href="#">...</a>\n </li>');
  1516. }
  1517. }
  1518. }
  1519. }
  1520. for (i = from; i <= to; i++) {
  1521. html.push(pageItem(i));
  1522. }
  1523. if (this.totalPages > to) {
  1524. var min = this.totalPages - (this.options.paginationPagesBySide - 1);
  1525. if (to >= min) min = to + 1;
  1526. if (to + 1 === min - 1) {
  1527. i = to + 1;
  1528. html.push(pageItem(i));
  1529. } else {
  1530. if (min > to + 1) {
  1531. if (this.totalPages - to > this.options.paginationPagesBySide * 2 && this.options.paginationUseIntermediate) {
  1532. i = Math.round((this.totalPages - middleSize - to) / 2 + to);
  1533. html.push(pageItem(i, ' page-intermediate'));
  1534. } else {
  1535. html.push('\n <li class="page-item page-last-separator disabled">\n <a class="page-link" href="#">...</a>\n </li>');
  1536. }
  1537. }
  1538. }
  1539. for (i = min; i <= this.totalPages; i++) {
  1540. html.push(pageItem(i));
  1541. }
  1542. }
  1543. html.push('\n <li class="page-item page-next">\n <a class="page-link" href="#">' + this.options.paginationNextText + '</a>\n </li>\n </ul>\n </div>\n ');
  1544. }
  1545. this.$pagination.html(html.join(''));
  1546. if (!this.options.onlyInfoPagination) {
  1547. $pageList = this.$pagination.find('.page-list a');
  1548. $pre = this.$pagination.find('.page-pre');
  1549. $next = this.$pagination.find('.page-next');
  1550. $number = this.$pagination.find('.page-item').not('.page-next, .page-pre');
  1551. if (this.options.smartDisplay) {
  1552. if (this.totalPages <= 1) {
  1553. this.$pagination.find('div.pagination').hide();
  1554. }
  1555. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  1556. this.$pagination.find('span.page-list').hide();
  1557. }
  1558. // when data is empty, hide the pagination
  1559. this.$pagination[this.getData().length ? 'show' : 'hide']();
  1560. }
  1561. if (!this.options.paginationLoop) {
  1562. if (this.options.pageNumber === 1) {
  1563. $pre.addClass('disabled');
  1564. }
  1565. if (this.options.pageNumber === this.totalPages) {
  1566. $next.addClass('disabled');
  1567. }
  1568. }
  1569. if ($allSelected) {
  1570. this.options.pageSize = this.options.formatAllRows();
  1571. }
  1572. // removed the events for last and first, onPageNumber executeds the same logic
  1573. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  1574. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1575. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1576. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1577. }
  1578. }
  1579. }, {
  1580. key: 'updatePagination',
  1581. value: function updatePagination(event) {
  1582. // Fix #171: IE disabled button can be clicked bug.
  1583. if (event && $(event.currentTarget).hasClass('disabled')) {
  1584. return;
  1585. }
  1586. if (!this.options.maintainSelected) {
  1587. this.resetRows();
  1588. }
  1589. this.initPagination();
  1590. if (this.options.sidePagination === 'server') {
  1591. this.initServer();
  1592. } else {
  1593. this.initBody();
  1594. }
  1595. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1596. }
  1597. }, {
  1598. key: 'onPageListChange',
  1599. value: function onPageListChange(event) {
  1600. event.preventDefault();
  1601. var $this = $(event.currentTarget);
  1602. $this.parent().addClass('active').siblings().removeClass('active');
  1603. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ? this.options.formatAllRows() : +$this.text();
  1604. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1605. this.updatePagination(event);
  1606. return false;
  1607. }
  1608. }, {
  1609. key: 'onPagePre',
  1610. value: function onPagePre(event) {
  1611. event.preventDefault();
  1612. if (this.options.pageNumber - 1 === 0) {
  1613. this.options.pageNumber = this.options.totalPages;
  1614. } else {
  1615. this.options.pageNumber--;
  1616. }
  1617. this.updatePagination(event);
  1618. return false;
  1619. }
  1620. }, {
  1621. key: 'onPageNext',
  1622. value: function onPageNext(event) {
  1623. event.preventDefault();
  1624. if (this.options.pageNumber + 1 > this.options.totalPages) {
  1625. this.options.pageNumber = 1;
  1626. } else {
  1627. this.options.pageNumber++;
  1628. }
  1629. this.updatePagination(event);
  1630. return false;
  1631. }
  1632. }, {
  1633. key: 'onPageNumber',
  1634. value: function onPageNumber(event) {
  1635. event.preventDefault();
  1636. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1637. return;
  1638. }
  1639. this.options.pageNumber = +$(event.currentTarget).text();
  1640. this.updatePagination(event);
  1641. return false;
  1642. }
  1643. }, {
  1644. key: 'initRow',
  1645. value: function initRow(item, i, data, parentDom) {
  1646. var _this7 = this;
  1647. var html = [];
  1648. var style = {};
  1649. var csses = [];
  1650. var data_ = '';
  1651. var attributes = {};
  1652. var htmlAttributes = [];
  1653. if (Utils.findIndex(this.hiddenRows, item) > -1) {
  1654. return;
  1655. }
  1656. style = Utils.calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1657. if (style && style.css) {
  1658. var _iteratorNormalCompletion10 = true;
  1659. var _didIteratorError10 = false;
  1660. var _iteratorError10 = undefined;
  1661. try {
  1662. for (var _iterator10 = Object.entries(style.css)[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
  1663. var _ref10 = _step10.value;
  1664. var _ref11 = _slicedToArray(_ref10, 2);
  1665. var key = _ref11[0];
  1666. var value = _ref11[1];
  1667. csses.push(key + ': ' + value);
  1668. }
  1669. } catch (err) {
  1670. _didIteratorError10 = true;
  1671. _iteratorError10 = err;
  1672. } finally {
  1673. try {
  1674. if (!_iteratorNormalCompletion10 && _iterator10.return) {
  1675. _iterator10.return();
  1676. }
  1677. } finally {
  1678. if (_didIteratorError10) {
  1679. throw _iteratorError10;
  1680. }
  1681. }
  1682. }
  1683. }
  1684. attributes = Utils.calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes);
  1685. if (attributes) {
  1686. var _iteratorNormalCompletion11 = true;
  1687. var _didIteratorError11 = false;
  1688. var _iteratorError11 = undefined;
  1689. try {
  1690. for (var _iterator11 = Object.entries(attributes)[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
  1691. var _ref12 = _step11.value;
  1692. var _ref13 = _slicedToArray(_ref12, 2);
  1693. var _key2 = _ref13[0];
  1694. var _value2 = _ref13[1];
  1695. htmlAttributes.push(_key2 + '="' + Utils.escapeHTML(_value2) + '"');
  1696. }
  1697. } catch (err) {
  1698. _didIteratorError11 = true;
  1699. _iteratorError11 = err;
  1700. } finally {
  1701. try {
  1702. if (!_iteratorNormalCompletion11 && _iterator11.return) {
  1703. _iterator11.return();
  1704. }
  1705. } finally {
  1706. if (_didIteratorError11) {
  1707. throw _iteratorError11;
  1708. }
  1709. }
  1710. }
  1711. }
  1712. if (item._data && !$.isEmptyObject(item._data)) {
  1713. var _iteratorNormalCompletion12 = true;
  1714. var _didIteratorError12 = false;
  1715. var _iteratorError12 = undefined;
  1716. try {
  1717. for (var _iterator12 = Object.entries(item._data)[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
  1718. var _ref14 = _step12.value;
  1719. var _ref15 = _slicedToArray(_ref14, 2);
  1720. var k = _ref15[0];
  1721. var v = _ref15[1];
  1722. // ignore data-index
  1723. if (k === 'index') {
  1724. return;
  1725. }
  1726. data_ += ' data-' + k + '="' + v + '"';
  1727. }
  1728. } catch (err) {
  1729. _didIteratorError12 = true;
  1730. _iteratorError12 = err;
  1731. } finally {
  1732. try {
  1733. if (!_iteratorNormalCompletion12 && _iterator12.return) {
  1734. _iterator12.return();
  1735. }
  1736. } finally {
  1737. if (_didIteratorError12) {
  1738. throw _iteratorError12;
  1739. }
  1740. }
  1741. }
  1742. }
  1743. 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)), ' data-index="' + i + '"', Utils.sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]), Utils.sprintf('%s', data_), '>');
  1744. if (this.options.cardView) {
  1745. html.push('<td colspan="' + this.header.fields.length + '"><div class="card-views">');
  1746. }
  1747. if (!this.options.cardView && this.options.detailView) {
  1748. html.push('<td>');
  1749. if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) {
  1750. html.push('\n <a class="detail-icon" href="#">\n <i class="' + this.options.iconsPrefix + ' ' + this.options.icons.detailOpen + '"></i>\n </a>\n ');
  1751. }
  1752. html.push('</td>');
  1753. }
  1754. this.header.fields.forEach(function (field, j) {
  1755. var text = '';
  1756. var value_ = Utils.getItemField(item, field, _this7.options.escape);
  1757. var value = '';
  1758. var type = '';
  1759. var cellStyle = {};
  1760. var id_ = '';
  1761. var class_ = _this7.header.classes[j];
  1762. var style_ = '';
  1763. var data_ = '';
  1764. var rowspan_ = '';
  1765. var colspan_ = '';
  1766. var title_ = '';
  1767. var column = _this7.columns[j];
  1768. if (_this7.fromHtml && typeof value_ === 'undefined') {
  1769. if (!column.checkbox && !column.radio) {
  1770. return;
  1771. }
  1772. }
  1773. if (!column.visible) {
  1774. return;
  1775. }
  1776. if (_this7.options.cardView && !column.cardVisible) {
  1777. return;
  1778. }
  1779. if (column.escape) {
  1780. value_ = Utils.escapeHTML(value_);
  1781. }
  1782. if (csses.concat([_this7.header.styles[j]]).length) {
  1783. style_ = ' style="' + csses.concat([_this7.header.styles[j]]).join('; ') + '"';
  1784. }
  1785. // handle td's id and class
  1786. if (item['_' + field + '_id']) {
  1787. id_ = Utils.sprintf(' id="%s"', item['_' + field + '_id']);
  1788. }
  1789. if (item['_' + field + '_class']) {
  1790. class_ = Utils.sprintf(' class="%s"', item['_' + field + '_class']);
  1791. }
  1792. if (item['_' + field + '_rowspan']) {
  1793. rowspan_ = Utils.sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1794. }
  1795. if (item['_' + field + '_colspan']) {
  1796. colspan_ = Utils.sprintf(' colspan="%s"', item['_' + field + '_colspan']);
  1797. }
  1798. if (item['_' + field + '_title']) {
  1799. title_ = Utils.sprintf(' title="%s"', item['_' + field + '_title']);
  1800. }
  1801. cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle);
  1802. if (cellStyle.classes) {
  1803. class_ = ' class="' + cellStyle.classes + '"';
  1804. }
  1805. if (cellStyle.css) {
  1806. var csses_ = [];
  1807. var _iteratorNormalCompletion13 = true;
  1808. var _didIteratorError13 = false;
  1809. var _iteratorError13 = undefined;
  1810. try {
  1811. for (var _iterator13 = Object.entries(cellStyle.css)[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
  1812. var _ref16 = _step13.value;
  1813. var _ref17 = _slicedToArray(_ref16, 2);
  1814. var _key3 = _ref17[0];
  1815. var _value3 = _ref17[1];
  1816. csses_.push(_key3 + ': ' + _value3);
  1817. }
  1818. } catch (err) {
  1819. _didIteratorError13 = true;
  1820. _iteratorError13 = err;
  1821. } finally {
  1822. try {
  1823. if (!_iteratorNormalCompletion13 && _iterator13.return) {
  1824. _iterator13.return();
  1825. }
  1826. } finally {
  1827. if (_didIteratorError13) {
  1828. throw _iteratorError13;
  1829. }
  1830. }
  1831. }
  1832. style_ = ' style="' + csses_.concat(_this7.header.styles[j]).join('; ') + '"';
  1833. }
  1834. value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_);
  1835. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1836. var _iteratorNormalCompletion14 = true;
  1837. var _didIteratorError14 = false;
  1838. var _iteratorError14 = undefined;
  1839. try {
  1840. for (var _iterator14 = Object.entries(item['_' + field + '_data'])[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
  1841. var _ref18 = _step14.value;
  1842. var _ref19 = _slicedToArray(_ref18, 2);
  1843. var _k2 = _ref19[0];
  1844. var _v = _ref19[1];
  1845. // ignore data-index
  1846. if (_k2 === 'index') {
  1847. return;
  1848. }
  1849. data_ += ' data-' + _k2 + '="' + _v + '"';
  1850. }
  1851. } catch (err) {
  1852. _didIteratorError14 = true;
  1853. _iteratorError14 = err;
  1854. } finally {
  1855. try {
  1856. if (!_iteratorNormalCompletion14 && _iterator14.return) {
  1857. _iterator14.return();
  1858. }
  1859. } finally {
  1860. if (_didIteratorError14) {
  1861. throw _iteratorError14;
  1862. }
  1863. }
  1864. }
  1865. }
  1866. if (column.checkbox || column.radio) {
  1867. type = column.checkbox ? 'checkbox' : type;
  1868. type = column.radio ? 'radio' : type;
  1869. var c = column['class'] || '';
  1870. var isChecked = value === true || value_ || value && value.checked;
  1871. var isDisabled = !column.checkboxEnabled || value && value.disabled;
  1872. text = [_this7.options.cardView ? '<div class="card-view ' + c + '">' : '<td class="bs-checkbox ' + c + '">', '<input\n data-index="' + i + '"\n name="' + _this7.options.selectItemName + '"\n type="' + type + '"\n ' + Utils.sprintf('value="%s"', item[_this7.options.idField]) + '\n ' + Utils.sprintf('checked="%s"', isChecked ? 'checked' : undefined) + '\n ' + Utils.sprintf('disabled="%s"', isDisabled ? 'disabled' : undefined) + ' />', _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '</div>' : '</td>'].join('');
  1873. item[_this7.header.stateField] = value === true || !!value_ || value && value.checked;
  1874. } else {
  1875. value = typeof value === 'undefined' || value === null ? _this7.options.undefinedText : value;
  1876. if (_this7.options.cardView) {
  1877. var cardTitle = _this7.options.showHeader ? '<span class="title"' + style + '>' + Utils.getFieldTitle(_this7.columns, field) + '</span>' : '';
  1878. text = '<div class="card-view">' + cardTitle + '<span class="value">' + value + '</span></div>';
  1879. if (_this7.options.smartDisplay && value === '') {
  1880. text = '<div class="card-view"></div>';
  1881. }
  1882. } else {
  1883. text = '<td' + id_ + class_ + style_ + data_ + rowspan_ + colspan_ + title_ + '>' + value + '</td>';
  1884. }
  1885. }
  1886. html.push(text);
  1887. });
  1888. if (this.options.cardView) {
  1889. html.push('</div></td>');
  1890. }
  1891. html.push('</tr>');
  1892. return html.join('');
  1893. }
  1894. }, {
  1895. key: 'initBody',
  1896. value: function initBody(fixedScroll) {
  1897. var _this8 = this;
  1898. var data = this.getData();
  1899. this.trigger('pre-body', data);
  1900. this.$body = this.$el.find('>tbody');
  1901. if (!this.$body.length) {
  1902. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1903. }
  1904. // Fix #389 Bootstrap-table-flatJSON is not working
  1905. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1906. this.pageFrom = 1;
  1907. this.pageTo = data.length;
  1908. }
  1909. var trFragments = $(document.createDocumentFragment());
  1910. var hasTr = false;
  1911. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1912. var item = data[i];
  1913. var tr = this.initRow(item, i, data, trFragments);
  1914. hasTr = hasTr || !!tr;
  1915. if (tr && typeof tr === 'string') {
  1916. trFragments.append(tr);
  1917. }
  1918. }
  1919. // show no records
  1920. if (!hasTr) {
  1921. this.$body.html('<tr class="no-records-found">' + Utils.sprintf('<td colspan="%s">%s</td>', this.$header.find('th').length, this.options.formatNoMatches()) + '</tr>');
  1922. } else {
  1923. this.$body.html(trFragments);
  1924. }
  1925. if (!fixedScroll) {
  1926. this.scrollTo(0);
  1927. }
  1928. // click to select by column
  1929. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (_ref20) {
  1930. var currentTarget = _ref20.currentTarget,
  1931. type = _ref20.type,
  1932. target = _ref20.target;
  1933. var $td = $(currentTarget);
  1934. var $tr = $td.parent();
  1935. var item = _this8.data[$tr.data('index')];
  1936. var index = $td[0].cellIndex;
  1937. var fields = _this8.getVisibleFields();
  1938. var field = fields[_this8.options.detailView && !_this8.options.cardView ? index - 1 : index];
  1939. var column = _this8.columns[_this8.fieldsColumnsIndex[field]];
  1940. var value = Utils.getItemField(item, field, _this8.options.escape);
  1941. if ($td.find('.detail-icon').length) {
  1942. return;
  1943. }
  1944. _this8.trigger(type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  1945. _this8.trigger(type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
  1946. // if click to select - then trigger the checkbox/radio click
  1947. if (type === 'click' && _this8.options.clickToSelect && column.clickToSelect && !_this8.options.ignoreClickToSelectOn(target)) {
  1948. var $selectItem = $tr.find(Utils.sprintf('[name="%s"]', _this8.options.selectItemName));
  1949. if ($selectItem.length) {
  1950. $selectItem[0].click(); // #144: .trigger('click') bug
  1951. }
  1952. }
  1953. });
  1954. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) {
  1955. e.preventDefault();
  1956. var $this = $(e.currentTarget); // Fix #980 Detail view, when searching, returns wrong row
  1957. var $tr = $this.parent().parent();
  1958. var index = $tr.data('index');
  1959. var row = data[index];
  1960. // remove and update
  1961. if ($tr.next().is('tr.detail-view')) {
  1962. $this.find('i').attr('class', Utils.sprintf('%s %s', _this8.options.iconsPrefix, _this8.options.icons.detailOpen));
  1963. _this8.trigger('collapse-row', index, row, $tr.next());
  1964. $tr.next().remove();
  1965. } else {
  1966. $this.find('i').attr('class', Utils.sprintf('%s %s', _this8.options.iconsPrefix, _this8.options.icons.detailClose));
  1967. $tr.after(Utils.sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.find('td').length));
  1968. var $element = $tr.next().find('td');
  1969. var content = Utils.calculateObjectValue(_this8.options, _this8.options.detailFormatter, [index, row, $element], '');
  1970. if ($element.length === 1) {
  1971. $element.append(content);
  1972. }
  1973. _this8.trigger('expand-row', index, row, $element);
  1974. }
  1975. _this8.resetView();
  1976. return false;
  1977. });
  1978. this.$selectItem = this.$body.find(Utils.sprintf('[name="%s"]', this.options.selectItemName));
  1979. this.$selectItem.off('click').on('click', function (e) {
  1980. e.stopImmediatePropagation();
  1981. var $this = $(e.currentTarget);
  1982. _this8.check_($this.prop('checked'), $this.data('index'));
  1983. });
  1984. this.header.events.forEach(function (_events, i) {
  1985. var events = _events;
  1986. if (!events) {
  1987. return;
  1988. }
  1989. // fix bug, if events is defined with namespace
  1990. if (typeof events === 'string') {
  1991. events = Utils.calculateObjectValue(null, events);
  1992. }
  1993. var field = _this8.header.fields[i];
  1994. var fieldIndex = _this8.getVisibleFields().indexOf(field);
  1995. if (fieldIndex === -1) {
  1996. return;
  1997. }
  1998. if (_this8.options.detailView && !_this8.options.cardView) {
  1999. fieldIndex += 1;
  2000. }
  2001. var _loop = function _loop(key, event) {
  2002. _this8.$body.find('>tr:not(.no-records-found)').each(function (i, tr) {
  2003. var $tr = $(tr);
  2004. var $td = $tr.find(_this8.options.cardView ? '.card-view' : 'td').eq(fieldIndex);
  2005. var index = key.indexOf(' ');
  2006. var name = key.substring(0, index);
  2007. var el = key.substring(index + 1);
  2008. $td.find(el).off(name).on(name, function (e) {
  2009. var index = $tr.data('index');
  2010. var row = _this8.data[index];
  2011. var value = row[field];
  2012. event.apply(_this8, [e, value, row, index]);
  2013. });
  2014. });
  2015. };
  2016. var _iteratorNormalCompletion15 = true;
  2017. var _didIteratorError15 = false;
  2018. var _iteratorError15 = undefined;
  2019. try {
  2020. for (var _iterator15 = Object.entries(events)[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
  2021. var _ref21 = _step15.value;
  2022. var _ref22 = _slicedToArray(_ref21, 2);
  2023. var key = _ref22[0];
  2024. var event = _ref22[1];
  2025. _loop(key, event);
  2026. }
  2027. } catch (err) {
  2028. _didIteratorError15 = true;
  2029. _iteratorError15 = err;
  2030. } finally {
  2031. try {
  2032. if (!_iteratorNormalCompletion15 && _iterator15.return) {
  2033. _iterator15.return();
  2034. }
  2035. } finally {
  2036. if (_didIteratorError15) {
  2037. throw _iteratorError15;
  2038. }
  2039. }
  2040. }
  2041. });
  2042. this.updateSelected();
  2043. this.resetView();
  2044. this.trigger('post-body', data);
  2045. }
  2046. }, {
  2047. key: 'initServer',
  2048. value: function initServer(silent, query, url) {
  2049. var _this9 = this;
  2050. var data = {};
  2051. var index = this.header.fields.indexOf(this.options.sortName);
  2052. var params = {
  2053. searchText: this.searchText,
  2054. sortName: this.options.sortName,
  2055. sortOrder: this.options.sortOrder
  2056. };
  2057. if (this.header.sortNames[index]) {
  2058. params.sortName = this.header.sortNames[index];
  2059. }
  2060. if (this.options.pagination && this.options.sidePagination === 'server') {
  2061. params.pageSize = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize;
  2062. params.pageNumber = this.options.pageNumber;
  2063. }
  2064. if (!(url || this.options.url) && !this.options.ajax) {
  2065. return;
  2066. }
  2067. if (this.options.queryParamsType === 'limit') {
  2068. params = {
  2069. search: params.searchText,
  2070. sort: params.sortName,
  2071. order: params.sortOrder
  2072. };
  2073. if (this.options.pagination && this.options.sidePagination === 'server') {
  2074. params.offset = this.options.pageSize === this.options.formatAllRows() ? 0 : this.options.pageSize * (this.options.pageNumber - 1);
  2075. params.limit = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize;
  2076. if (params.limit === 0) {
  2077. delete params.limit;
  2078. }
  2079. }
  2080. }
  2081. if (!$.isEmptyObject(this.filterColumnsPartial)) {
  2082. params.filter = JSON.stringify(this.filterColumnsPartial, null);
  2083. }
  2084. data = Utils.calculateObjectValue(this.options, this.options.queryParams, [params], data);
  2085. $.extend(data, query || {});
  2086. // false to stop request
  2087. if (data === false) {
  2088. return;
  2089. }
  2090. if (!silent) {
  2091. this.$tableLoading.show();
  2092. }
  2093. var request = $.extend({}, Utils.calculateObjectValue(null, this.options.ajaxOptions), {
  2094. type: this.options.method,
  2095. url: url || this.options.url,
  2096. data: this.options.contentType === 'application/json' && this.options.method === 'post' ? JSON.stringify(data) : data,
  2097. cache: this.options.cache,
  2098. contentType: this.options.contentType,
  2099. dataType: this.options.dataType,
  2100. success: function success(_res) {
  2101. var res = Utils.calculateObjectValue(_this9.options, _this9.options.responseHandler, [_res], _res);
  2102. _this9.load(res);
  2103. _this9.trigger('load-success', res);
  2104. if (!silent) {
  2105. _this9.$tableLoading.hide();
  2106. }
  2107. },
  2108. error: function error(jqXHR) {
  2109. var data = [];
  2110. if (_this9.options.sidePagination === 'server') {
  2111. data = {};
  2112. data[_this9.options.totalField] = 0;
  2113. data[_this9.options.dataField] = [];
  2114. }
  2115. _this9.load(data);
  2116. _this9.trigger('load-error', jqXHR.status, jqXHR);
  2117. if (!silent) _this9.$tableLoading.hide();
  2118. }
  2119. });
  2120. if (this.options.ajax) {
  2121. Utils.calculateObjectValue(this, this.options.ajax, [request], null);
  2122. } else {
  2123. if (this._xhr && this._xhr.readyState !== 4) {
  2124. this._xhr.abort();
  2125. }
  2126. this._xhr = $.ajax(request);
  2127. }
  2128. }
  2129. }, {
  2130. key: 'initSearchText',
  2131. value: function initSearchText() {
  2132. if (this.options.search) {
  2133. this.searchText = '';
  2134. if (this.options.searchText !== '') {
  2135. var $search = this.$toolbar.find('.search input');
  2136. $search.val(this.options.searchText);
  2137. this.onSearch({ currentTarget: $search, firedByInitSearchText: true });
  2138. }
  2139. }
  2140. }
  2141. }, {
  2142. key: 'getCaret',
  2143. value: function getCaret() {
  2144. var _this10 = this;
  2145. this.$header.find('th').each(function (i, th) {
  2146. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === _this10.options.sortName ? _this10.options.sortOrder : 'both');
  2147. });
  2148. }
  2149. }, {
  2150. key: 'updateSelected',
  2151. value: function updateSelected() {
  2152. var checkAll = this.$selectItem.filter(':enabled').length && this.$selectItem.filter(':enabled').length === this.$selectItem.filter(':enabled').filter(':checked').length;
  2153. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  2154. this.$selectItem.each(function (i, el) {
  2155. $(el).closest('tr')[$(el).prop('checked') ? 'addClass' : 'removeClass']('selected');
  2156. });
  2157. }
  2158. }, {
  2159. key: 'updateRows',
  2160. value: function updateRows() {
  2161. var _this11 = this;
  2162. this.$selectItem.each(function (i, el) {
  2163. _this11.data[$(el).data('index')][_this11.header.stateField] = $(el).prop('checked');
  2164. });
  2165. }
  2166. }, {
  2167. key: 'resetRows',
  2168. value: function resetRows() {
  2169. var _iteratorNormalCompletion16 = true;
  2170. var _didIteratorError16 = false;
  2171. var _iteratorError16 = undefined;
  2172. try {
  2173. for (var _iterator16 = this.data[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
  2174. var row = _step16.value;
  2175. this.$selectAll.prop('checked', false);
  2176. this.$selectItem.prop('checked', false);
  2177. if (this.header.stateField) {
  2178. row[this.header.stateField] = false;
  2179. }
  2180. }
  2181. } catch (err) {
  2182. _didIteratorError16 = true;
  2183. _iteratorError16 = err;
  2184. } finally {
  2185. try {
  2186. if (!_iteratorNormalCompletion16 && _iterator16.return) {
  2187. _iterator16.return();
  2188. }
  2189. } finally {
  2190. if (_didIteratorError16) {
  2191. throw _iteratorError16;
  2192. }
  2193. }
  2194. }
  2195. this.initHiddenRows();
  2196. }
  2197. }, {
  2198. key: 'trigger',
  2199. value: function trigger(_name) {
  2200. var _options;
  2201. var name = _name + '.bs.table';
  2202. for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key4 = 1; _key4 < _len2; _key4++) {
  2203. args[_key4 - 1] = arguments[_key4];
  2204. }
  2205. (_options = this.options)[BootstrapTable.EVENTS[name]].apply(_options, args);
  2206. this.$el.trigger($.Event(name), args);
  2207. this.options.onAll(name, args);
  2208. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  2209. }
  2210. }, {
  2211. key: 'resetHeader',
  2212. value: function resetHeader() {
  2213. // fix #61: the hidden table reset header bug.
  2214. // fix bug: get $el.css('width') error sometime (height = 500)
  2215. clearTimeout(this.timeoutId_);
  2216. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  2217. }
  2218. }, {
  2219. key: 'fitHeader',
  2220. value: function fitHeader() {
  2221. var _this12 = this;
  2222. if (this.$el.is(':hidden')) {
  2223. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), 100);
  2224. return;
  2225. }
  2226. var fixedBody = this.$tableBody.get(0);
  2227. var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0;
  2228. this.$el.css('margin-top', -this.$header.outerHeight());
  2229. var focused = $(':focus');
  2230. if (focused.length > 0) {
  2231. var $th = focused.parents('th');
  2232. if ($th.length > 0) {
  2233. var dataField = $th.attr('data-field');
  2234. if (dataField !== undefined) {
  2235. var $headerTh = this.$header.find('[data-field=\'' + dataField + '\']');
  2236. if ($headerTh.length > 0) {
  2237. $headerTh.find(':input').addClass('focus-temp');
  2238. }
  2239. }
  2240. }
  2241. }
  2242. this.$header_ = this.$header.clone(true, true);
  2243. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  2244. this.$tableHeader.css({
  2245. 'margin-right': scrollWidth
  2246. }).find('table').css('width', this.$el.outerWidth()).html('').attr('class', this.$el.attr('class')).append(this.$header_);
  2247. var focusedTemp = $('.focus-temp:visible:eq(0)');
  2248. if (focusedTemp.length > 0) {
  2249. focusedTemp.focus();
  2250. this.$header.find('.focus-temp').removeClass('focus-temp');
  2251. }
  2252. // fix bug: $.data() is not working as expected after $.append()
  2253. this.$header.find('th[data-field]').each(function (i, el) {
  2254. _this12.$header_.find(Utils.sprintf('th[data-field="%s"]', $(el).data('field'))).data($(el).data());
  2255. });
  2256. var visibleFields = this.getVisibleFields();
  2257. var $ths = this.$header_.find('th');
  2258. var $tr = this.$body.find('>tr:first-child:not(.no-records-found)');
  2259. while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) {
  2260. $tr = $tr.next();
  2261. }
  2262. $tr.find('> *').each(function (i, el) {
  2263. var $this = $(el);
  2264. var index = i;
  2265. if (_this12.options.detailView && !_this12.options.cardView) {
  2266. if (i === 0) {
  2267. var $thDetail = $ths.filter('.detail');
  2268. var _zoomWidth = $thDetail.width() - $thDetail.find('.fht-cell').width();
  2269. $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth);
  2270. }
  2271. index = i - 1;
  2272. }
  2273. if (index === -1) {
  2274. return;
  2275. }
  2276. var $th = _this12.$header_.find(Utils.sprintf('th[data-field="%s"]', visibleFields[index]));
  2277. if ($th.length > 1) {
  2278. $th = $($ths[$this[0].cellIndex]);
  2279. }
  2280. var zoomWidth = $th.width() - $th.find('.fht-cell').width();
  2281. $th.find('.fht-cell').width($this.innerWidth() - zoomWidth);
  2282. });
  2283. this.horizontalScroll();
  2284. this.trigger('post-header');
  2285. }
  2286. }, {
  2287. key: 'resetFooter',
  2288. value: function resetFooter() {
  2289. var data = this.getData();
  2290. var html = [];
  2291. if (!this.options.showFooter || this.options.cardView) {
  2292. // do nothing
  2293. return;
  2294. }
  2295. if (!this.options.cardView && this.options.detailView) {
  2296. html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
  2297. }
  2298. var _iteratorNormalCompletion17 = true;
  2299. var _didIteratorError17 = false;
  2300. var _iteratorError17 = undefined;
  2301. try {
  2302. for (var _iterator17 = this.columns[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
  2303. var column = _step17.value;
  2304. var falign = '';
  2305. var valign = '';
  2306. var csses = [];
  2307. var style = {};
  2308. var class_ = Utils.sprintf(' class="%s"', column['class']);
  2309. if (!column.visible) {
  2310. return;
  2311. }
  2312. if (this.options.cardView && !column.cardVisible) {
  2313. return;
  2314. }
  2315. falign = Utils.sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  2316. valign = Utils.sprintf('vertical-align: %s; ', column.valign);
  2317. style = Utils.calculateObjectValue(null, this.options.footerStyle);
  2318. if (style && style.css) {
  2319. var _iteratorNormalCompletion18 = true;
  2320. var _didIteratorError18 = false;
  2321. var _iteratorError18 = undefined;
  2322. try {
  2323. for (var _iterator18 = Object.keys(style.css)[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {
  2324. var _ref23 = _step18.value;
  2325. var _ref24 = _slicedToArray(_ref23, 2);
  2326. var key = _ref24[0];
  2327. var value = _ref24[1];
  2328. csses.push(key + ': ' + value);
  2329. }
  2330. } catch (err) {
  2331. _didIteratorError18 = true;
  2332. _iteratorError18 = err;
  2333. } finally {
  2334. try {
  2335. if (!_iteratorNormalCompletion18 && _iterator18.return) {
  2336. _iterator18.return();
  2337. }
  2338. } finally {
  2339. if (_didIteratorError18) {
  2340. throw _iteratorError18;
  2341. }
  2342. }
  2343. }
  2344. }
  2345. html.push('<td', class_, Utils.sprintf(' style="%s"', falign + valign + csses.concat().join('; ')), '>');
  2346. html.push('<div class="th-inner">');
  2347. html.push(Utils.calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  2348. html.push('</div>');
  2349. html.push('<div class="fht-cell"></div>');
  2350. html.push('</div>');
  2351. html.push('</td>');
  2352. }
  2353. } catch (err) {
  2354. _didIteratorError17 = true;
  2355. _iteratorError17 = err;
  2356. } finally {
  2357. try {
  2358. if (!_iteratorNormalCompletion17 && _iterator17.return) {
  2359. _iterator17.return();
  2360. }
  2361. } finally {
  2362. if (_didIteratorError17) {
  2363. throw _iteratorError17;
  2364. }
  2365. }
  2366. }
  2367. this.$tableFooter.find('tr').html(html.join(''));
  2368. this.$tableFooter.show();
  2369. clearTimeout(this.timeoutFooter_);
  2370. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), this.$el.is(':hidden') ? 100 : 0);
  2371. }
  2372. }, {
  2373. key: 'fitFooter',
  2374. value: function fitFooter() {
  2375. clearTimeout(this.timeoutFooter_);
  2376. if (this.$el.is(':hidden')) {
  2377. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  2378. return;
  2379. }
  2380. var elWidth = this.$el.css('width');
  2381. var scrollWidth = elWidth > this.$tableBody.width() ? Utils.getScrollBarWidth() : 0;
  2382. this.$tableFooter.css({
  2383. 'margin-right': scrollWidth
  2384. }).find('table').css('width', elWidth).attr('class', this.$el.attr('class'));
  2385. var $footerTd = this.$tableFooter.find('td');
  2386. this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i, el) {
  2387. var $this = $(el);
  2388. $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
  2389. });
  2390. this.horizontalScroll();
  2391. }
  2392. }, {
  2393. key: 'horizontalScroll',
  2394. value: function horizontalScroll() {
  2395. var _this13 = this;
  2396. // horizontal scroll event
  2397. // TODO: it's probably better improving the layout than binding to scroll event
  2398. this.trigger('scroll-body');
  2399. this.$tableBody.off('scroll').on('scroll', function (_ref25) {
  2400. var currentTarget = _ref25.currentTarget;
  2401. if (_this13.options.showHeader && _this13.options.height) {
  2402. _this13.$tableHeader.scrollLeft($(currentTarget).scrollLeft());
  2403. }
  2404. if (_this13.options.showFooter && !_this13.options.cardView) {
  2405. _this13.$tableFooter.scrollLeft($(currentTarget).scrollLeft());
  2406. }
  2407. });
  2408. }
  2409. }, {
  2410. key: 'toggleColumn',
  2411. value: function toggleColumn(index, checked, needUpdate) {
  2412. if (index === -1) {
  2413. return;
  2414. }
  2415. this.columns[index].visible = checked;
  2416. this.initHeader();
  2417. this.initSearch();
  2418. this.initPagination();
  2419. this.initBody();
  2420. if (this.options.showColumns) {
  2421. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  2422. if (needUpdate) {
  2423. $items.filter(Utils.sprintf('[value="%s"]', index)).prop('checked', checked);
  2424. }
  2425. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  2426. $items.filter(':checked').prop('disabled', true);
  2427. }
  2428. }
  2429. }
  2430. }, {
  2431. key: 'getVisibleFields',
  2432. value: function getVisibleFields() {
  2433. var visibleFields = [];
  2434. var _iteratorNormalCompletion19 = true;
  2435. var _didIteratorError19 = false;
  2436. var _iteratorError19 = undefined;
  2437. try {
  2438. for (var _iterator19 = this.header.fields[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {
  2439. var field = _step19.value;
  2440. var column = this.columns[this.fieldsColumnsIndex[field]];
  2441. if (!column.visible) {
  2442. continue;
  2443. }
  2444. visibleFields.push(field);
  2445. }
  2446. } catch (err) {
  2447. _didIteratorError19 = true;
  2448. _iteratorError19 = err;
  2449. } finally {
  2450. try {
  2451. if (!_iteratorNormalCompletion19 && _iterator19.return) {
  2452. _iterator19.return();
  2453. }
  2454. } finally {
  2455. if (_didIteratorError19) {
  2456. throw _iteratorError19;
  2457. }
  2458. }
  2459. }
  2460. return visibleFields;
  2461. }
  2462. }, {
  2463. key: 'resetView',
  2464. value: function resetView(params) {
  2465. var padding = 0;
  2466. if (params && params.height) {
  2467. this.options.height = params.height;
  2468. }
  2469. this.$selectAll.prop('checked', this.$selectItem.length > 0 && this.$selectItem.length === this.$selectItem.filter(':checked').length);
  2470. if (this.options.cardView) {
  2471. // remove the element css
  2472. this.$el.css('margin-top', '0');
  2473. this.$tableContainer.css('padding-bottom', '0');
  2474. this.$tableFooter.hide();
  2475. return;
  2476. }
  2477. if (this.options.showHeader && this.options.height) {
  2478. this.$tableHeader.show();
  2479. this.resetHeader();
  2480. padding += this.$header.outerHeight();
  2481. } else {
  2482. this.$tableHeader.hide();
  2483. this.trigger('post-header');
  2484. }
  2485. if (this.options.showFooter) {
  2486. this.resetFooter();
  2487. if (this.options.height) {
  2488. padding += this.$tableFooter.outerHeight() + 1;
  2489. }
  2490. }
  2491. if (this.options.height) {
  2492. var toolbarHeight = this.$toolbar.outerHeight(true);
  2493. var paginationHeight = this.$pagination.outerHeight(true);
  2494. var height = this.options.height - toolbarHeight - paginationHeight;
  2495. var tableHeight = this.$tableBody.find('table').outerHeight(true);
  2496. this.$tableContainer.css('height', height + 'px');
  2497. this.$tableBorder && this.$tableBorder.css('height', height - tableHeight - padding - 1 + 'px');
  2498. }
  2499. // Assign the correct sortable arrow
  2500. this.getCaret();
  2501. this.$tableContainer.css('padding-bottom', padding + 'px');
  2502. this.trigger('reset-view');
  2503. }
  2504. }, {
  2505. key: 'getData',
  2506. value: function getData(useCurrentPage) {
  2507. var data = this.options.data;
  2508. if (this.searchText || this.options.sortName || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) {
  2509. data = this.data;
  2510. }
  2511. if (useCurrentPage) {
  2512. return data.slice(this.pageFrom - 1, this.pageTo);
  2513. }
  2514. return data;
  2515. }
  2516. }, {
  2517. key: 'load',
  2518. value: function load(_data) {
  2519. var fixedScroll = false;
  2520. var data = _data;
  2521. // #431: support pagination
  2522. if (this.options.pagination && this.options.sidePagination === 'server') {
  2523. this.options.totalRows = data[this.options.totalField];
  2524. }
  2525. fixedScroll = data.fixedScroll;
  2526. data = Array.isArray(data) ? data : data[this.options.dataField];
  2527. this.initData(data);
  2528. this.initSearch();
  2529. this.initPagination();
  2530. this.initBody(fixedScroll);
  2531. }
  2532. }, {
  2533. key: 'append',
  2534. value: function append(data) {
  2535. this.initData(data, 'append');
  2536. this.initSearch();
  2537. this.initPagination();
  2538. this.initSort();
  2539. this.initBody(true);
  2540. }
  2541. }, {
  2542. key: 'prepend',
  2543. value: function prepend(data) {
  2544. this.initData(data, 'prepend');
  2545. this.initSearch();
  2546. this.initPagination();
  2547. this.initSort();
  2548. this.initBody(true);
  2549. }
  2550. }, {
  2551. key: 'remove',
  2552. value: function remove(params) {
  2553. var len = this.options.data.length;
  2554. var i = void 0;
  2555. var row = void 0;
  2556. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  2557. return;
  2558. }
  2559. for (i = len - 1; i >= 0; i--) {
  2560. row = this.options.data[i];
  2561. if (!row.hasOwnProperty(params.field)) {
  2562. continue;
  2563. }
  2564. if (params.values.includes(row[params.field])) {
  2565. this.options.data.splice(i, 1);
  2566. if (this.options.sidePagination === 'server') {
  2567. this.options.totalRows -= 1;
  2568. }
  2569. }
  2570. }
  2571. if (len === this.options.data.length) {
  2572. return;
  2573. }
  2574. this.initSearch();
  2575. this.initPagination();
  2576. this.initSort();
  2577. this.initBody(true);
  2578. }
  2579. }, {
  2580. key: 'removeAll',
  2581. value: function removeAll() {
  2582. if (this.options.data.length > 0) {
  2583. this.options.data.splice(0, this.options.data.length);
  2584. this.initSearch();
  2585. this.initPagination();
  2586. this.initBody(true);
  2587. }
  2588. }
  2589. }, {
  2590. key: 'getRowByUniqueId',
  2591. value: function getRowByUniqueId(_id) {
  2592. var uniqueId = this.options.uniqueId;
  2593. var len = this.options.data.length;
  2594. var id = _id;
  2595. var dataRow = null;
  2596. var i = void 0;
  2597. var row = void 0;
  2598. var rowUniqueId = void 0;
  2599. for (i = len - 1; i >= 0; i--) {
  2600. row = this.options.data[i];
  2601. if (row.hasOwnProperty(uniqueId)) {
  2602. // uniqueId is a column
  2603. rowUniqueId = row[uniqueId];
  2604. } else if (row._data && row._data.hasOwnProperty(uniqueId)) {
  2605. // uniqueId is a row data property
  2606. rowUniqueId = row._data[uniqueId];
  2607. } else {
  2608. continue;
  2609. }
  2610. if (typeof rowUniqueId === 'string') {
  2611. id = id.toString();
  2612. } else if (typeof rowUniqueId === 'number') {
  2613. if (Number(rowUniqueId) === rowUniqueId && rowUniqueId % 1 === 0) {
  2614. id = parseInt(id);
  2615. } else if (rowUniqueId === Number(rowUniqueId) && rowUniqueId !== 0) {
  2616. id = parseFloat(id);
  2617. }
  2618. }
  2619. if (rowUniqueId === id) {
  2620. dataRow = row;
  2621. break;
  2622. }
  2623. }
  2624. return dataRow;
  2625. }
  2626. }, {
  2627. key: 'removeByUniqueId',
  2628. value: function removeByUniqueId(id) {
  2629. var len = this.options.data.length;
  2630. var row = this.getRowByUniqueId(id);
  2631. if (row) {
  2632. this.options.data.splice(this.options.data.indexOf(row), 1);
  2633. }
  2634. if (len === this.options.data.length) {
  2635. return;
  2636. }
  2637. this.initSearch();
  2638. this.initPagination();
  2639. this.initBody(true);
  2640. }
  2641. }, {
  2642. key: 'updateByUniqueId',
  2643. value: function updateByUniqueId(params) {
  2644. var allParams = Array.isArray(params) ? params : [params];
  2645. var _iteratorNormalCompletion20 = true;
  2646. var _didIteratorError20 = false;
  2647. var _iteratorError20 = undefined;
  2648. try {
  2649. for (var _iterator20 = allParams[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {
  2650. var _params = _step20.value;
  2651. if (!_params.hasOwnProperty('id') || !_params.hasOwnProperty('row')) {
  2652. continue;
  2653. }
  2654. var rowId = this.options.data.indexOf(this.getRowByUniqueId(_params.id));
  2655. if (rowId === -1) {
  2656. continue;
  2657. }
  2658. $.extend(this.options.data[rowId], _params.row);
  2659. }
  2660. } catch (err) {
  2661. _didIteratorError20 = true;
  2662. _iteratorError20 = err;
  2663. } finally {
  2664. try {
  2665. if (!_iteratorNormalCompletion20 && _iterator20.return) {
  2666. _iterator20.return();
  2667. }
  2668. } finally {
  2669. if (_didIteratorError20) {
  2670. throw _iteratorError20;
  2671. }
  2672. }
  2673. }
  2674. this.initSearch();
  2675. this.initPagination();
  2676. this.initSort();
  2677. this.initBody(true);
  2678. }
  2679. }, {
  2680. key: 'refreshColumnTitle',
  2681. value: function refreshColumnTitle(params) {
  2682. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) {
  2683. return;
  2684. }
  2685. this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape ? Utils.escapeHTML(params.title) : params.title;
  2686. if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
  2687. var header = this.options.height !== undefined ? this.$tableHeader : this.$header;
  2688. header.find('th[data-field]').each(function (i, el) {
  2689. if ($(el).data('field') === params.field) {
  2690. $($(el).find('.th-inner')[0]).text(params.title);
  2691. return false;
  2692. }
  2693. });
  2694. }
  2695. }
  2696. }, {
  2697. key: 'insertRow',
  2698. value: function insertRow(params) {
  2699. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  2700. return;
  2701. }
  2702. this.options.data.splice(params.index, 0, params.row);
  2703. this.initSearch();
  2704. this.initPagination();
  2705. this.initSort();
  2706. this.initBody(true);
  2707. }
  2708. }, {
  2709. key: 'updateRow',
  2710. value: function updateRow(params) {
  2711. var allParams = Array.isArray(params) ? params : [params];
  2712. var _iteratorNormalCompletion21 = true;
  2713. var _didIteratorError21 = false;
  2714. var _iteratorError21 = undefined;
  2715. try {
  2716. for (var _iterator21 = allParams[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {
  2717. var _params2 = _step21.value;
  2718. if (!_params2.hasOwnProperty('index') || !_params2.hasOwnProperty('row')) {
  2719. continue;
  2720. }
  2721. $.extend(this.options.data[_params2.index], _params2.row);
  2722. }
  2723. } catch (err) {
  2724. _didIteratorError21 = true;
  2725. _iteratorError21 = err;
  2726. } finally {
  2727. try {
  2728. if (!_iteratorNormalCompletion21 && _iterator21.return) {
  2729. _iterator21.return();
  2730. }
  2731. } finally {
  2732. if (_didIteratorError21) {
  2733. throw _iteratorError21;
  2734. }
  2735. }
  2736. }
  2737. this.initSearch();
  2738. this.initPagination();
  2739. this.initSort();
  2740. this.initBody(true);
  2741. }
  2742. }, {
  2743. key: 'initHiddenRows',
  2744. value: function initHiddenRows() {
  2745. this.hiddenRows = [];
  2746. }
  2747. }, {
  2748. key: 'showRow',
  2749. value: function showRow(params) {
  2750. this.toggleRow(params, true);
  2751. }
  2752. }, {
  2753. key: 'hideRow',
  2754. value: function hideRow(params) {
  2755. this.toggleRow(params, false);
  2756. }
  2757. }, {
  2758. key: 'toggleRow',
  2759. value: function toggleRow(params, visible) {
  2760. var row = void 0;
  2761. if (params.hasOwnProperty('index')) {
  2762. row = this.getData()[params.index];
  2763. } else if (params.hasOwnProperty('uniqueId')) {
  2764. row = this.getRowByUniqueId(params.uniqueId);
  2765. }
  2766. if (!row) {
  2767. return;
  2768. }
  2769. var index = Utils.findIndex(this.hiddenRows, row);
  2770. if (!visible && index === -1) {
  2771. this.hiddenRows.push(row);
  2772. } else if (visible && index > -1) {
  2773. this.hiddenRows.splice(index, 1);
  2774. }
  2775. this.initBody(true);
  2776. }
  2777. }, {
  2778. key: 'getHiddenRows',
  2779. value: function getHiddenRows(show) {
  2780. if (show) {
  2781. this.initHiddenRows();
  2782. this.initBody(true);
  2783. return;
  2784. }
  2785. var data = this.getData();
  2786. var rows = [];
  2787. var _iteratorNormalCompletion22 = true;
  2788. var _didIteratorError22 = false;
  2789. var _iteratorError22 = undefined;
  2790. try {
  2791. for (var _iterator22 = data[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {
  2792. var row = _step22.value;
  2793. if (this.hiddenRows.includes(row)) {
  2794. rows.push(row);
  2795. }
  2796. }
  2797. } catch (err) {
  2798. _didIteratorError22 = true;
  2799. _iteratorError22 = err;
  2800. } finally {
  2801. try {
  2802. if (!_iteratorNormalCompletion22 && _iterator22.return) {
  2803. _iterator22.return();
  2804. }
  2805. } finally {
  2806. if (_didIteratorError22) {
  2807. throw _iteratorError22;
  2808. }
  2809. }
  2810. }
  2811. this.hiddenRows = rows;
  2812. return rows;
  2813. }
  2814. }, {
  2815. key: 'mergeCells',
  2816. value: function mergeCells(options) {
  2817. var row = options.index;
  2818. var col = this.getVisibleFields().indexOf(options.field);
  2819. var rowspan = options.rowspan || 1;
  2820. var colspan = options.colspan || 1;
  2821. var i = void 0;
  2822. var j = void 0;
  2823. var $tr = this.$body.find('>tr');
  2824. if (this.options.detailView && !this.options.cardView) {
  2825. col += 1;
  2826. }
  2827. var $td = $tr.eq(row).find('>td').eq(col);
  2828. if (row < 0 || col < 0 || row >= this.data.length) {
  2829. return;
  2830. }
  2831. for (i = row; i < row + rowspan; i++) {
  2832. for (j = col; j < col + colspan; j++) {
  2833. $tr.eq(i).find('>td').eq(j).hide();
  2834. }
  2835. }
  2836. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  2837. }
  2838. }, {
  2839. key: 'updateCell',
  2840. value: function updateCell(params) {
  2841. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) {
  2842. return;
  2843. }
  2844. this.data[params.index][params.field] = params.value;
  2845. if (params.reinit === false) {
  2846. return;
  2847. }
  2848. this.initSort();
  2849. this.initBody(true);
  2850. }
  2851. }, {
  2852. key: 'updateCellById',
  2853. value: function updateCellById(params) {
  2854. var _this14 = this;
  2855. if (!params.hasOwnProperty('id') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) {
  2856. return;
  2857. }
  2858. var allParams = Array.isArray(params) ? params : [params];
  2859. allParams.forEach(function (_ref26) {
  2860. var id = _ref26.id,
  2861. field = _ref26.field,
  2862. value = _ref26.value;
  2863. var rowId = _this14.options.data.indexOf(_this14.getRowByUniqueId(id));
  2864. if (rowId === -1) {
  2865. return;
  2866. }
  2867. _this14.data[rowId][field] = value;
  2868. });
  2869. if (params.reinit === false) {
  2870. return;
  2871. }
  2872. this.initSort();
  2873. this.initBody(true);
  2874. }
  2875. }, {
  2876. key: 'getOptions',
  2877. value: function getOptions() {
  2878. // Deep copy: remove data
  2879. var options = $.extend({}, this.options);
  2880. delete options.data;
  2881. return $.extend(true, {}, options);
  2882. }
  2883. }, {
  2884. key: 'getSelections',
  2885. value: function getSelections() {
  2886. var _this15 = this;
  2887. // fix #2424: from html with checkbox
  2888. return this.options.data.filter(function (row) {
  2889. return row[_this15.header.stateField] === true;
  2890. });
  2891. }
  2892. }, {
  2893. key: 'getAllSelections',
  2894. value: function getAllSelections() {
  2895. var _this16 = this;
  2896. return this.options.data.filter(function (row) {
  2897. return row[_this16.header.stateField];
  2898. });
  2899. }
  2900. }, {
  2901. key: 'checkAll',
  2902. value: function checkAll() {
  2903. this.checkAll_(true);
  2904. }
  2905. }, {
  2906. key: 'uncheckAll',
  2907. value: function uncheckAll() {
  2908. this.checkAll_(false);
  2909. }
  2910. }, {
  2911. key: 'checkInvert',
  2912. value: function checkInvert() {
  2913. var $items = this.$selectItem.filter(':enabled');
  2914. var checked = $items.filter(':checked');
  2915. $items.each(function (i, el) {
  2916. $(el).prop('checked', !$(el).prop('checked'));
  2917. });
  2918. this.updateRows();
  2919. this.updateSelected();
  2920. this.trigger('uncheck-some', checked);
  2921. checked = this.getSelections();
  2922. this.trigger('check-some', checked);
  2923. }
  2924. }, {
  2925. key: 'checkAll_',
  2926. value: function checkAll_(checked) {
  2927. var rows = void 0;
  2928. if (!checked) {
  2929. rows = this.getSelections();
  2930. }
  2931. this.$selectAll.add(this.$selectAll_).prop('checked', checked);
  2932. this.$selectItem.filter(':enabled').prop('checked', checked);
  2933. this.updateRows();
  2934. if (checked) {
  2935. rows = this.getSelections();
  2936. }
  2937. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  2938. }
  2939. }, {
  2940. key: 'check',
  2941. value: function check(index) {
  2942. this.check_(true, index);
  2943. }
  2944. }, {
  2945. key: 'uncheck',
  2946. value: function uncheck(index) {
  2947. this.check_(false, index);
  2948. }
  2949. }, {
  2950. key: 'check_',
  2951. value: function check_(checked, index) {
  2952. var $el = this.$selectItem.filter('[data-index="' + index + '"]');
  2953. var row = this.data[index];
  2954. if ($el.is(':radio') || this.options.singleSelect) {
  2955. var _iteratorNormalCompletion23 = true;
  2956. var _didIteratorError23 = false;
  2957. var _iteratorError23 = undefined;
  2958. try {
  2959. for (var _iterator23 = this.options.data[Symbol.iterator](), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) {
  2960. var r = _step23.value;
  2961. r[this.header.stateField] = false;
  2962. }
  2963. } catch (err) {
  2964. _didIteratorError23 = true;
  2965. _iteratorError23 = err;
  2966. } finally {
  2967. try {
  2968. if (!_iteratorNormalCompletion23 && _iterator23.return) {
  2969. _iterator23.return();
  2970. }
  2971. } finally {
  2972. if (_didIteratorError23) {
  2973. throw _iteratorError23;
  2974. }
  2975. }
  2976. }
  2977. this.$selectItem.filter(':checked').not($el).prop('checked', false);
  2978. }
  2979. row[this.header.stateField] = checked;
  2980. $el.prop('checked', checked);
  2981. this.updateSelected();
  2982. this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
  2983. }
  2984. }, {
  2985. key: 'checkBy',
  2986. value: function checkBy(obj) {
  2987. this.checkBy_(true, obj);
  2988. }
  2989. }, {
  2990. key: 'uncheckBy',
  2991. value: function uncheckBy(obj) {
  2992. this.checkBy_(false, obj);
  2993. }
  2994. }, {
  2995. key: 'checkBy_',
  2996. value: function checkBy_(checked, obj) {
  2997. var _this17 = this;
  2998. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  2999. return;
  3000. }
  3001. var rows = [];
  3002. this.options.data.forEach(function (row, i) {
  3003. if (!row.hasOwnProperty(obj.field)) {
  3004. return false;
  3005. }
  3006. if (obj.values.includes(row[obj.field])) {
  3007. var $el = _this17.$selectItem.filter(':enabled').filter(Utils.sprintf('[data-index="%s"]', i)).prop('checked', checked);
  3008. row[_this17.header.stateField] = checked;
  3009. rows.push(row);
  3010. _this17.trigger(checked ? 'check' : 'uncheck', row, $el);
  3011. }
  3012. });
  3013. this.updateSelected();
  3014. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  3015. }
  3016. }, {
  3017. key: 'destroy',
  3018. value: function destroy() {
  3019. this.$el.insertBefore(this.$container);
  3020. $(this.options.toolbar).insertBefore(this.$el);
  3021. this.$container.next().remove();
  3022. this.$container.remove();
  3023. this.$el.html(this.$el_.html()).css('margin-top', '0').attr('class', this.$el_.attr('class') || ''); // reset the class
  3024. }
  3025. }, {
  3026. key: 'showLoading',
  3027. value: function showLoading() {
  3028. this.$tableLoading.show();
  3029. }
  3030. }, {
  3031. key: 'hideLoading',
  3032. value: function hideLoading() {
  3033. this.$tableLoading.hide();
  3034. }
  3035. }, {
  3036. key: 'togglePagination',
  3037. value: function togglePagination() {
  3038. this.options.pagination = !this.options.pagination;
  3039. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  3040. if (this.options.pagination) {
  3041. button.attr('class', this.options.iconsPrefix + ' ' + this.options.icons.paginationSwitchDown);
  3042. } else {
  3043. button.attr('class', this.options.iconsPrefix + ' ' + this.options.icons.paginationSwitchUp);
  3044. }
  3045. this.updatePagination();
  3046. }
  3047. }, {
  3048. key: 'toggleFullscreen',
  3049. value: function toggleFullscreen() {
  3050. this.$el.closest('.bootstrap-table').toggleClass('fullscreen');
  3051. }
  3052. }, {
  3053. key: 'refresh',
  3054. value: function refresh(params) {
  3055. if (params && params.url) {
  3056. this.options.url = params.url;
  3057. }
  3058. if (params && params.pageNumber) {
  3059. this.options.pageNumber = params.pageNumber;
  3060. }
  3061. if (params && params.pageSize) {
  3062. this.options.pageSize = params.pageSize;
  3063. }
  3064. this.initServer(params && params.silent, params && params.query, params && params.url);
  3065. this.trigger('refresh', params);
  3066. }
  3067. }, {
  3068. key: 'resetWidth',
  3069. value: function resetWidth() {
  3070. if (this.options.showHeader && this.options.height) {
  3071. this.fitHeader();
  3072. }
  3073. if (this.options.showFooter && !this.options.cardView) {
  3074. this.fitFooter();
  3075. }
  3076. }
  3077. }, {
  3078. key: 'showColumn',
  3079. value: function showColumn(field) {
  3080. this.toggleColumn(this.fieldsColumnsIndex[field], true, true);
  3081. }
  3082. }, {
  3083. key: 'hideColumn',
  3084. value: function hideColumn(field) {
  3085. this.toggleColumn(this.fieldsColumnsIndex[field], false, true);
  3086. }
  3087. }, {
  3088. key: 'getHiddenColumns',
  3089. value: function getHiddenColumns() {
  3090. return this.columns.filter(function (_ref27) {
  3091. var visible = _ref27.visible;
  3092. return !visible;
  3093. });
  3094. }
  3095. }, {
  3096. key: 'getVisibleColumns',
  3097. value: function getVisibleColumns() {
  3098. return this.columns.filter(function (_ref28) {
  3099. var visible = _ref28.visible;
  3100. return visible;
  3101. });
  3102. }
  3103. }, {
  3104. key: 'toggleAllColumns',
  3105. value: function toggleAllColumns(visible) {
  3106. var _iteratorNormalCompletion24 = true;
  3107. var _didIteratorError24 = false;
  3108. var _iteratorError24 = undefined;
  3109. try {
  3110. for (var _iterator24 = this.columns[Symbol.iterator](), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) {
  3111. var column = _step24.value;
  3112. column.visible = visible;
  3113. }
  3114. } catch (err) {
  3115. _didIteratorError24 = true;
  3116. _iteratorError24 = err;
  3117. } finally {
  3118. try {
  3119. if (!_iteratorNormalCompletion24 && _iterator24.return) {
  3120. _iterator24.return();
  3121. }
  3122. } finally {
  3123. if (_didIteratorError24) {
  3124. throw _iteratorError24;
  3125. }
  3126. }
  3127. }
  3128. this.initHeader();
  3129. this.initSearch();
  3130. this.initPagination();
  3131. this.initBody();
  3132. if (this.options.showColumns) {
  3133. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  3134. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  3135. $items.filter(':checked').prop('disabled', true);
  3136. }
  3137. }
  3138. }
  3139. }, {
  3140. key: 'showAllColumns',
  3141. value: function showAllColumns() {
  3142. this.toggleAllColumns(true);
  3143. }
  3144. }, {
  3145. key: 'hideAllColumns',
  3146. value: function hideAllColumns() {
  3147. this.toggleAllColumns(false);
  3148. }
  3149. }, {
  3150. key: 'filterBy',
  3151. value: function filterBy(columns) {
  3152. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  3153. this.options.pageNumber = 1;
  3154. this.initSearch();
  3155. this.updatePagination();
  3156. }
  3157. }, {
  3158. key: 'scrollTo',
  3159. value: function scrollTo(_value) {
  3160. if (typeof _value === 'undefined') {
  3161. return this.$tableBody.scrollTop();
  3162. }
  3163. var value = _value;
  3164. if (typeof _value === 'string' && _value === 'bottom') {
  3165. value = this.$tableBody[0].scrollHeight;
  3166. }
  3167. this.$tableBody.scrollTop(value);
  3168. }
  3169. }, {
  3170. key: 'getScrollPosition',
  3171. value: function getScrollPosition() {
  3172. return this.scrollTo();
  3173. }
  3174. }, {
  3175. key: 'selectPage',
  3176. value: function selectPage(page) {
  3177. if (page > 0 && page <= this.options.totalPages) {
  3178. this.options.pageNumber = page;
  3179. this.updatePagination();
  3180. }
  3181. }
  3182. }, {
  3183. key: 'prevPage',
  3184. value: function prevPage() {
  3185. if (this.options.pageNumber > 1) {
  3186. this.options.pageNumber--;
  3187. this.updatePagination();
  3188. }
  3189. }
  3190. }, {
  3191. key: 'nextPage',
  3192. value: function nextPage() {
  3193. if (this.options.pageNumber < this.options.totalPages) {
  3194. this.options.pageNumber++;
  3195. this.updatePagination();
  3196. }
  3197. }
  3198. }, {
  3199. key: 'toggleView',
  3200. value: function toggleView() {
  3201. this.options.cardView = !this.options.cardView;
  3202. this.initHeader();
  3203. // Fixed remove toolbar when click cardView button.
  3204. // this.initToolbar();
  3205. var $icon = this.$toolbar.find('button[name="toggle"] i');
  3206. if (this.options.cardView) {
  3207. $icon.removeClass(this.options.icons.toggleOff);
  3208. $icon.addClass(this.options.icons.toggleOn);
  3209. } else {
  3210. $icon.removeClass(this.options.icons.toggleOn);
  3211. $icon.addClass(this.options.icons.toggleOff);
  3212. }
  3213. this.initBody();
  3214. this.trigger('toggle', this.options.cardView);
  3215. }
  3216. }, {
  3217. key: 'refreshOptions',
  3218. value: function refreshOptions(options) {
  3219. // If the objects are equivalent then avoid the call of destroy / init methods
  3220. if (Utils.compareObjects(this.options, options, true)) {
  3221. return;
  3222. }
  3223. this.options = $.extend(this.options, options);
  3224. this.trigger('refresh-options', this.options);
  3225. this.destroy();
  3226. this.init();
  3227. }
  3228. }, {
  3229. key: 'resetSearch',
  3230. value: function resetSearch(text) {
  3231. var $search = this.$toolbar.find('.search input');
  3232. $search.val(text || '');
  3233. this.onSearch({ currentTarget: $search });
  3234. }
  3235. }, {
  3236. key: 'expandRow_',
  3237. value: function expandRow_(expand, index) {
  3238. var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', index));
  3239. if ($tr.next().is('tr.detail-view') === !expand) {
  3240. $tr.find('> td > .detail-icon').click();
  3241. }
  3242. }
  3243. }, {
  3244. key: 'expandRow',
  3245. value: function expandRow(index) {
  3246. this.expandRow_(true, index);
  3247. }
  3248. }, {
  3249. key: 'collapseRow',
  3250. value: function collapseRow(index) {
  3251. this.expandRow_(false, index);
  3252. }
  3253. }, {
  3254. key: 'expandAllRows',
  3255. value: function expandAllRows(isSubTable) {
  3256. var _this18 = this;
  3257. if (isSubTable) {
  3258. var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', 0));
  3259. var detailIcon = null;
  3260. var executeInterval = false;
  3261. var idInterval = -1;
  3262. if (!$tr.next().is('tr.detail-view')) {
  3263. $tr.find('> td > .detail-icon').click();
  3264. executeInterval = true;
  3265. } else if (!$tr.next().next().is('tr.detail-view')) {
  3266. $tr.next().find('.detail-icon').click();
  3267. executeInterval = true;
  3268. }
  3269. if (executeInterval) {
  3270. try {
  3271. idInterval = setInterval(function () {
  3272. detailIcon = _this18.$body.find('tr.detail-view').last().find('.detail-icon');
  3273. if (detailIcon.length > 0) {
  3274. detailIcon.click();
  3275. } else {
  3276. clearInterval(idInterval);
  3277. }
  3278. }, 1);
  3279. } catch (ex) {
  3280. clearInterval(idInterval);
  3281. }
  3282. }
  3283. } else {
  3284. var trs = this.$body.children();
  3285. for (var i = 0; i < trs.length; i++) {
  3286. this.expandRow_(true, $(trs[i]).data('index'));
  3287. }
  3288. }
  3289. }
  3290. }, {
  3291. key: 'collapseAllRows',
  3292. value: function collapseAllRows(isSubTable) {
  3293. if (isSubTable) {
  3294. this.expandRow_(false, 0);
  3295. } else {
  3296. var trs = this.$body.children();
  3297. for (var i = 0; i < trs.length; i++) {
  3298. this.expandRow_(false, $(trs[i]).data('index'));
  3299. }
  3300. }
  3301. }
  3302. }, {
  3303. key: 'updateFormatText',
  3304. value: function updateFormatText(name, text) {
  3305. if (this.options[Utils.sprintf('format%s', name)]) {
  3306. if (typeof text === 'string') {
  3307. this.options[Utils.sprintf('format%s', name)] = function () {
  3308. return text;
  3309. };
  3310. } else if (typeof text === 'function') {
  3311. this.options[Utils.sprintf('format%s', name)] = text;
  3312. }
  3313. }
  3314. this.initToolbar();
  3315. this.initPagination();
  3316. this.initBody();
  3317. }
  3318. }]);
  3319. return BootstrapTable;
  3320. }();
  3321. BootstrapTable.DEFAULTS = DEFAULTS;
  3322. BootstrapTable.LOCALES = LOCALES;
  3323. BootstrapTable.COLUMN_DEFAULTS = COLUMN_DEFAULTS;
  3324. BootstrapTable.EVENTS = EVENTS;
  3325. // BOOTSTRAP TABLE PLUGIN DEFINITION
  3326. // =======================
  3327. var allowedMethods = ['getOptions', 'getSelections', 'getAllSelections', 'getData', 'load', 'append', 'prepend', 'remove', 'removeAll', 'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId', 'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows', 'mergeCells', 'refreshColumnTitle', 'checkAll', 'uncheckAll', 'checkInvert', 'check', 'uncheck', 'checkBy', 'uncheckBy', 'refresh', 'resetView', 'resetWidth', 'destroy', 'showLoading', 'hideLoading', 'showColumn', 'hideColumn', 'getHiddenColumns', 'getVisibleColumns', 'showAllColumns', 'hideAllColumns', 'filterBy', 'scrollTo', 'getScrollPosition', 'selectPage', 'prevPage', 'nextPage', 'togglePagination', 'toggleView', 'refreshOptions', 'resetSearch', 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows', 'updateFormatText', 'updateCellById'];
  3328. $.BootstrapTable = BootstrapTable;
  3329. $.fn.bootstrapTable = function (option) {
  3330. for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key5 = 1; _key5 < _len3; _key5++) {
  3331. args[_key5 - 1] = arguments[_key5];
  3332. }
  3333. var value = void 0;
  3334. this.each(function (i, el) {
  3335. var data = $(el).data('bootstrap.table');
  3336. var options = $.extend({}, BootstrapTable.DEFAULTS, $(el).data(), (typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object' && option);
  3337. if (typeof option === 'string') {
  3338. var _data2;
  3339. if (!allowedMethods.includes(option)) {
  3340. throw new Error('Unknown method: ' + option);
  3341. }
  3342. if (!data) {
  3343. return;
  3344. }
  3345. value = (_data2 = data)[option].apply(_data2, args);
  3346. if (option === 'destroy') {
  3347. $(el).removeData('bootstrap.table');
  3348. }
  3349. }
  3350. if (!data) {
  3351. $(el).data('bootstrap.table', data = new $.BootstrapTable(el, options));
  3352. }
  3353. });
  3354. return typeof value === 'undefined' ? this : value;
  3355. };
  3356. $.fn.bootstrapTable.Constructor = BootstrapTable;
  3357. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  3358. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  3359. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  3360. $.fn.bootstrapTable.methods = allowedMethods;
  3361. $.fn.bootstrapTable.utils = Utils;
  3362. // BOOTSTRAP TABLE INIT
  3363. // =======================
  3364. $(function () {
  3365. $('[data-toggle="table"]').bootstrapTable();
  3366. });
  3367. })(jQuery);
  3368. });