bootstrap-table.js 132 KB

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