bootstrap-table.js 133 KB

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