bootstrap-table.js 136 KB

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