bootstrap-table.js 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * version: 1.8.1
  4. * https://github.com/wenzhixin/bootstrap-table/
  5. */
  6. !function ($) {
  7. 'use strict';
  8. // TOOLS DEFINITION
  9. // ======================
  10. var cachedWidth = null;
  11. // it only does '%s', and return '' when arguments are undefined
  12. var sprintf = function (str) {
  13. var args = arguments,
  14. flag = true,
  15. i = 1;
  16. str = str.replace(/%s/g, function () {
  17. var arg = args[i++];
  18. if (typeof arg === 'undefined') {
  19. flag = false;
  20. return '';
  21. }
  22. return arg;
  23. });
  24. return flag ? str : '';
  25. };
  26. var getPropertyFromOther = function (list, from, to, value) {
  27. var result = '';
  28. $.each(list, function (i, item) {
  29. if (item[from] === value) {
  30. result = item[to];
  31. return false;
  32. }
  33. return true;
  34. });
  35. return result;
  36. };
  37. var getFieldIndex = function (columns, field) {
  38. var index = -1;
  39. $.each(columns, function (i, column) {
  40. if (column.field === field) {
  41. index = i;
  42. return false;
  43. }
  44. return true;
  45. });
  46. return index;
  47. };
  48. // http://jsfiddle.net/wenyi/47nz7ez9/3/
  49. var setFieldIndex = function (columns) {
  50. var i, j, k,
  51. totalCol = 0,
  52. flag = [];
  53. for (i = 0; i < columns[0].length; i++) {
  54. totalCol += columns[0][i].colspan || 1;
  55. }
  56. for (i = 0; i < columns.length; i++) {
  57. flag[i] = [];
  58. for (j = 0; j < totalCol; j++) {
  59. flag[i][j] = false;
  60. }
  61. }
  62. for (i = 0; i < columns.length; i++) {
  63. for (j = 0; j < columns[i].length; j++) {
  64. var r = columns[i][j],
  65. rowspan = r.rowspan || 1,
  66. colspan = r.colspan || 1,
  67. index = $.inArray(false, flag[i]);
  68. if (colspan === 1) {
  69. r.fieldIndex = index;
  70. // when field is undefined, use index instead
  71. if (typeof r.field === 'undefined') {
  72. r.field = index;
  73. }
  74. }
  75. for (k = 0; k < rowspan; k++) {
  76. flag[i + k][index] = true;
  77. }
  78. for (k = 0; k < colspan; k++) {
  79. flag[i][index + k] = true;
  80. }
  81. }
  82. }
  83. };
  84. var getScrollBarWidth = function () {
  85. if (cachedWidth === null) {
  86. var inner = $('<p/>').addClass('fixed-table-scroll-inner'),
  87. outer = $('<div/>').addClass('fixed-table-scroll-outer'),
  88. w1, w2;
  89. outer.append(inner);
  90. $('body').append(outer);
  91. w1 = inner[0].offsetWidth;
  92. outer.css('overflow', 'scroll');
  93. w2 = inner[0].offsetWidth;
  94. if (w1 === w2) {
  95. w2 = outer[0].clientWidth;
  96. }
  97. outer.remove();
  98. cachedWidth = w1 - w2;
  99. }
  100. return cachedWidth;
  101. };
  102. var calculateObjectValue = function (self, name, args, defaultValue) {
  103. var func = name;
  104. if (typeof name === 'string') {
  105. // support obj.func1.func2
  106. var names = name.split('.');
  107. if (names.length > 1) {
  108. func = window;
  109. $.each(names, function (i, f) {
  110. func = func[f];
  111. });
  112. } else {
  113. func = window[name];
  114. }
  115. }
  116. if (typeof func === 'object') {
  117. return func;
  118. }
  119. if (typeof func === 'function') {
  120. return func.apply(self, args);
  121. }
  122. if (!func && typeof name === 'string' && sprintf.apply(this, [name].concat(args))) {
  123. return sprintf.apply(this, [name].concat(args));
  124. }
  125. return defaultValue;
  126. };
  127. var compareObjects = function (objectA, objectB, compareLength) {
  128. // Create arrays of property names
  129. var objectAProperties = Object.getOwnPropertyNames(objectA),
  130. objectBProperties = Object.getOwnPropertyNames(objectB),
  131. propName = '';
  132. if (compareLength) {
  133. // If number of properties is different, objects are not equivalent
  134. if (objectAProperties.length !== objectBProperties.length) {
  135. return false;
  136. }
  137. }
  138. for (var i = 0; i < objectAProperties.length; i++) {
  139. propName = objectAProperties[i];
  140. // If the property is not in the object B properties, continue with the next property
  141. if ($.inArray(propName, objectBProperties) > -1) {
  142. // If values of same property are not equal, objects are not equivalent
  143. if (objectA[propName] !== objectB[propName]) {
  144. return false;
  145. }
  146. }
  147. }
  148. // If we made it this far, objects are considered equivalent
  149. return true;
  150. };
  151. var escapeHTML = function (text) {
  152. if (typeof text === 'string') {
  153. return text
  154. .replace(/&/g, "&amp;")
  155. .replace(/</g, "&lt;")
  156. .replace(/>/g, "&gt;")
  157. .replace(/"/g, "&quot;")
  158. .replace(/'/g, "&#039;");
  159. }
  160. return text;
  161. };
  162. var getRealHeight = function ($el) {
  163. var height = 0;
  164. $el.children().each(function () {
  165. if (height < $(this).outerHeight(true)) {
  166. height = $(this).outerHeight(true);
  167. }
  168. });
  169. return height;
  170. };
  171. var getRealDataAttr = function (dataAttr) {
  172. for (var attr in dataAttr) {
  173. var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
  174. if (auxAttr !== attr) {
  175. dataAttr[auxAttr] = dataAttr[attr];
  176. delete dataAttr[attr];
  177. }
  178. }
  179. return dataAttr;
  180. };
  181. var getItemField = function (item, field) {
  182. var value = item;
  183. if (field !== undefined) {
  184. var props = field.split('.');
  185. for (var p in props) {
  186. value = value[props[p]];
  187. }
  188. }
  189. return value;
  190. }
  191. // BOOTSTRAP TABLE CLASS DEFINITION
  192. // ======================
  193. var BootstrapTable = function (el, options) {
  194. this.options = options;
  195. this.$el = $(el);
  196. this.$el_ = this.$el.clone();
  197. this.timeoutId_ = 0;
  198. this.timeoutFooter_ = 0;
  199. this.init();
  200. };
  201. BootstrapTable.DEFAULTS = {
  202. classes: 'table table-hover',
  203. locale: undefined,
  204. height: undefined,
  205. undefinedText: '-',
  206. sortName: undefined,
  207. sortOrder: 'asc',
  208. striped: false,
  209. columns: [[]],
  210. data: [],
  211. dataField: 'rows',
  212. method: 'get',
  213. url: undefined,
  214. ajax: undefined,
  215. cache: true,
  216. contentType: 'application/json',
  217. dataType: 'json',
  218. ajaxOptions: {},
  219. queryParams: function (params) {
  220. return params;
  221. },
  222. queryParamsType: 'limit', // undefined
  223. responseHandler: function (res) {
  224. return res;
  225. },
  226. pagination: false,
  227. sidePagination: 'client', // client or server
  228. totalRows: 0, // server side need to set
  229. pageNumber: 1,
  230. pageSize: 10,
  231. pageList: [10, 25, 50, 100],
  232. paginationHAlign: 'right', //right, left
  233. paginationVAlign: 'bottom', //bottom, top, both
  234. paginationDetailHAlign: 'left', //right, left
  235. paginationFirstText: '&laquo;',
  236. paginationPreText: '&lsaquo;',
  237. paginationNextText: '&rsaquo;',
  238. paginationLastText: '&raquo;',
  239. search: false,
  240. strictSearch: false,
  241. searchAlign: 'right',
  242. selectItemName: 'btSelectItem',
  243. showHeader: true,
  244. showFooter: false,
  245. showColumns: false,
  246. showPaginationSwitch: false,
  247. showRefresh: false,
  248. showToggle: false,
  249. buttonsAlign: 'right',
  250. smartDisplay: true,
  251. minimumCountColumns: 1,
  252. idField: undefined,
  253. uniqueId: undefined,
  254. cardView: false,
  255. detailView: false,
  256. detailFormatter: function (index, row) {
  257. return '';
  258. },
  259. trimOnSearch: true,
  260. clickToSelect: false,
  261. singleSelect: false,
  262. toolbar: undefined,
  263. toolbarAlign: 'left',
  264. checkboxHeader: true,
  265. sortable: true,
  266. silentSort: true,
  267. maintainSelected: false,
  268. searchTimeOut: 500,
  269. searchText: '',
  270. iconSize: undefined,
  271. iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
  272. icons: {
  273. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  274. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  275. refresh: 'glyphicon-refresh icon-refresh',
  276. toggle: 'glyphicon-list-alt icon-list-alt',
  277. columns: 'glyphicon-th icon-th',
  278. detailOpen: 'glyphicon-plus icon-plus',
  279. detailClose: 'glyphicon-minus icon-minus'
  280. },
  281. rowStyle: function (row, index) {
  282. return {};
  283. },
  284. rowAttributes: function (row, index) {
  285. return {};
  286. },
  287. onAll: function (name, args) {
  288. return false;
  289. },
  290. onClickCell: function (field, value, row, $element) {
  291. return false;
  292. },
  293. onDblClickCell: function (field, value, row, $element) {
  294. return false;
  295. },
  296. onClickRow: function (item, $element) {
  297. return false;
  298. },
  299. onDblClickRow: function (item, $element) {
  300. return false;
  301. },
  302. onSort: function (name, order) {
  303. return false;
  304. },
  305. onCheck: function (row) {
  306. return false;
  307. },
  308. onUncheck: function (row) {
  309. return false;
  310. },
  311. onCheckAll: function (rows) {
  312. return false;
  313. },
  314. onUncheckAll: function (rows) {
  315. return false;
  316. },
  317. onCheckSome: function (rows) {
  318. return false;
  319. },
  320. onUncheckSome: function (rows) {
  321. return false;
  322. },
  323. onLoadSuccess: function (data) {
  324. return false;
  325. },
  326. onLoadError: function (status) {
  327. return false;
  328. },
  329. onColumnSwitch: function (field, checked) {
  330. return false;
  331. },
  332. onPageChange: function (number, size) {
  333. return false;
  334. },
  335. onSearch: function (text) {
  336. return false;
  337. },
  338. onToggle: function (cardView) {
  339. return false;
  340. },
  341. onPreBody: function (data) {
  342. return false;
  343. },
  344. onPostBody: function () {
  345. return false;
  346. },
  347. onPostHeader: function () {
  348. return false;
  349. },
  350. onExpandRow: function (index, row, $detail) {
  351. return false;
  352. },
  353. onCollapseRow: function (index, row) {
  354. return false;
  355. },
  356. onRefreshOptions: function (options) {
  357. return false;
  358. },
  359. onResetView: function () {
  360. return false;
  361. }
  362. };
  363. BootstrapTable.LOCALES = [];
  364. BootstrapTable.LOCALES['en-US'] = BootstrapTable.LOCALES['en'] = {
  365. formatLoadingMessage: function () {
  366. return 'Loading, please wait...';
  367. },
  368. formatRecordsPerPage: function (pageNumber) {
  369. return sprintf('%s records per page', pageNumber);
  370. },
  371. formatShowingRows: function (pageFrom, pageTo, totalRows) {
  372. return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
  373. },
  374. formatSearch: function () {
  375. return 'Search';
  376. },
  377. formatNoMatches: function () {
  378. return 'No matching records found';
  379. },
  380. formatPaginationSwitch: function () {
  381. return 'Hide/Show pagination';
  382. },
  383. formatRefresh: function () {
  384. return 'Refresh';
  385. },
  386. formatToggle: function () {
  387. return 'Toggle';
  388. },
  389. formatColumns: function () {
  390. return 'Columns';
  391. },
  392. formatAllRows: function () {
  393. return 'All';
  394. }
  395. };
  396. $.extend(BootstrapTable.DEFAULTS, BootstrapTable.LOCALES['en-US']);
  397. BootstrapTable.COLUMN_DEFAULTS = {
  398. radio: false,
  399. checkbox: false,
  400. checkboxEnabled: true,
  401. field: undefined,
  402. title: undefined,
  403. titleTooltip: undefined,
  404. 'class': undefined,
  405. align: undefined, // left, right, center
  406. halign: undefined, // left, right, center
  407. falign: undefined, // left, right, center
  408. valign: undefined, // top, middle, bottom
  409. width: undefined,
  410. sortable: false,
  411. order: 'asc', // asc, desc
  412. visible: true,
  413. switchable: true,
  414. clickToSelect: true,
  415. formatter: undefined,
  416. footerFormatter: undefined,
  417. events: undefined,
  418. sorter: undefined,
  419. sortName: undefined,
  420. cellStyle: undefined,
  421. searchable: true,
  422. searchFormatter: true,
  423. cardVisible: true
  424. };
  425. BootstrapTable.EVENTS = {
  426. 'all.bs.table': 'onAll',
  427. 'click-cell.bs.table': 'onClickCell',
  428. 'dbl-click-cell.bs.table': 'onDblClickCell',
  429. 'click-row.bs.table': 'onClickRow',
  430. 'dbl-click-row.bs.table': 'onDblClickRow',
  431. 'sort.bs.table': 'onSort',
  432. 'check.bs.table': 'onCheck',
  433. 'uncheck.bs.table': 'onUncheck',
  434. 'check-all.bs.table': 'onCheckAll',
  435. 'uncheck-all.bs.table': 'onUncheckAll',
  436. 'check-some.bs.table': 'onCheckSome',
  437. 'uncheck-some.bs.table': 'onUncheckSome',
  438. 'load-success.bs.table': 'onLoadSuccess',
  439. 'load-error.bs.table': 'onLoadError',
  440. 'column-switch.bs.table': 'onColumnSwitch',
  441. 'page-change.bs.table': 'onPageChange',
  442. 'search.bs.table': 'onSearch',
  443. 'toggle.bs.table': 'onToggle',
  444. 'pre-body.bs.table': 'onPreBody',
  445. 'post-body.bs.table': 'onPostBody',
  446. 'post-header.bs.table': 'onPostHeader',
  447. 'expand-row.bs.table': 'onExpandRow',
  448. 'collapse-row.bs.table': 'onCollapseRow',
  449. 'refresh-options.bs.table': 'onRefreshOptions',
  450. 'reset-view.bs.table': 'onResetView'
  451. };
  452. BootstrapTable.prototype.init = function () {
  453. this.initLocale();
  454. this.initContainer();
  455. this.initTable();
  456. this.initHeader();
  457. this.initData();
  458. this.initFooter();
  459. this.initToolbar();
  460. this.initPagination();
  461. this.initBody();
  462. this.initSearchText();
  463. this.initServer();
  464. };
  465. BootstrapTable.prototype.initLocale = function () {
  466. if (this.options.locale) {
  467. var parts = this.options.locale.split(/-|_/);
  468. parts[0].toLowerCase();
  469. parts[1] && parts[1].toUpperCase();
  470. if ($.fn.bootstrapTable.locales[this.options.locale]) {
  471. // locale as requested
  472. $.extend(this.options, $.fn.bootstrapTable.locales[this.options.locale]);
  473. } else if ($.fn.bootstrapTable.locales[parts.join('-')]) {
  474. // locale with sep set to - (in case original was specified with _)
  475. $.extend(this.options, $.fn.bootstrapTable.locales[parts.join('-')]);
  476. } else if ($.fn.bootstrapTable.locales[parts[0]]) {
  477. // short locale language code (i.e. 'en')
  478. $.extend(this.options, $.fn.bootstrapTable.locales[parts[0]]);
  479. }
  480. }
  481. };
  482. BootstrapTable.prototype.initContainer = function () {
  483. this.$container = $([
  484. '<div class="bootstrap-table">',
  485. '<div class="fixed-table-toolbar"></div>',
  486. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  487. '<div class="fixed-table-pagination" style="clear: both;"></div>' :
  488. '',
  489. '<div class="fixed-table-container">',
  490. '<div class="fixed-table-header"><table></table></div>',
  491. '<div class="fixed-table-body">',
  492. '<div class="fixed-table-loading">',
  493. this.options.formatLoadingMessage(),
  494. '</div>',
  495. '</div>',
  496. '<div class="fixed-table-footer"><table><tr></tr></table></div>',
  497. this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
  498. '<div class="fixed-table-pagination"></div>' :
  499. '',
  500. '</div>',
  501. '</div>'
  502. ].join(''));
  503. this.$container.insertAfter(this.$el);
  504. this.$tableContainer = this.$container.find('.fixed-table-container');
  505. this.$tableHeader = this.$container.find('.fixed-table-header');
  506. this.$tableBody = this.$container.find('.fixed-table-body');
  507. this.$tableLoading = this.$container.find('.fixed-table-loading');
  508. this.$tableFooter = this.$container.find('.fixed-table-footer');
  509. this.$toolbar = this.$container.find('.fixed-table-toolbar');
  510. this.$pagination = this.$container.find('.fixed-table-pagination');
  511. this.$tableBody.append(this.$el);
  512. this.$container.after('<div class="clearfix"></div>');
  513. this.$el.addClass(this.options.classes);
  514. if (this.options.striped) {
  515. this.$el.addClass('table-striped');
  516. }
  517. if ($.inArray('table-no-bordered', this.options.classes.split(' ')) !== -1) {
  518. this.$tableContainer.addClass('table-no-bordered');
  519. }
  520. };
  521. BootstrapTable.prototype.initTable = function () {
  522. var that = this,
  523. columns = [],
  524. data = [];
  525. this.$header = this.$el.find('thead');
  526. if (!this.$header.length) {
  527. this.$header = $('<thead></thead>').appendTo(this.$el);
  528. }
  529. this.$header.find('tr').each(function () {
  530. var column = [];
  531. $(this).find('th').each(function () {
  532. column.push($.extend({}, {
  533. title: $(this).html(),
  534. 'class': $(this).attr('class'),
  535. titleTooltip: $(this).attr('title'),
  536. rowspan: $(this).attr('rowspan') ? +$(this).attr('rowspan') : undefined,
  537. colspan: $(this).attr('colspan') ? +$(this).attr('colspan') : undefined
  538. }, $(this).data()));
  539. });
  540. columns.push(column);
  541. });
  542. if (!$.isArray(this.options.columns[0])) {
  543. this.options.columns = [this.options.columns];
  544. }
  545. this.options.columns = $.extend(true, [], columns, this.options.columns);
  546. this.columns = [];
  547. setFieldIndex(this.options.columns);
  548. $.each(this.options.columns, function (i, columns) {
  549. $.each(columns, function (j, column) {
  550. column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, column);
  551. if (typeof column.fieldIndex !== 'undefined') {
  552. that.columns[column.fieldIndex] = column;
  553. }
  554. that.options.columns[i][j] = column;
  555. });
  556. });
  557. // if options.data is setting, do not process tbody data
  558. if (this.options.data.length) {
  559. return;
  560. }
  561. this.$el.find('tbody tr').each(function () {
  562. var row = {};
  563. // save tr's id, class and data-* attributes
  564. row._id = $(this).attr('id');
  565. row._class = $(this).attr('class');
  566. row._data = getRealDataAttr($(this).data());
  567. $(this).find('td').each(function (i) {
  568. var field = that.columns[i].field;
  569. row[field] = $(this).html();
  570. // save td's id, class and data-* attributes
  571. row['_' + field + '_id'] = $(this).attr('id');
  572. row['_' + field + '_class'] = $(this).attr('class');
  573. row['_' + field + '_rowspan'] = $(this).attr('rowspan');
  574. row['_' + field + '_title'] = $(this).attr('title');
  575. row['_' + field + '_data'] = getRealDataAttr($(this).data());
  576. });
  577. data.push(row);
  578. });
  579. this.options.data = data;
  580. };
  581. BootstrapTable.prototype.initHeader = function () {
  582. var that = this,
  583. visibleColumns = {},
  584. html = [];
  585. this.header = {
  586. fields: [],
  587. styles: [],
  588. classes: [],
  589. formatters: [],
  590. events: [],
  591. sorters: [],
  592. sortNames: [],
  593. cellStyles: [],
  594. searchables: []
  595. };
  596. $.each(this.options.columns, function (i, columns) {
  597. html.push('<tr>');
  598. if (i == 0 && !that.options.cardView && that.options.detailView) {
  599. html.push(sprintf('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>',
  600. that.options.columns.length));
  601. }
  602. $.each(columns, function (j, column) {
  603. var text = '',
  604. halign = '', // header align style
  605. align = '', // body align style
  606. style = '',
  607. class_ = sprintf(' class="%s"', column['class']),
  608. order = that.options.sortOrder || column.order,
  609. unitWidth = 'px',
  610. width = column.width;
  611. if (column.width !== undefined && (!that.options.cardView)) {
  612. if (typeof column.width === 'string') {
  613. if (column.width.indexOf('%') !== -1) {
  614. unitWidth = '%';
  615. }
  616. }
  617. }
  618. if (column.width && typeof column.width === 'string') {
  619. width = column.width.replace('%', '').replace('px', '');
  620. }
  621. halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  622. align = sprintf('text-align: %s; ', column.align);
  623. style = sprintf('vertical-align: %s; ', column.valign);
  624. style += sprintf('width: %s%s; ', column.checkbox || column.radio ? 36 : width, unitWidth);
  625. if (typeof column.fieldIndex !== 'undefined') {
  626. that.header.fields[column.fieldIndex] = column.field;
  627. that.header.styles[column.fieldIndex] = align + style;
  628. that.header.classes[column.fieldIndex] = class_;
  629. that.header.formatters[column.fieldIndex] = column.formatter;
  630. that.header.events[column.fieldIndex] = column.events;
  631. that.header.sorters[column.fieldIndex] = column.sorter;
  632. that.header.sortNames[column.fieldIndex] = column.sortName;
  633. that.header.cellStyles[column.fieldIndex] = column.cellStyle;
  634. that.header.searchables[column.fieldIndex] = column.searchable;
  635. if (!column.visible) {
  636. return;
  637. }
  638. if (that.options.cardView && (!column.cardVisible)) {
  639. return;
  640. }
  641. visibleColumns[column.field] = column;
  642. }
  643. html.push('<th' + sprintf(' title="%s"', column.titleTooltip),
  644. column.checkbox || column.radio ?
  645. sprintf(' class="bs-checkbox %s"', column['class'] || '') :
  646. class_,
  647. sprintf(' style="%s"', halign + style),
  648. sprintf(' rowspan="%s"', column.rowspan),
  649. sprintf(' colspan="%s"', column.colspan),
  650. sprintf(' data-field="%s"', column.field),
  651. "tabindex='0'",
  652. '>');
  653. html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
  654. 'sortable both' : ''));
  655. text = column.title;
  656. if (column.checkbox) {
  657. if (!that.options.singleSelect && that.options.checkboxHeader) {
  658. text = '<input name="btSelectAll" type="checkbox" />';
  659. }
  660. that.header.stateField = column.field;
  661. }
  662. if (column.radio) {
  663. text = '';
  664. that.header.stateField = column.field;
  665. that.options.singleSelect = true;
  666. }
  667. html.push(text);
  668. html.push('</div>');
  669. html.push('<div class="fht-cell"></div>');
  670. html.push('</div>');
  671. html.push('</th>');
  672. });
  673. html.push('</tr>');
  674. });
  675. this.$header.html(html.join(''));
  676. this.$header.find('th[data-field]').each(function (i) {
  677. $(this).data(visibleColumns[$(this).data('field')]);
  678. });
  679. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
  680. if (that.options.sortable && $(this).parent().data().sortable) {
  681. that.onSort(event);
  682. }
  683. });
  684. this.$header.children().children().off('keypress').on('keypress', function (event) {
  685. if (that.options.sortable && $(this).data().sortable) {
  686. var code = event.keyCode || event.which;
  687. if (code == 13) { //Enter keycode
  688. that.onSort(event);
  689. }
  690. }
  691. });
  692. if (!this.options.showHeader || this.options.cardView) {
  693. this.$header.hide();
  694. this.$tableHeader.hide();
  695. this.$tableLoading.css('top', 0);
  696. } else {
  697. this.$header.show();
  698. this.$tableHeader.show();
  699. this.$tableLoading.css('top', this.$header.outerHeight() + 1);
  700. // Assign the correct sortable arrow
  701. this.getCaret();
  702. }
  703. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  704. this.$container.off('click', '[name="btSelectAll"]')
  705. .on('click', '[name="btSelectAll"]', function () {
  706. var checked = $(this).prop('checked');
  707. that[checked ? 'checkAll' : 'uncheckAll']();
  708. });
  709. };
  710. BootstrapTable.prototype.initFooter = function () {
  711. if (!this.options.showFooter || this.options.cardView) {
  712. this.$tableFooter.hide();
  713. } else {
  714. this.$tableFooter.show();
  715. }
  716. };
  717. /**
  718. * @param data
  719. * @param type: append / prepend
  720. */
  721. BootstrapTable.prototype.initData = function (data, type) {
  722. if (type === 'append') {
  723. this.data = this.data.concat(data);
  724. } else if (type === 'prepend') {
  725. this.data = [].concat(data).concat(this.data);
  726. } else {
  727. this.data = data || this.options.data;
  728. }
  729. // Fix #839 Records deleted when adding new row on filtered table
  730. if (type === 'append') {
  731. this.options.data = this.options.data.concat(data);
  732. } else if (type === 'prepend') {
  733. this.options.data = [].concat(data).concat(this.options.data);
  734. } else {
  735. this.options.data = this.data;
  736. }
  737. if (this.options.sidePagination === 'server') {
  738. return;
  739. }
  740. this.initSort();
  741. };
  742. BootstrapTable.prototype.initSort = function () {
  743. var that = this,
  744. name = this.options.sortName,
  745. order = this.options.sortOrder === 'desc' ? -1 : 1,
  746. index = $.inArray(this.options.sortName, this.header.fields);
  747. if (index !== -1) {
  748. this.data.sort(function (a, b) {
  749. if (that.header.sortNames[index]) {
  750. name = that.header.sortNames[index];
  751. }
  752. var aa = getItemField(a, name),
  753. bb = getItemField(b, name),
  754. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
  755. if (value !== undefined) {
  756. return order * value;
  757. }
  758. // Fix #161: undefined or null string sort bug.
  759. if (aa === undefined || aa === null) {
  760. aa = '';
  761. }
  762. if (bb === undefined || bb === null) {
  763. bb = '';
  764. }
  765. // IF both values are numeric, do a numeric comparison
  766. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  767. // Convert numerical values form string to float.
  768. aa = parseFloat(aa);
  769. bb = parseFloat(bb);
  770. if (aa < bb) {
  771. return order * -1;
  772. }
  773. return order;
  774. }
  775. if (aa === bb) {
  776. return 0;
  777. }
  778. // If value is not a string, convert to string
  779. if (typeof aa !== 'string') {
  780. aa = aa.toString();
  781. }
  782. if (aa.localeCompare(bb) === -1) {
  783. return order * -1;
  784. }
  785. return order;
  786. });
  787. }
  788. };
  789. BootstrapTable.prototype.onSort = function (event) {
  790. var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(),
  791. $this_ = this.$header.find('th').eq($this.index());
  792. this.$header.add(this.$header_).find('span.order').remove();
  793. if (this.options.sortName === $this.data('field')) {
  794. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  795. } else {
  796. this.options.sortName = $this.data('field');
  797. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  798. }
  799. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  800. $this.add($this_).data('order', this.options.sortOrder);
  801. // Assign the correct sortable arrow
  802. this.getCaret();
  803. if (this.options.sidePagination === 'server') {
  804. this.initServer(this.options.silentSort);
  805. return;
  806. }
  807. this.initSort();
  808. this.initBody();
  809. };
  810. BootstrapTable.prototype.initToolbar = function () {
  811. var that = this,
  812. html = [],
  813. timeoutId = 0,
  814. $keepOpen,
  815. $search,
  816. switchableCount = 0;
  817. this.$toolbar.html('');
  818. if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
  819. $(sprintf('<div class="bars pull-%s"></div>', this.options.toolbarAlign))
  820. .appendTo(this.$toolbar)
  821. .append($(this.options.toolbar));
  822. }
  823. // showColumns, showToggle, showRefresh
  824. html = [sprintf('<div class="columns columns-%s btn-group pull-%s">',
  825. this.options.buttonsAlign, this.options.buttonsAlign)];
  826. if (typeof this.options.icons === 'string') {
  827. this.options.icons = calculateObjectValue(null, this.options.icons);
  828. }
  829. if (this.options.showPaginationSwitch) {
  830. html.push(sprintf('<button class="btn btn-default" type="button" name="paginationSwitch" title="%s">',
  831. this.options.formatPaginationSwitch()),
  832. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
  833. '</button>');
  834. }
  835. if (this.options.showRefresh) {
  836. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="refresh" title="%s">',
  837. this.options.formatRefresh()),
  838. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
  839. '</button>');
  840. }
  841. if (this.options.showToggle) {
  842. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="toggle" title="%s">',
  843. this.options.formatToggle()),
  844. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
  845. '</button>');
  846. }
  847. if (this.options.showColumns) {
  848. html.push(sprintf('<div class="keep-open btn-group" title="%s">',
  849. this.options.formatColumns()),
  850. '<button type="button" class="btn btn-default' + (this.options.iconSize == undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
  851. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
  852. ' <span class="caret"></span>',
  853. '</button>',
  854. '<ul class="dropdown-menu" role="menu">');
  855. $.each(this.columns, function (i, column) {
  856. if (column.radio || column.checkbox) {
  857. return;
  858. }
  859. if (that.options.cardView && (!column.cardVisible)) {
  860. return;
  861. }
  862. var checked = column.visible ? ' checked="checked"' : '';
  863. if (column.switchable) {
  864. html.push(sprintf('<li>' +
  865. '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
  866. '</li>', column.field, i, checked, column.title));
  867. switchableCount++;
  868. }
  869. });
  870. html.push('</ul>',
  871. '</div>');
  872. }
  873. html.push('</div>');
  874. // Fix #188: this.showToolbar is for extentions
  875. if (this.showToolbar || html.length > 2) {
  876. this.$toolbar.append(html.join(''));
  877. }
  878. if (this.options.showPaginationSwitch) {
  879. this.$toolbar.find('button[name="paginationSwitch"]')
  880. .off('click').on('click', $.proxy(this.togglePagination, this));
  881. }
  882. if (this.options.showRefresh) {
  883. this.$toolbar.find('button[name="refresh"]')
  884. .off('click').on('click', $.proxy(this.refresh, this));
  885. }
  886. if (this.options.showToggle) {
  887. this.$toolbar.find('button[name="toggle"]')
  888. .off('click').on('click', function () {
  889. that.toggleView();
  890. });
  891. }
  892. if (this.options.showColumns) {
  893. $keepOpen = this.$toolbar.find('.keep-open');
  894. if (switchableCount <= this.options.minimumCountColumns) {
  895. $keepOpen.find('input').prop('disabled', true);
  896. }
  897. $keepOpen.find('li').off('click').on('click', function (event) {
  898. event.stopImmediatePropagation();
  899. });
  900. $keepOpen.find('input').off('click').on('click', function () {
  901. var $this = $(this);
  902. that.toggleColumn(getFieldIndex(that.columns,
  903. $(this).data('field')), $this.prop('checked'), false);
  904. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  905. });
  906. }
  907. if (this.options.search) {
  908. html = [];
  909. html.push(
  910. '<div class="pull-' + this.options.searchAlign + ' search">',
  911. sprintf('<input class="form-control' + (this.options.iconSize === undefined ? '' : ' input-' + this.options.iconSize) + '" type="text" placeholder="%s">',
  912. this.options.formatSearch()),
  913. '</div>');
  914. this.$toolbar.append(html.join(''));
  915. $search = this.$toolbar.find('.search input');
  916. $search.off('keyup drop').on('keyup drop', function (event) {
  917. clearTimeout(timeoutId); // doesn't matter if it's 0
  918. timeoutId = setTimeout(function () {
  919. that.onSearch(event);
  920. }, that.options.searchTimeOut);
  921. });
  922. }
  923. };
  924. BootstrapTable.prototype.onSearch = function (event) {
  925. var text = $.trim($(event.currentTarget).val());
  926. // trim search input
  927. if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
  928. $(event.currentTarget).val(text);
  929. }
  930. if (text === this.searchText) {
  931. return;
  932. }
  933. this.searchText = text;
  934. this.options.pageNumber = 1;
  935. this.initSearch();
  936. this.updatePagination();
  937. this.trigger('search', text);
  938. };
  939. BootstrapTable.prototype.initSearch = function () {
  940. var that = this;
  941. if (this.options.sidePagination !== 'server') {
  942. var s = this.searchText && this.searchText.toLowerCase();
  943. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  944. // Check filter
  945. this.data = f ? $.grep(this.options.data, function (item, i) {
  946. for (var key in f) {
  947. if (item[key] !== f[key]) {
  948. return false;
  949. }
  950. }
  951. return true;
  952. }) : this.options.data;
  953. this.data = s ? $.grep(this.data, function (item, i) {
  954. for (var key in item) {
  955. key = $.isNumeric(key) ? parseInt(key, 10) : key;
  956. var value = item[key],
  957. column = that.columns[getFieldIndex(that.columns, key)],
  958. j = $.inArray(key, that.header.fields);
  959. // Fix #142: search use formated data
  960. if (column && column.searchFormatter) {
  961. value = calculateObjectValue(column,
  962. that.header.formatters[j], [value, item, i], value);
  963. }
  964. var index = $.inArray(key, that.header.fields);
  965. if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
  966. if (that.options.strictSearch) {
  967. if ((value + '').toLowerCase() === s) {
  968. return true;
  969. }
  970. } else {
  971. if ((value + '').toLowerCase().indexOf(s) !== -1) {
  972. return true;
  973. }
  974. }
  975. }
  976. }
  977. return false;
  978. }) : this.data;
  979. }
  980. };
  981. BootstrapTable.prototype.initPagination = function () {
  982. if (!this.options.pagination) {
  983. this.$pagination.hide();
  984. return;
  985. } else {
  986. this.$pagination.show();
  987. }
  988. var that = this,
  989. html = [],
  990. $allSelected = false,
  991. i, from, to,
  992. $pageList,
  993. $first, $pre,
  994. $next, $last,
  995. $number,
  996. data = this.getData();
  997. if (this.options.sidePagination !== 'server') {
  998. this.options.totalRows = data.length;
  999. }
  1000. this.totalPages = 0;
  1001. if (this.options.totalRows) {
  1002. if (this.options.pageSize === this.options.formatAllRows()) {
  1003. this.options.pageSize = this.options.totalRows;
  1004. $allSelected = true;
  1005. } else if (this.options.pageSize === this.options.totalRows) {
  1006. // Fix #667 Table with pagination,
  1007. // multiple pages and a search that matches to one page throws exception
  1008. var pageLst = typeof this.options.pageList === 'string' ?
  1009. this.options.pageList.replace('[', '').replace(']', '')
  1010. .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
  1011. if (pageLst.indexOf(this.options.formatAllRows().toLowerCase()) > -1) {
  1012. $allSelected = true;
  1013. }
  1014. }
  1015. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  1016. this.options.totalPages = this.totalPages;
  1017. }
  1018. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  1019. this.options.pageNumber = this.totalPages;
  1020. }
  1021. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  1022. this.pageTo = this.options.pageNumber * this.options.pageSize;
  1023. if (this.pageTo > this.options.totalRows) {
  1024. this.pageTo = this.options.totalRows;
  1025. }
  1026. html.push(
  1027. '<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
  1028. '<span class="pagination-info">',
  1029. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  1030. '</span>');
  1031. html.push('<span class="page-list">');
  1032. var pageNumber = [
  1033. sprintf('<span class="btn-group %s">',
  1034. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  1035. 'dropdown' : 'dropup'),
  1036. '<button type="button" class="btn btn-default ' +
  1037. (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
  1038. ' dropdown-toggle" data-toggle="dropdown">',
  1039. '<span class="page-size">',
  1040. $allSelected ? this.options.formatAllRows() : this.options.pageSize,
  1041. '</span>',
  1042. ' <span class="caret"></span>',
  1043. '</button>',
  1044. '<ul class="dropdown-menu" role="menu">'
  1045. ],
  1046. pageList = this.options.pageList;
  1047. if (typeof this.options.pageList === 'string') {
  1048. var list = this.options.pageList.replace('[', '').replace(']', '')
  1049. .replace(/ /g, '').split(',');
  1050. pageList = [];
  1051. $.each(list, function (i, value) {
  1052. pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
  1053. that.options.formatAllRows() : +value);
  1054. });
  1055. }
  1056. $.each(pageList, function (i, page) {
  1057. if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
  1058. var active;
  1059. if ($allSelected) {
  1060. active = page === that.options.formatAllRows() ? ' class="active"' : '';
  1061. } else {
  1062. active = page === that.options.pageSize ? ' class="active"' : '';
  1063. }
  1064. pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
  1065. }
  1066. });
  1067. pageNumber.push('</ul></span>');
  1068. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  1069. html.push('</span>');
  1070. html.push('</div>',
  1071. '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
  1072. '<ul class="pagination' + (this.options.iconSize === undefined ? '' : ' pagination-' + this.options.iconSize) + '">',
  1073. '<li class="page-first"><a href="javascript:void(0)">' + this.options.paginationFirstText + '</a></li>',
  1074. '<li class="page-pre"><a href="javascript:void(0)">' + this.options.paginationPreText + '</a></li>');
  1075. if (this.totalPages < 5) {
  1076. from = 1;
  1077. to = this.totalPages;
  1078. } else {
  1079. from = this.options.pageNumber - 2;
  1080. to = from + 4;
  1081. if (from < 1) {
  1082. from = 1;
  1083. to = 5;
  1084. }
  1085. if (to > this.totalPages) {
  1086. to = this.totalPages;
  1087. from = to - 4;
  1088. }
  1089. }
  1090. for (i = from; i <= to; i++) {
  1091. html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
  1092. '<a href="javascript:void(0)">', i, '</a>',
  1093. '</li>');
  1094. }
  1095. html.push(
  1096. '<li class="page-next"><a href="javascript:void(0)">' + this.options.paginationNextText + '</a></li>',
  1097. '<li class="page-last"><a href="javascript:void(0)">' + this.options.paginationLastText + '</a></li>',
  1098. '</ul>',
  1099. '</div>');
  1100. this.$pagination.html(html.join(''));
  1101. $pageList = this.$pagination.find('.page-list a');
  1102. $first = this.$pagination.find('.page-first');
  1103. $pre = this.$pagination.find('.page-pre');
  1104. $next = this.$pagination.find('.page-next');
  1105. $last = this.$pagination.find('.page-last');
  1106. $number = this.$pagination.find('.page-number');
  1107. if (this.options.pageNumber <= 1) {
  1108. $first.addClass('disabled');
  1109. $pre.addClass('disabled');
  1110. }
  1111. if (this.options.pageNumber >= this.totalPages) {
  1112. $next.addClass('disabled');
  1113. $last.addClass('disabled');
  1114. }
  1115. if (this.options.smartDisplay) {
  1116. if (this.totalPages <= 1) {
  1117. this.$pagination.find('div.pagination').hide();
  1118. }
  1119. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  1120. this.$pagination.find('span.page-list').hide();
  1121. }
  1122. // when data is empty, hide the pagination
  1123. this.$pagination[this.getData().length ? 'show' : 'hide']();
  1124. }
  1125. if ($allSelected) {
  1126. this.options.pageSize = this.options.formatAllRows();
  1127. }
  1128. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  1129. $first.off('click').on('click', $.proxy(this.onPageFirst, this));
  1130. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1131. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1132. $last.off('click').on('click', $.proxy(this.onPageLast, this));
  1133. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1134. };
  1135. BootstrapTable.prototype.updatePagination = function (event) {
  1136. // Fix #171: IE disabled button can be clicked bug.
  1137. if (event && $(event.currentTarget).hasClass('disabled')) {
  1138. return;
  1139. }
  1140. if (!this.options.maintainSelected) {
  1141. this.resetRows();
  1142. }
  1143. this.initPagination();
  1144. if (this.options.sidePagination === 'server') {
  1145. this.initServer();
  1146. } else {
  1147. this.initBody();
  1148. }
  1149. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1150. };
  1151. BootstrapTable.prototype.onPageListChange = function (event) {
  1152. var $this = $(event.currentTarget);
  1153. $this.parent().addClass('active').siblings().removeClass('active');
  1154. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
  1155. this.options.formatAllRows() : +$this.text();
  1156. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1157. this.updatePagination(event);
  1158. };
  1159. BootstrapTable.prototype.onPageFirst = function (event) {
  1160. this.options.pageNumber = 1;
  1161. this.updatePagination(event);
  1162. };
  1163. BootstrapTable.prototype.onPagePre = function (event) {
  1164. this.options.pageNumber--;
  1165. this.updatePagination(event);
  1166. };
  1167. BootstrapTable.prototype.onPageNext = function (event) {
  1168. this.options.pageNumber++;
  1169. this.updatePagination(event);
  1170. };
  1171. BootstrapTable.prototype.onPageLast = function (event) {
  1172. this.options.pageNumber = this.totalPages;
  1173. this.updatePagination(event);
  1174. };
  1175. BootstrapTable.prototype.onPageNumber = function (event) {
  1176. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1177. return;
  1178. }
  1179. this.options.pageNumber = +$(event.currentTarget).text();
  1180. this.updatePagination(event);
  1181. };
  1182. BootstrapTable.prototype.initBody = function (fixedScroll) {
  1183. var that = this,
  1184. html = [],
  1185. data = this.getData();
  1186. this.trigger('pre-body', data);
  1187. this.$body = this.$el.find('tbody');
  1188. if (!this.$body.length) {
  1189. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1190. }
  1191. //Fix #389 Bootstrap-table-flatJSON is not working
  1192. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1193. this.pageFrom = 1;
  1194. this.pageTo = data.length;
  1195. }
  1196. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1197. var key,
  1198. item = data[i],
  1199. style = {},
  1200. csses = [],
  1201. data_ = '',
  1202. attributes = {},
  1203. htmlAttributes = [];
  1204. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1205. if (style && style.css) {
  1206. for (key in style.css) {
  1207. csses.push(key + ': ' + style.css[key]);
  1208. }
  1209. }
  1210. attributes = calculateObjectValue(this.options,
  1211. this.options.rowAttributes, [item, i], attributes);
  1212. if (attributes) {
  1213. for (key in attributes) {
  1214. htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
  1215. }
  1216. }
  1217. if (item._data && !$.isEmptyObject(item._data)) {
  1218. $.each(item._data, function (k, v) {
  1219. // ignore data-index
  1220. if (k === 'index') {
  1221. return;
  1222. }
  1223. data_ += sprintf(' data-%s="%s"', k, v);
  1224. });
  1225. }
  1226. html.push('<tr',
  1227. sprintf(' %s', htmlAttributes.join(' ')),
  1228. sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
  1229. sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
  1230. sprintf(' data-index="%s"', i),
  1231. sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
  1232. sprintf('%s', data_),
  1233. '>'
  1234. );
  1235. if (this.options.cardView) {
  1236. html.push(sprintf('<td colspan="%s">', this.header.fields.length));
  1237. }
  1238. if (!this.options.cardView && this.options.detailView) {
  1239. html.push('<td>',
  1240. '<a class="detail-icon" href="javascript:">',
  1241. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
  1242. '</a>',
  1243. '</td>');
  1244. }
  1245. $.each(this.header.fields, function (j, field) {
  1246. var text = '',
  1247. value = getItemField(item, field),
  1248. type = '',
  1249. cellStyle = {},
  1250. id_ = '',
  1251. class_ = that.header.classes[j],
  1252. data_ = '',
  1253. rowspan_ = '',
  1254. title_ = '',
  1255. column = that.columns[getFieldIndex(that.columns, field)];
  1256. if (!column.visible) {
  1257. return;
  1258. }
  1259. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  1260. value = calculateObjectValue(column,
  1261. that.header.formatters[j], [value, item, i], value);
  1262. // handle td's id and class
  1263. if (item['_' + field + '_id']) {
  1264. id_ = sprintf(' id="%s"', item['_' + field + '_id']);
  1265. }
  1266. if (item['_' + field + '_class']) {
  1267. class_ = sprintf(' class="%s"', item['_' + field + '_class']);
  1268. }
  1269. if (item['_' + field + '_rowspan']) {
  1270. rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1271. }
  1272. if (item['_' + field + '_title']) {
  1273. title_ = sprintf(' title="%s"', item['_' + field + '_title']);
  1274. }
  1275. cellStyle = calculateObjectValue(that.header,
  1276. that.header.cellStyles[j], [value, item, i], cellStyle);
  1277. if (cellStyle.classes) {
  1278. class_ = sprintf(' class="%s"', cellStyle.classes);
  1279. }
  1280. if (cellStyle.css) {
  1281. var csses_ = [];
  1282. for (var key in cellStyle.css) {
  1283. csses_.push(key + ': ' + cellStyle.css[key]);
  1284. }
  1285. style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
  1286. }
  1287. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1288. $.each(item['_' + field + '_data'], function (k, v) {
  1289. // ignore data-index
  1290. if (k === 'index') {
  1291. return;
  1292. }
  1293. data_ += sprintf(' data-%s="%s"', k, v);
  1294. });
  1295. }
  1296. if (column.checkbox || column.radio) {
  1297. type = column.checkbox ? 'checkbox' : type;
  1298. type = column.radio ? 'radio' : type;
  1299. text = [that.options.cardView ?
  1300. '<div class="card-view">' : '<td class="bs-checkbox">',
  1301. '<input' +
  1302. sprintf(' data-index="%s"', i) +
  1303. sprintf(' name="%s"', that.options.selectItemName) +
  1304. sprintf(' type="%s"', type) +
  1305. sprintf(' value="%s"', item[that.options.idField]) +
  1306. sprintf(' checked="%s"', value === true ||
  1307. (value && value.checked) ? 'checked' : undefined) +
  1308. sprintf(' disabled="%s"', !column.checkboxEnabled ||
  1309. (value && value.disabled) ? 'disabled' : undefined) +
  1310. ' />',
  1311. that.options.cardView ? '</div>' : '</td>'
  1312. ].join('');
  1313. item[that.header.stateField] = value === true || (value && value.checked);
  1314. } else {
  1315. value = typeof value === 'undefined' || value === null ?
  1316. that.options.undefinedText : value;
  1317. text = that.options.cardView ? ['<div class="card-view">',
  1318. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  1319. getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
  1320. sprintf('<span class="value">%s</span>', value),
  1321. '</div>'
  1322. ].join('') : [sprintf('<td%s %s %s %s %s %s>', id_, class_, style, data_, rowspan_, title_),
  1323. value,
  1324. '</td>'
  1325. ].join('');
  1326. // Hide empty data on Card view when smartDisplay is set to true.
  1327. if (that.options.cardView && that.options.smartDisplay && value === '') {
  1328. text = '';
  1329. }
  1330. }
  1331. html.push(text);
  1332. });
  1333. if (this.options.cardView) {
  1334. html.push('</td>');
  1335. }
  1336. html.push('</tr>');
  1337. }
  1338. // show no records
  1339. if (!html.length) {
  1340. html.push('<tr class="no-records-found">',
  1341. sprintf('<td colspan="%s">%s</td>',
  1342. this.$header.find('th').length, this.options.formatNoMatches()),
  1343. '</tr>');
  1344. }
  1345. this.$body.html(html.join(''));
  1346. if (!fixedScroll) {
  1347. this.scrollTo(0);
  1348. }
  1349. // click to select by column
  1350. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
  1351. var $td = $(this),
  1352. $tr = $td.parent(),
  1353. item = that.data[$tr.data('index')],
  1354. index = $td[0].cellIndex,
  1355. field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
  1356. colomn = that.columns[getFieldIndex(that.columns, field)],
  1357. value = getItemField(item, field);
  1358. if ($td.find('.detail-icon').length) {
  1359. return;
  1360. }
  1361. that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  1362. that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr);
  1363. // if click to select - then trigger the checkbox/radio click
  1364. if (e.type === 'click' && that.options.clickToSelect && colomn.clickToSelect) {
  1365. var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
  1366. if ($selectItem.length) {
  1367. $selectItem[0].click(); // #144: .trigger('click') bug
  1368. }
  1369. }
  1370. });
  1371. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function () {
  1372. var $this = $(this),
  1373. $tr = $this.parent().parent(),
  1374. index = $tr.data('index'),
  1375. row = data[index]; // Fix #980 Detail view, when searching, returns wrong row
  1376. // remove and update
  1377. if ($tr.next().is('tr.detail-view')) {
  1378. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailOpen));
  1379. $tr.next().remove();
  1380. that.trigger('collapse-row', index, row);
  1381. } else {
  1382. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
  1383. $tr.after(sprintf('<tr class="detail-view"><td colspan="%s">%s</td></tr>',
  1384. $tr.find('td').length, calculateObjectValue(that.options,
  1385. that.options.detailFormatter, [index, row], '')));
  1386. that.trigger('expand-row', index, row, $tr.next().find('td'));
  1387. }
  1388. that.resetView();
  1389. });
  1390. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  1391. this.$selectItem.off('click').on('click', function (event) {
  1392. event.stopImmediatePropagation();
  1393. var checked = $(this).prop('checked'),
  1394. row = that.data[$(this).data('index')];
  1395. row[that.header.stateField] = checked;
  1396. if (that.options.singleSelect) {
  1397. that.$selectItem.not(this).each(function () {
  1398. that.data[$(this).data('index')][that.header.stateField] = false;
  1399. });
  1400. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  1401. }
  1402. that.updateSelected();
  1403. that.trigger(checked ? 'check' : 'uncheck', row);
  1404. });
  1405. $.each(this.header.events, function (i, events) {
  1406. if (!events) {
  1407. return;
  1408. }
  1409. // fix bug, if events is defined with namespace
  1410. if (typeof events === 'string') {
  1411. events = calculateObjectValue(null, events);
  1412. }
  1413. var field = that.header.fields[i],
  1414. fieldIndex = $.inArray(field, that.getVisibleFields());
  1415. if (that.options.detailView && !that.options.cardView) {
  1416. fieldIndex += 1;
  1417. }
  1418. for (var key in events) {
  1419. that.$body.find('tr').each(function () {
  1420. var $tr = $(this),
  1421. $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
  1422. index = key.indexOf(' '),
  1423. name = key.substring(0, index),
  1424. el = key.substring(index + 1),
  1425. func = events[key];
  1426. $td.find(el).off(name).on(name, function (e) {
  1427. var index = $tr.data('index'),
  1428. row = that.data[index],
  1429. value = row[field];
  1430. func.apply(this, [e, value, row, index]);
  1431. });
  1432. });
  1433. }
  1434. });
  1435. this.updateSelected();
  1436. this.resetView();
  1437. this.trigger('post-body');
  1438. };
  1439. BootstrapTable.prototype.initServer = function (silent, query) {
  1440. var that = this,
  1441. data = {},
  1442. params = {
  1443. pageSize: this.options.pageSize === this.options.formatAllRows() ?
  1444. this.options.totalRows : this.options.pageSize,
  1445. pageNumber: this.options.pageNumber,
  1446. searchText: this.searchText,
  1447. sortName: this.options.sortName,
  1448. sortOrder: this.options.sortOrder
  1449. },
  1450. request;
  1451. if (!this.options.url && !this.options.ajax) {
  1452. return;
  1453. }
  1454. if (this.options.queryParamsType === 'limit') {
  1455. params = {
  1456. search: params.searchText,
  1457. sort: params.sortName,
  1458. order: params.sortOrder
  1459. };
  1460. if (this.options.pagination) {
  1461. params.limit = this.options.pageSize === this.options.formatAllRows() ?
  1462. this.options.totalRows : this.options.pageSize;
  1463. params.offset = this.options.pageSize === this.options.formatAllRows() ?
  1464. 0 : this.options.pageSize * (this.options.pageNumber - 1);
  1465. }
  1466. }
  1467. if (!($.isEmptyObject(this.filterColumnsPartial))) {
  1468. params['filter'] = JSON.stringify(this.filterColumnsPartial, null);
  1469. }
  1470. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  1471. $.extend(data, query || {});
  1472. // false to stop request
  1473. if (data === false) {
  1474. return;
  1475. }
  1476. if (!silent) {
  1477. this.$tableLoading.show();
  1478. }
  1479. request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
  1480. type: this.options.method,
  1481. url: this.options.url,
  1482. data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
  1483. JSON.stringify(data) : data,
  1484. cache: this.options.cache,
  1485. contentType: this.options.contentType,
  1486. dataType: this.options.dataType,
  1487. success: function (res) {
  1488. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  1489. that.load(res);
  1490. that.trigger('load-success', res);
  1491. },
  1492. error: function (res) {
  1493. that.trigger('load-error', res.status, res);
  1494. },
  1495. complete: function () {
  1496. if (!silent) {
  1497. that.$tableLoading.hide();
  1498. }
  1499. }
  1500. });
  1501. if (this.options.ajax) {
  1502. calculateObjectValue(this, this.options.ajax, [request], null);
  1503. } else {
  1504. $.ajax(request);
  1505. }
  1506. };
  1507. BootstrapTable.prototype.initSearchText = function () {
  1508. if (this.options.search) {
  1509. if (this.options.searchText !== '') {
  1510. var $search = this.$toolbar.find('.search input');
  1511. $search.val(this.options.searchText);
  1512. this.onSearch({currentTarget: $search});
  1513. }
  1514. }
  1515. };
  1516. BootstrapTable.prototype.getCaret = function () {
  1517. var that = this;
  1518. $.each(this.$header.find('th'), function (i, th) {
  1519. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === that.options.sortName ? that.options.sortOrder : 'both');
  1520. });
  1521. };
  1522. BootstrapTable.prototype.updateSelected = function () {
  1523. var checkAll = this.$selectItem.filter(':enabled').length &&
  1524. this.$selectItem.filter(':enabled').length ===
  1525. this.$selectItem.filter(':enabled').filter(':checked').length;
  1526. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  1527. this.$selectItem.each(function () {
  1528. $(this).closest('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  1529. });
  1530. };
  1531. BootstrapTable.prototype.updateRows = function () {
  1532. var that = this;
  1533. this.$selectItem.each(function () {
  1534. that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
  1535. });
  1536. };
  1537. BootstrapTable.prototype.resetRows = function () {
  1538. var that = this;
  1539. $.each(this.data, function (i, row) {
  1540. that.$selectAll.prop('checked', false);
  1541. that.$selectItem.prop('checked', false);
  1542. if (that.header.stateField) {
  1543. row[that.header.stateField] = false;
  1544. }
  1545. });
  1546. };
  1547. BootstrapTable.prototype.trigger = function (name) {
  1548. var args = Array.prototype.slice.call(arguments, 1);
  1549. name += '.bs.table';
  1550. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  1551. this.$el.trigger($.Event(name), args);
  1552. this.options.onAll(name, args);
  1553. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  1554. };
  1555. BootstrapTable.prototype.resetHeader = function () {
  1556. // fix #61: the hidden table reset header bug.
  1557. // fix bug: get $el.css('width') error sometime (height = 500)
  1558. clearTimeout(this.timeoutId_);
  1559. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  1560. };
  1561. BootstrapTable.prototype.fitHeader = function () {
  1562. var that = this,
  1563. fixedBody,
  1564. scrollWidth,
  1565. focused,
  1566. focusedTemp;
  1567. if (that.$el.is(':hidden')) {
  1568. that.timeoutId_ = setTimeout($.proxy(that.fitHeader, that), 100);
  1569. return;
  1570. }
  1571. fixedBody = this.$tableBody.get(0);
  1572. scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
  1573. fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
  1574. getScrollBarWidth() : 0;
  1575. this.$el.css('margin-top', -this.$header.outerHeight());
  1576. focused = $(':focus');
  1577. if (focused.length > 0) {
  1578. var $th = focused.parents('th');
  1579. if ($th.length > 0) {
  1580. var dataField = $th.attr('data-field');
  1581. if (dataField !== undefined) {
  1582. var $headerTh = this.$header.find("[data-field='" + dataField + "']");
  1583. if ($headerTh.length > 0) {
  1584. $headerTh.find(":input").addClass("focus-temp");
  1585. }
  1586. }
  1587. }
  1588. }
  1589. this.$header_ = this.$header.clone(true, true);
  1590. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  1591. this.$tableHeader.css({
  1592. 'margin-right': scrollWidth
  1593. }).find('table').css('width', this.$el.outerWidth())
  1594. .html('').attr('class', this.$el.attr('class'))
  1595. .append(this.$header_);
  1596. focusedTemp = $('.focus-temp:visible:eq(0)');
  1597. if (focusedTemp.length > 0) {
  1598. focusedTemp.focus();
  1599. this.$header.find('.focus-temp').removeClass('focus-temp');
  1600. }
  1601. // fix bug: $.data() is not working as expected after $.append()
  1602. this.$header.find('th[data-field]').each(function (i) {
  1603. that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
  1604. });
  1605. var visibleFields = this.getVisibleFields();
  1606. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  1607. var $this = $(this),
  1608. index = i;
  1609. if (that.options.detailView && !that.options.cardView) {
  1610. if (i === 0) {
  1611. that.$header_.find('th.detail').find('.fht-cell').width($this.innerWidth());
  1612. }
  1613. index = i - 1;
  1614. }
  1615. that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]))
  1616. .find('.fht-cell').width($this.innerWidth());
  1617. });
  1618. // horizontal scroll event
  1619. // TODO: it's probably better improving the layout than binding to scroll event
  1620. this.$tableBody.off('scroll').on('scroll', function () {
  1621. that.$tableHeader.scrollLeft($(this).scrollLeft());
  1622. if (that.options.showFooter && !that.options.cardView) {
  1623. that.$tableFooter.scrollLeft($(this).scrollLeft());
  1624. }
  1625. });
  1626. that.trigger('post-header');
  1627. };
  1628. BootstrapTable.prototype.resetFooter = function () {
  1629. var that = this,
  1630. data = that.getData(),
  1631. html = [];
  1632. if (!this.options.showFooter || this.options.cardView) { //do nothing
  1633. return;
  1634. }
  1635. if (!this.options.cardView && this.options.detailView) {
  1636. html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
  1637. }
  1638. $.each(this.columns, function (i, column) {
  1639. var falign = '', // footer align style
  1640. style = '',
  1641. class_ = sprintf(' class="%s"', column['class']);
  1642. if (!column.visible) {
  1643. return;
  1644. }
  1645. if (that.options.cardView && (!column.cardVisible)) {
  1646. return;
  1647. }
  1648. falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  1649. style = sprintf('vertical-align: %s; ', column.valign);
  1650. html.push('<td', class_, sprintf(' style="%s"', falign + style), '>');
  1651. html.push('<div class="th-inner">');
  1652. html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  1653. html.push('</div>');
  1654. html.push('<div class="fht-cell"></div>');
  1655. html.push('</div>');
  1656. html.push('</td>');
  1657. });
  1658. this.$tableFooter.find('tr').html(html.join(''));
  1659. clearTimeout(this.timeoutFooter_);
  1660. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
  1661. this.$el.is(':hidden') ? 100 : 0);
  1662. };
  1663. BootstrapTable.prototype.fitFooter = function () {
  1664. var that = this,
  1665. $footerTd,
  1666. elWidth,
  1667. scrollWidth;
  1668. clearTimeout(this.timeoutFooter_);
  1669. if (this.$el.is(':hidden')) {
  1670. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  1671. return;
  1672. }
  1673. elWidth = this.$el.css('width');
  1674. scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
  1675. this.$tableFooter.css({
  1676. 'margin-right': scrollWidth
  1677. }).find('table').css('width', elWidth)
  1678. .attr('class', this.$el.attr('class'));
  1679. $footerTd = this.$tableFooter.find('td');
  1680. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  1681. var $this = $(this);
  1682. $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
  1683. });
  1684. };
  1685. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  1686. if (index === -1) {
  1687. return;
  1688. }
  1689. this.columns[index].visible = checked;
  1690. this.initHeader();
  1691. this.initSearch();
  1692. this.initPagination();
  1693. this.initBody();
  1694. if (this.options.showColumns) {
  1695. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  1696. if (needUpdate) {
  1697. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  1698. }
  1699. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  1700. $items.filter(':checked').prop('disabled', true);
  1701. }
  1702. }
  1703. };
  1704. BootstrapTable.prototype.toggleRow = function (index, isIdField, visible) {
  1705. if (index === -1) {
  1706. return;
  1707. }
  1708. $(this.$body[0]).children().filter(sprintf(isIdField ? '[data-uniqueid="%s"]' : '[data-index="%s"]', index))[visible ? 'show' : 'hide']();
  1709. };
  1710. BootstrapTable.prototype.getVisibleFields = function () {
  1711. var that = this,
  1712. visibleFields = [];
  1713. $.each(this.header.fields, function (j, field) {
  1714. var column = that.columns[getFieldIndex(that.columns, field)];
  1715. if (!column.visible) {
  1716. return;
  1717. }
  1718. visibleFields.push(field);
  1719. });
  1720. return visibleFields;
  1721. };
  1722. // PUBLIC FUNCTION DEFINITION
  1723. // =======================
  1724. BootstrapTable.prototype.resetView = function (params) {
  1725. var padding = 0;
  1726. if (params && params.height) {
  1727. this.options.height = params.height;
  1728. }
  1729. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  1730. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  1731. if (this.options.height) {
  1732. var toolbarHeight = getRealHeight(this.$toolbar),
  1733. paginationHeight = getRealHeight(this.$pagination),
  1734. height = this.options.height - toolbarHeight - paginationHeight;
  1735. this.$tableContainer.css('height', height + 'px');
  1736. }
  1737. if (this.options.cardView) {
  1738. // remove the element css
  1739. this.$el.css('margin-top', '0');
  1740. this.$tableContainer.css('padding-bottom', '0');
  1741. return;
  1742. }
  1743. if (this.options.showHeader && this.options.height) {
  1744. this.$tableHeader.show();
  1745. this.resetHeader();
  1746. padding += this.$header.outerHeight();
  1747. } else {
  1748. this.$tableHeader.hide();
  1749. this.trigger('post-header');
  1750. }
  1751. if (this.options.showFooter) {
  1752. this.resetFooter();
  1753. if (this.options.height) {
  1754. padding += this.$tableFooter.outerHeight() + 1;
  1755. }
  1756. }
  1757. // Assign the correct sortable arrow
  1758. this.getCaret();
  1759. this.$tableContainer.css('padding-bottom', padding + 'px');
  1760. this.trigger('reset-view');
  1761. };
  1762. BootstrapTable.prototype.getData = function (useCurrentPage) {
  1763. return (this.searchText || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) ?
  1764. (useCurrentPage ? this.data.slice(this.pageFrom - 1, this.pageTo) : this.data) :
  1765. (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo) : this.options.data);
  1766. };
  1767. BootstrapTable.prototype.load = function (data) {
  1768. var fixedScroll = false;
  1769. // #431: support pagination
  1770. if (this.options.sidePagination === 'server') {
  1771. this.options.totalRows = data.total;
  1772. fixedScroll = data.fixedScroll;
  1773. data = data[this.options.dataField];
  1774. } else if (!$.isArray(data)) { // support fixedScroll
  1775. fixedScroll = data.fixedScroll;
  1776. data = data.data;
  1777. }
  1778. this.initData(data);
  1779. this.initSearch();
  1780. this.initPagination();
  1781. this.initBody(fixedScroll);
  1782. };
  1783. BootstrapTable.prototype.append = function (data) {
  1784. this.initData(data, 'append');
  1785. this.initSearch();
  1786. this.initPagination();
  1787. this.initBody(true);
  1788. };
  1789. BootstrapTable.prototype.prepend = function (data) {
  1790. this.initData(data, 'prepend');
  1791. this.initSearch();
  1792. this.initPagination();
  1793. this.initBody(true);
  1794. };
  1795. BootstrapTable.prototype.remove = function (params) {
  1796. var len = this.options.data.length,
  1797. i, row;
  1798. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  1799. return;
  1800. }
  1801. for (i = len - 1; i >= 0; i--) {
  1802. row = this.options.data[i];
  1803. if (!row.hasOwnProperty(params.field)) {
  1804. continue;
  1805. }
  1806. if ($.inArray(row[params.field], params.values) !== -1) {
  1807. this.options.data.splice(i, 1);
  1808. }
  1809. }
  1810. if (len === this.options.data.length) {
  1811. return;
  1812. }
  1813. this.initSearch();
  1814. this.initPagination();
  1815. this.initBody(true);
  1816. };
  1817. BootstrapTable.prototype.removeAll = function () {
  1818. if (this.options.data.length > 0) {
  1819. this.options.data.splice(0, this.options.data.length);
  1820. this.initSearch();
  1821. this.initPagination();
  1822. this.initBody(true);
  1823. }
  1824. };
  1825. BootstrapTable.prototype.getRowByUniqueId = function (id) {
  1826. var uniqueId = this.options.uniqueId,
  1827. len = this.options.data.length,
  1828. dataRow = null,
  1829. i, row;
  1830. for (i = len - 1; i >= 0; i--) {
  1831. row = this.options.data[i];
  1832. if (!row.hasOwnProperty(uniqueId)) {
  1833. continue;
  1834. }
  1835. if (typeof row[uniqueId] === 'string') {
  1836. id = id.toString();
  1837. } else if (typeof row[uniqueId] === 'number') {
  1838. if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
  1839. id = parseInt(id);
  1840. } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
  1841. id = parseFloat(id);
  1842. }
  1843. }
  1844. if (row[uniqueId] === id) {
  1845. dataRow = row;
  1846. break;
  1847. }
  1848. }
  1849. return dataRow;
  1850. };
  1851. BootstrapTable.prototype.removeByUniqueId = function (id) {
  1852. var len = this.options.data.length,
  1853. row = this.getRowByUniqueId(id);
  1854. if (row) {
  1855. this.options.data.splice(this.options.data.indexOf(row), 1);
  1856. }
  1857. if (len === this.options.data.length) {
  1858. return;
  1859. }
  1860. this.initSearch();
  1861. this.initPagination();
  1862. this.initBody(true);
  1863. };
  1864. BootstrapTable.prototype.insertRow = function (params) {
  1865. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1866. return;
  1867. }
  1868. this.data.splice(params.index, 0, params.row);
  1869. this.initSearch();
  1870. this.initPagination();
  1871. this.initSort();
  1872. this.initBody(true);
  1873. };
  1874. BootstrapTable.prototype.updateRow = function (params) {
  1875. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1876. return;
  1877. }
  1878. $.extend(this.data[params.index], params.row);
  1879. this.initSort();
  1880. this.initBody(true);
  1881. };
  1882. BootstrapTable.prototype.showRow = function (params) {
  1883. if (!params.hasOwnProperty('index')) {
  1884. return;
  1885. }
  1886. this.toggleRow(params.index, params.isIdField === undefined ? false : true, true);
  1887. };
  1888. BootstrapTable.prototype.hideRow = function (params) {
  1889. if (!params.hasOwnProperty('index')) {
  1890. return;
  1891. }
  1892. this.toggleRow(params.index, params.isIdField === undefined ? false : true, false);
  1893. };
  1894. BootstrapTable.prototype.getRowsHidden = function (show) {
  1895. var rows = $(this.$body[0]).children().filter(':hidden'),
  1896. i = 0;
  1897. if (show) {
  1898. for (; i < rows.length; i++) {
  1899. $(rows[i]).show();
  1900. }
  1901. }
  1902. return rows;
  1903. };
  1904. BootstrapTable.prototype.mergeCells = function (options) {
  1905. var row = options.index,
  1906. col = $.inArray(options.field, this.getVisibleFields()),
  1907. rowspan = options.rowspan || 1,
  1908. colspan = options.colspan || 1,
  1909. i, j,
  1910. $tr = this.$body.find('tr'),
  1911. $td;
  1912. if (this.options.detailView && !this.options.cardView) {
  1913. col += 1;
  1914. }
  1915. $td = $tr.eq(row).find('td').eq(col);
  1916. if (row < 0 || col < 0 || row >= this.data.length) {
  1917. return;
  1918. }
  1919. for (i = row; i < row + rowspan; i++) {
  1920. for (j = col; j < col + colspan; j++) {
  1921. $tr.eq(i).find('td').eq(j).hide();
  1922. }
  1923. }
  1924. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  1925. };
  1926. BootstrapTable.prototype.updateCell = function (params) {
  1927. if (!params.hasOwnProperty('rowIndex') || !params.hasOwnProperty('fieldName') || !params.hasOwnProperty('fieldValue')) {
  1928. return;
  1929. }
  1930. this.data[params.rowIndex][params.fieldName] = params.fieldValue;
  1931. this.initSort();
  1932. this.initBody(true);
  1933. };
  1934. BootstrapTable.prototype.getOptions = function () {
  1935. return this.options;
  1936. };
  1937. BootstrapTable.prototype.getSelections = function () {
  1938. var that = this;
  1939. return $.grep(this.data, function (row) {
  1940. return row[that.header.stateField];
  1941. });
  1942. };
  1943. BootstrapTable.prototype.getAllSelections = function () {
  1944. var that = this;
  1945. return $.grep(this.options.data, function (row) {
  1946. return row[that.header.stateField];
  1947. });
  1948. };
  1949. BootstrapTable.prototype.checkAll = function () {
  1950. this.checkAll_(true);
  1951. };
  1952. BootstrapTable.prototype.uncheckAll = function () {
  1953. this.checkAll_(false);
  1954. };
  1955. BootstrapTable.prototype.checkAll_ = function (checked) {
  1956. var rows;
  1957. if (!checked) {
  1958. rows = this.getSelections();
  1959. }
  1960. this.$selectAll.add(this.$selectAll_).prop('checked', checked);
  1961. this.$selectItem.filter(':enabled').prop('checked', checked);
  1962. this.updateRows();
  1963. if (checked) {
  1964. rows = this.getSelections();
  1965. }
  1966. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  1967. };
  1968. BootstrapTable.prototype.check = function (index) {
  1969. this.check_(true, index);
  1970. };
  1971. BootstrapTable.prototype.uncheck = function (index) {
  1972. this.check_(false, index);
  1973. };
  1974. BootstrapTable.prototype.check_ = function (checked, index) {
  1975. this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1976. this.data[index][this.header.stateField] = checked;
  1977. this.updateSelected();
  1978. this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
  1979. };
  1980. BootstrapTable.prototype.checkBy = function (obj) {
  1981. this.checkBy_(true, obj);
  1982. };
  1983. BootstrapTable.prototype.uncheckBy = function (obj) {
  1984. this.checkBy_(false, obj);
  1985. };
  1986. BootstrapTable.prototype.checkBy_ = function (checked, obj) {
  1987. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  1988. return;
  1989. }
  1990. var that = this,
  1991. rows = [];
  1992. $.each(this.options.data, function (index, row) {
  1993. if (!row.hasOwnProperty(obj.field)) {
  1994. return false;
  1995. }
  1996. if ($.inArray(row[obj.field], obj.values) !== -1) {
  1997. that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1998. row[that.header.stateField] = checked;
  1999. rows.push(row);
  2000. that.trigger(checked ? 'check' : 'uncheck', row);
  2001. }
  2002. });
  2003. this.updateSelected();
  2004. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  2005. };
  2006. BootstrapTable.prototype.destroy = function () {
  2007. this.$el.insertBefore(this.$container);
  2008. $(this.options.toolbar).insertBefore(this.$el);
  2009. this.$container.next().remove();
  2010. this.$container.remove();
  2011. this.$el.html(this.$el_.html())
  2012. .css('margin-top', '0')
  2013. .attr('class', this.$el_.attr('class') || ''); // reset the class
  2014. };
  2015. BootstrapTable.prototype.showLoading = function () {
  2016. this.$tableLoading.show();
  2017. };
  2018. BootstrapTable.prototype.hideLoading = function () {
  2019. this.$tableLoading.hide();
  2020. };
  2021. BootstrapTable.prototype.togglePagination = function () {
  2022. this.options.pagination = !this.options.pagination;
  2023. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  2024. if (this.options.pagination) {
  2025. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
  2026. } else {
  2027. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
  2028. }
  2029. this.updatePagination();
  2030. };
  2031. BootstrapTable.prototype.refresh = function (params) {
  2032. if (params && params.url) {
  2033. this.options.url = params.url;
  2034. this.options.pageNumber = 1;
  2035. }
  2036. this.initServer(params && params.silent, params && params.query);
  2037. };
  2038. BootstrapTable.prototype.resetWidth = function () {
  2039. if (this.options.showHeader && this.options.height) {
  2040. this.fitHeader();
  2041. }
  2042. if (this.options.showFooter) {
  2043. this.fitFooter();
  2044. }
  2045. };
  2046. BootstrapTable.prototype.showColumn = function (field) {
  2047. this.toggleColumn(getFieldIndex(this.columns, field), true, true);
  2048. };
  2049. BootstrapTable.prototype.hideColumn = function (field) {
  2050. this.toggleColumn(getFieldIndex(this.columns, field), false, true);
  2051. };
  2052. BootstrapTable.prototype.getHiddenColumns = function () {
  2053. return $.grep(this.columns, function (column) {
  2054. return !column.visible;
  2055. });
  2056. };
  2057. BootstrapTable.prototype.filterBy = function (columns) {
  2058. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  2059. this.options.pageNumber = 1;
  2060. this.initSearch();
  2061. this.updatePagination();
  2062. };
  2063. BootstrapTable.prototype.scrollTo = function (value) {
  2064. if (typeof value === 'string') {
  2065. value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
  2066. }
  2067. if (typeof value === 'number') {
  2068. this.$tableBody.scrollTop(value);
  2069. }
  2070. if (typeof value === 'undefined') {
  2071. return this.$tableBody.scrollTop();
  2072. }
  2073. };
  2074. BootstrapTable.prototype.getScrollPosition = function () {
  2075. return this.scrollTo();
  2076. };
  2077. BootstrapTable.prototype.selectPage = function (page) {
  2078. if (page > 0 && page <= this.options.totalPages) {
  2079. this.options.pageNumber = page;
  2080. this.updatePagination();
  2081. }
  2082. };
  2083. BootstrapTable.prototype.prevPage = function () {
  2084. if (this.options.pageNumber > 1) {
  2085. this.options.pageNumber--;
  2086. this.updatePagination();
  2087. }
  2088. };
  2089. BootstrapTable.prototype.nextPage = function () {
  2090. if (this.options.pageNumber < this.options.totalPages) {
  2091. this.options.pageNumber++;
  2092. this.updatePagination();
  2093. }
  2094. };
  2095. BootstrapTable.prototype.toggleView = function () {
  2096. this.options.cardView = !this.options.cardView;
  2097. this.initHeader();
  2098. // Fixed remove toolbar when click cardView button.
  2099. //that.initToolbar();
  2100. this.initBody();
  2101. this.trigger('toggle', this.options.cardView);
  2102. };
  2103. BootstrapTable.prototype.refreshOptions = function (options) {
  2104. //If the objects are equivalent then avoid the call of destroy / init methods
  2105. if (compareObjects(this.options, options, false)) {
  2106. return;
  2107. }
  2108. this.options = $.extend(this.options, options);
  2109. this.trigger('refresh-options', this.options);
  2110. this.destroy();
  2111. this.init();
  2112. };
  2113. BootstrapTable.prototype.resetSearch = function (text) {
  2114. var $search = this.$toolbar.find('.search input');
  2115. $search.val(text || '');
  2116. this.onSearch({currentTarget: $search});
  2117. };
  2118. BootstrapTable.prototype.expandRow_ = function (expand, index) {
  2119. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
  2120. if ($tr.next().is('tr.detail-view') === (expand ? false : true)) {
  2121. $tr.find('> td > .detail-icon').click();
  2122. }
  2123. };
  2124. BootstrapTable.prototype.expandRow = function (index) {
  2125. this.expandRow_(true, index);
  2126. };
  2127. BootstrapTable.prototype.collapseRow = function (index) {
  2128. this.expandRow_(false, index);
  2129. };
  2130. BootstrapTable.prototype.expandAllRows = function (isSubTable) {
  2131. if (isSubTable) {
  2132. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', 0)),
  2133. that = this,
  2134. detailIcon = null,
  2135. executeInterval = false,
  2136. idInterval = -1;
  2137. if (!$tr.next().is('tr.detail-view')) {
  2138. $tr.find('> td > .detail-icon').click();
  2139. executeInterval = true;
  2140. } else if (!$tr.next().next().is('tr.detail-view')) {
  2141. $tr.next().find(".detail-icon").click();
  2142. executeInterval = true;
  2143. }
  2144. if (executeInterval) {
  2145. try {
  2146. idInterval = setInterval(function () {
  2147. detailIcon = that.$body.find("tr.detail-view").last().find(".detail-icon");
  2148. if (detailIcon.length > 0) {
  2149. detailIcon.click();
  2150. } else {
  2151. clearInterval(idInterval);
  2152. }
  2153. }, 1);
  2154. } catch (ex) {
  2155. clearInterval(idInterval);
  2156. }
  2157. }
  2158. } else {
  2159. var trs = this.$body.children();
  2160. for (var i = 0; i < trs.length; i++) {
  2161. this.expandRow_(true, $(trs[i]).data("index"));
  2162. }
  2163. }
  2164. };
  2165. BootstrapTable.prototype.collapseAllRows = function (isSubTable) {
  2166. if (isSubTable) {
  2167. this.expandRow_(false, 0);
  2168. } else {
  2169. var trs = this.$body.children();
  2170. for (var i = 0; i < trs.length; i++) {
  2171. this.expandRow_(false, $(trs[i]).data("index"));
  2172. }
  2173. }
  2174. };
  2175. // BOOTSTRAP TABLE PLUGIN DEFINITION
  2176. // =======================
  2177. var allowedMethods = [
  2178. 'getOptions',
  2179. 'getSelections', 'getAllSelections', 'getData',
  2180. 'load', 'append', 'prepend', 'remove', 'removeAll',
  2181. 'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
  2182. 'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
  2183. 'mergeCells',
  2184. 'checkAll', 'uncheckAll',
  2185. 'check', 'uncheck',
  2186. 'checkBy', 'uncheckBy',
  2187. 'refresh',
  2188. 'resetView',
  2189. 'resetWidth',
  2190. 'destroy',
  2191. 'showLoading', 'hideLoading',
  2192. 'showColumn', 'hideColumn', 'getHiddenColumns',
  2193. 'filterBy',
  2194. 'scrollTo',
  2195. 'getScrollPosition',
  2196. 'selectPage', 'prevPage', 'nextPage',
  2197. 'togglePagination',
  2198. 'toggleView',
  2199. 'refreshOptions',
  2200. 'resetSearch',
  2201. 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows'
  2202. ];
  2203. $.fn.bootstrapTable = function (option) {
  2204. var value,
  2205. args = Array.prototype.slice.call(arguments, 1);
  2206. this.each(function () {
  2207. var $this = $(this),
  2208. data = $this.data('bootstrap.table'),
  2209. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  2210. typeof option === 'object' && option);
  2211. if (typeof option === 'string') {
  2212. if ($.inArray(option, allowedMethods) < 0) {
  2213. throw new Error("Unknown method: " + option);
  2214. }
  2215. if (!data) {
  2216. return;
  2217. }
  2218. value = data[option].apply(data, args);
  2219. if (option === 'destroy') {
  2220. $this.removeData('bootstrap.table');
  2221. }
  2222. }
  2223. if (!data) {
  2224. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  2225. }
  2226. });
  2227. return typeof value === 'undefined' ? this : value;
  2228. };
  2229. $.fn.bootstrapTable.Constructor = BootstrapTable;
  2230. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  2231. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  2232. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  2233. $.fn.bootstrapTable.methods = allowedMethods;
  2234. $.fn.bootstrapTable.utils = {
  2235. sprintf: sprintf,
  2236. getFieldIndex: getFieldIndex,
  2237. compareObjects: compareObjects,
  2238. calculateObjectValue: calculateObjectValue
  2239. };
  2240. // BOOTSTRAP TABLE INIT
  2241. // =======================
  2242. $(function () {
  2243. $('[data-toggle="table"]').bootstrapTable();
  2244. });
  2245. }(jQuery);