bootstrap-table.js 127 KB

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