bootstrap-table.js 136 KB

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