bootstrap-table.js 132 KB

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