bootstrap-table.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * version: 1.3.0
  4. * https://github.com/wenzhixin/bootstrap-table/
  5. */
  6. !function ($) {
  7. 'use strict';
  8. // TOOLS DEFINITION
  9. // ======================
  10. // it only does '%s', and return '' when arguments are undefined
  11. var sprintf = function(str) {
  12. var args = arguments,
  13. flag = true,
  14. i = 1;
  15. str = str.replace(/%s/g, function () {
  16. var arg = args[i++];
  17. if (typeof arg === 'undefined') {
  18. flag = false;
  19. return '';
  20. }
  21. return arg;
  22. });
  23. if (flag) {
  24. return str;
  25. }
  26. return '';
  27. };
  28. var getPropertyFromOther = function (list, from, to, value) {
  29. var result = '';
  30. $.each(list, function (i, item) {
  31. if (item[from] === value) {
  32. result = item[to];
  33. return false;
  34. }
  35. return true;
  36. });
  37. return result;
  38. };
  39. var getFieldIndex = function (columns, field) {
  40. var index = -1;
  41. $.each(columns, function (i, column) {
  42. if (column.field === field) {
  43. index = i;
  44. return false;
  45. }
  46. return true;
  47. });
  48. return index;
  49. };
  50. var getScrollBarWidth = function () {
  51. var inner = $('<p/>').addClass('fixed-table-scroll-inner'),
  52. outer = $('<div/>').addClass('fixed-table-scroll-outer'),
  53. w1, w2;
  54. outer.append(inner);
  55. $('body').append(outer);
  56. w1 = inner[0].offsetWidth;
  57. outer.css('overflow', 'scroll');
  58. w2 = inner[0].offsetWidth;
  59. if (w1 == w2) {
  60. w2 = outer[0].clientWidth;
  61. }
  62. outer.remove();
  63. return w1 - w2;
  64. };
  65. var calculateObjectValue = function (self, name, args, defaultValue) {
  66. if (typeof name === 'string') {
  67. // support obj.func1.func2
  68. var names = name.split('.');
  69. if (names.length > 1) {
  70. name = window;
  71. $.each(names, function (i, f) {
  72. name = name[f];
  73. });
  74. } else {
  75. name = window[name];
  76. }
  77. }
  78. if (typeof name === 'object') {
  79. return name;
  80. }
  81. if (typeof name === 'function') {
  82. return name.apply(self, args);
  83. }
  84. return defaultValue;
  85. };
  86. // BOOTSTRAP TABLE CLASS DEFINITION
  87. // ======================
  88. var BootstrapTable = function (el, options) {
  89. this.options = options;
  90. this.$el = $(el);
  91. this.$el_ = this.$el.clone();
  92. this.timeoutId_ = 0;
  93. this.init();
  94. };
  95. BootstrapTable.DEFAULTS = {
  96. classes: 'table table-hover',
  97. height: undefined,
  98. undefinedText: '-',
  99. sortName: undefined,
  100. sortOrder: 'asc',
  101. striped: false,
  102. columns: [],
  103. data: [],
  104. method: 'get',
  105. url: undefined,
  106. cache: true,
  107. contentType: 'application/json',
  108. queryParams: function (params) {return params;},
  109. queryParamsType: 'limit', // undefined
  110. responseHandler: function (res) {return res;},
  111. pagination: false,
  112. sidePagination: 'client', // client or server
  113. totalRows: 0, // server side need to set
  114. pageNumber: 1,
  115. pageSize: 10,
  116. pageList: [10, 25, 50, 100],
  117. search: false,
  118. selectItemName: 'btSelectItem',
  119. showHeader: true,
  120. showColumns: false,
  121. showRefresh: false,
  122. showToggle: false,
  123. minimumCountColumns: 1,
  124. idField: undefined,
  125. cardView: false,
  126. clickToSelect: false,
  127. singleSelect: false,
  128. toolbar: undefined,
  129. checkboxHeader: true,
  130. sortable: true,
  131. maintainSelected: false,
  132. rowStyle: function (row, index) {return {};},
  133. formatLoadingMessage: function () {
  134. return 'Loading, please wait…';
  135. },
  136. formatRecordsPerPage: function (pageNumber) {
  137. return sprintf('%s records per page', pageNumber);
  138. },
  139. formatShowingRows: function (pageFrom, pageTo, totalRows) {
  140. return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
  141. },
  142. formatSearch: function () {
  143. return 'Search';
  144. },
  145. formatNoMatches: function () {
  146. return 'No matching records found';
  147. },
  148. formatRefresh: function () {
  149. return 'Refresh';
  150. },
  151. formatToggle: function () {
  152. return 'Toggle';
  153. },
  154. formatColumns: function () {
  155. return 'Columns';
  156. },
  157. onAll: function (name, args) {return false;},
  158. onClickRow: function (item, $element) {return false;},
  159. onDblClickRow: function (item, $element) {return false;},
  160. onSort: function (name, order) {return false;},
  161. onCheck: function (row) {return false;},
  162. onUncheck: function (row) {return false;},
  163. onCheckAll: function () {return false;},
  164. onUncheckAll: function () {return false;},
  165. onLoadSuccess: function (data) {return false;},
  166. onLoadError: function (status) {return false;},
  167. onColumnSwitch: function (field, checked) {return false;}
  168. };
  169. BootstrapTable.COLUMN_DEFAULTS = {
  170. radio: false,
  171. checkbox: false,
  172. checkboxEnabled: true,
  173. field: undefined,
  174. title: undefined,
  175. 'class': undefined,
  176. align: undefined, // left, right, center
  177. halign: undefined, // left, right, center
  178. valign: undefined, // top, middle, bottom
  179. width: undefined,
  180. sortable: false,
  181. order: 'asc', // asc, desc
  182. visible: true,
  183. switchable: true,
  184. clickToSelect: true,
  185. formatter: undefined,
  186. events: undefined,
  187. sorter: undefined,
  188. cellStyle: undefined
  189. };
  190. BootstrapTable.EVENTS = {
  191. 'all.bs.table': 'onAll',
  192. 'click-row.bs.table': 'onClickRow',
  193. 'dbl-click-row.bs.table': 'onDblClickRow',
  194. 'sort.bs.table': 'onSort',
  195. 'check.bs.table': 'onCheck',
  196. 'uncheck.bs.table': 'onUncheck',
  197. 'check-all.bs.table': 'onCheckAll',
  198. 'uncheck-all.bs.table': 'onUncheckAll',
  199. 'load-success.bs.table': 'onLoadSuccess',
  200. 'load-error.bs.table': 'onLoadError',
  201. 'column-switch.bs.table': 'onColumnSwitch'
  202. };
  203. BootstrapTable.prototype.init = function () {
  204. this.initContainer();
  205. this.initTable();
  206. this.initHeader();
  207. this.initData();
  208. this.initToolbar();
  209. this.initPagination();
  210. this.initBody();
  211. this.initServer();
  212. };
  213. BootstrapTable.prototype.initContainer = function () {
  214. this.$container = $([
  215. '<div class="bootstrap-table">',
  216. '<div class="fixed-table-toolbar"></div>',
  217. '<div class="fixed-table-container">',
  218. '<div class="fixed-table-header"><table></table></div>',
  219. '<div class="fixed-table-body">',
  220. '<div class="fixed-table-loading">',
  221. this.options.formatLoadingMessage(),
  222. '</div>',
  223. '</div>',
  224. '<div class="fixed-table-pagination"></div>',
  225. '</div>',
  226. '</div>'].join(''));
  227. this.$container.insertAfter(this.$el);
  228. this.$container.find('.fixed-table-body').append(this.$el);
  229. this.$container.after('<div class="clearfix"></div>');
  230. this.$loading = this.$container.find('.fixed-table-loading');
  231. this.$el.addClass(this.options.classes);
  232. if (this.options.striped) {
  233. this.$el.addClass('table-striped');
  234. }
  235. };
  236. BootstrapTable.prototype.initTable = function () {
  237. var that = this,
  238. columns = [],
  239. data = [];
  240. this.$header = this.$el.find('thead');
  241. if (!this.$header.length) {
  242. this.$header = $('<thead></thead>').appendTo(this.$el);
  243. }
  244. if (!this.$header.find('tr').length) {
  245. this.$header.append('<tr></tr>');
  246. }
  247. this.$header.find('th').each(function () {
  248. var column = $.extend({}, {
  249. title: $(this).html(),
  250. 'class': $(this).attr('class')
  251. }, $(this).data());
  252. columns.push(column);
  253. });
  254. this.options.columns = $.extend([], columns, this.options.columns);
  255. $.each(this.options.columns, function (i, column) {
  256. that.options.columns[i] = $.extend({}, BootstrapTable.COLUMN_DEFAULTS,
  257. {field: i}, column); // when field is undefined, use index instead
  258. });
  259. // if options.data is setting, do not process tbody data
  260. if (this.options.data.length) {
  261. return;
  262. }
  263. this.$el.find('tbody tr').each(function () {
  264. var row = {};
  265. $(this).find('td').each(function (i) {
  266. row[that.options.columns[i].field] = $(this).html();
  267. });
  268. data.push(row);
  269. });
  270. this.options.data = data;
  271. };
  272. BootstrapTable.prototype.initHeader = function () {
  273. var that = this,
  274. visibleColumns = [],
  275. html = [];
  276. this.header = {
  277. fields: [],
  278. styles: [],
  279. classes: [],
  280. formatters: [],
  281. events: [],
  282. sorters: [],
  283. cellStyles: [],
  284. clickToSelects: []
  285. };
  286. $.each(this.options.columns, function (i, column) {
  287. var text = '',
  288. style = '',
  289. class_ = sprintf(' class="%s"', column['class']),
  290. order = that.options.sortOrder || column.order;
  291. if (!column.visible) {
  292. return;
  293. }
  294. style = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  295. style += sprintf('vertical-align: %s; ', column.valign);
  296. style += sprintf('width: %spx; ', column.checkbox || column.radio ? 36 : column.width);
  297. visibleColumns.push(column);
  298. that.header.fields.push(column.field);
  299. that.header.styles.push(style);
  300. that.header.classes.push(class_);
  301. that.header.formatters.push(column.formatter);
  302. that.header.events.push(column.events);
  303. that.header.sorters.push(column.sorter);
  304. that.header.cellStyles.push(column.cellStyle);
  305. that.header.clickToSelects.push(column.clickToSelect);
  306. html.push('<th',
  307. column.checkbox || column.radio ?
  308. sprintf(' class="bs-checkbox %s"', column['class'] || '') :
  309. class_,
  310. sprintf(' style="%s"', style),
  311. '>');
  312. html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
  313. 'sortable' : ''));
  314. text = column.title;
  315. if (that.options.sortName === column.field && that.options.sortable && column.sortable) {
  316. text += that.getCaretHtml();
  317. }
  318. if (column.checkbox) {
  319. if (!that.options.singleSelect && that.options.checkboxHeader) {
  320. text = '<input name="btSelectAll" type="checkbox" />';
  321. }
  322. that.header.stateField = column.field;
  323. }
  324. if (column.radio) {
  325. text = '';
  326. that.header.stateField = column.field;
  327. that.options.singleSelect = true;
  328. }
  329. html.push(text);
  330. html.push('</div>');
  331. html.push('<div class="fht-cell"></div>');
  332. html.push('</th>');
  333. });
  334. this.$header.find('tr').html(html.join(''));
  335. this.$header.find('th').each(function (i) {
  336. $(this).data(visibleColumns[i]);
  337. });
  338. this.$container.off('click', 'th').on('click', 'th', function (event) {
  339. if (that.options.sortable && $(this).data().sortable) {
  340. that.onSort(event);
  341. }
  342. });
  343. if (!this.options.showHeader || this.options.cardView) {
  344. this.$header.hide();
  345. this.$container.find('.fixed-table-header').hide();
  346. this.$loading.css('top', 0);
  347. } else {
  348. this.$header.show();
  349. this.$container.find('.fixed-table-header').show();
  350. this.$loading.css('top', '37px');
  351. }
  352. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  353. this.$container.off('click', '[name="btSelectAll"]')
  354. .on('click', '[name="btSelectAll"]', function () {
  355. var checked = $(this).prop('checked');
  356. that[checked ? 'checkAll' : 'uncheckAll']();
  357. });
  358. };
  359. BootstrapTable.prototype.initData = function (data, append) {
  360. if (append) {
  361. this.data = this.data.concat(data);
  362. } else {
  363. this.data = data || this.options.data;
  364. }
  365. this.options.data = this.data;
  366. if (this.options.sidePagination === 'server') {
  367. return;
  368. }
  369. this.initSort();
  370. };
  371. BootstrapTable.prototype.initSort = function () {
  372. var that = this,
  373. name = this.options.sortName,
  374. order = this.options.sortOrder === 'desc' ? -1 : 1,
  375. index = $.inArray(this.options.sortName, this.header.fields);
  376. if (index !== -1) {
  377. this.data.sort(function (a, b) {
  378. var aa = a[name],
  379. bb = b[name],
  380. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
  381. if (value !== undefined) {
  382. return order * value;
  383. }
  384. // Fix #161: undefined or null string sort bug.
  385. if (aa === null) {
  386. aa = '';
  387. }
  388. if (bb === null) {
  389. bb = '';
  390. }
  391. if (aa === bb) {
  392. return 0;
  393. }
  394. if (aa < bb) {
  395. return order * -1;
  396. }
  397. return order;
  398. });
  399. }
  400. };
  401. BootstrapTable.prototype.onSort = function (event) {
  402. var $this = $(event.currentTarget),
  403. $this_ = this.$header.find('th').eq($this.index());
  404. this.$header.add(this.$header_).find('span.order').remove();
  405. if (this.options.sortName === $this.data('field')) {
  406. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  407. } else {
  408. this.options.sortName = $this.data('field');
  409. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  410. }
  411. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  412. $this.add($this_).data('order', this.options.sortOrder)
  413. .find('.th-inner').append(this.getCaretHtml());
  414. if (this.options.sidePagination === 'server') {
  415. this.initServer();
  416. return;
  417. }
  418. this.initSort();
  419. this.initBody();
  420. };
  421. BootstrapTable.prototype.initToolbar = function () {
  422. var that = this,
  423. html = [],
  424. timeoutId = 0,
  425. $keepOpen,
  426. $search,
  427. switchableCount = 0;
  428. this.$toolbar = this.$container.find('.fixed-table-toolbar').html('');
  429. if (typeof this.options.toolbar === 'string') {
  430. $('<div class="bars pull-left"></div>')
  431. .appendTo(this.$toolbar)
  432. .append($(this.options.toolbar));
  433. }
  434. // showColumns, showToggle, showRefresh
  435. html = ['<div class="columns btn-group pull-right">'];
  436. if (this.options.showRefresh) {
  437. html.push(sprintf('<button class="btn btn-default" type="button" name="refresh" title="%s">',
  438. this.options.formatRefresh()),
  439. '<i class="glyphicon glyphicon-refresh icon-refresh"></i>',
  440. '</button>');
  441. }
  442. if (this.options.showToggle) {
  443. html.push(sprintf('<button class="btn btn-default" type="button" name="toggle" title="%s">',
  444. this.options.formatToggle()),
  445. '<i class="glyphicon glyphicon glyphicon-list-alt icon-list-alt"></i>',
  446. '</button>');
  447. }
  448. if (this.options.showColumns) {
  449. html.push(sprintf('<div class="keep-open %s" title="%s">',
  450. this.options.showRefresh || this.options.showToggle ? 'btn-group' : '',
  451. this.options.formatColumns()),
  452. '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">',
  453. '<i class="glyphicon glyphicon-th icon-th"></i>',
  454. ' <span class="caret"></span>',
  455. '</button>',
  456. '<ul class="dropdown-menu" role="menu">');
  457. $.each(this.options.columns, function (i, column) {
  458. if (column.radio || column.checkbox) {
  459. return;
  460. }
  461. var checked = column.visible ? ' checked="checked"' : '';
  462. if (column.switchable) {
  463. html.push(sprintf('<li>' +
  464. '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
  465. '</li>', column.field, i, checked, column.title));
  466. switchableCount++;
  467. }
  468. });
  469. html.push('</ul>',
  470. '</div>');
  471. }
  472. html.push('</div>');
  473. if (html.length > 2) {
  474. this.$toolbar.append(html.join(''));
  475. }
  476. if (this.options.showRefresh) {
  477. this.$toolbar.find('button[name="refresh"]')
  478. .off('click').on('click', $.proxy(this.refresh, this));
  479. }
  480. if (this.options.showToggle) {
  481. this.$toolbar.find('button[name="toggle"]')
  482. .off('click').on('click', function () {
  483. that.options.cardView = !that.options.cardView;
  484. that.initHeader();
  485. that.initBody();
  486. });
  487. }
  488. if (this.options.showColumns) {
  489. $keepOpen = this.$toolbar.find('.keep-open');
  490. if (switchableCount <= this.options.minimumCountColumns) {
  491. $keepOpen.find('input').prop('disabled', true);
  492. }
  493. $keepOpen.find('li').off('click').on('click', function (event) {
  494. event.stopImmediatePropagation();
  495. });
  496. $keepOpen.find('input').off('click').on('click', function () {
  497. var $this = $(this);
  498. that.toggleColumn($this.val(), $this.prop('checked'), false);
  499. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  500. });
  501. }
  502. if (this.options.search) {
  503. html = [];
  504. html.push(
  505. '<div class="pull-right search">',
  506. sprintf('<input class="form-control" type="text" placeholder="%s">',
  507. this.options.formatSearch()),
  508. '</div>');
  509. this.$toolbar.append(html.join(''));
  510. $search = this.$toolbar.find('.search input');
  511. $search.off('keyup').on('keyup', function (event) {
  512. clearTimeout(timeoutId); // doesn't matter if it's 0
  513. timeoutId = setTimeout(function () {
  514. that.onSearch(event);
  515. }, 500); // 500ms
  516. });
  517. }
  518. };
  519. BootstrapTable.prototype.onSearch = function (event) {
  520. var text = $.trim($(event.currentTarget).val());
  521. // trim search input
  522. $(event.currentTarget).val(text);
  523. if (text === this.searchText) {
  524. return;
  525. }
  526. this.searchText = text;
  527. this.options.pageNumber = 1;
  528. this.initSearch();
  529. this.updatePagination();
  530. };
  531. BootstrapTable.prototype.initSearch = function () {
  532. var that = this;
  533. if (this.options.sidePagination !== 'server') {
  534. var s = this.searchText && this.searchText.toLowerCase();
  535. this.data = s ? $.grep(this.options.data, function (item, i) {
  536. key = $.isNumeric(key) ? parseInt(key, 10) : key;
  537. for (var key in item) {
  538. var value = item[key];
  539. // Fix #142: search use formated data
  540. value = calculateObjectValue(that.header,
  541. that.header.formatters[$.inArray(key, that.header.fields)],
  542. [value, item, i], value);
  543. if ($.inArray(key, that.header.fields) !== -1 &&
  544. (typeof value === 'string' ||
  545. typeof value === 'number') &&
  546. (value + '').toLowerCase().indexOf(s) !== -1) {
  547. return true;
  548. }
  549. }
  550. return false;
  551. }) : this.options.data;
  552. }
  553. };
  554. BootstrapTable.prototype.initPagination = function () {
  555. this.$pagination = this.$container.find('.fixed-table-pagination');
  556. if (!this.options.pagination) {
  557. return;
  558. }
  559. var that = this,
  560. html = [],
  561. i, from, to,
  562. $pageList,
  563. $first, $pre,
  564. $next, $last,
  565. $number,
  566. data = this.searchText ? this.data : this.options.data;
  567. if (this.options.sidePagination !== 'server') {
  568. this.options.totalRows = data.length;
  569. }
  570. this.totalPages = 0;
  571. if (this.options.totalRows) {
  572. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  573. }
  574. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  575. this.options.pageNumber = this.totalPages;
  576. }
  577. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  578. this.pageTo = this.options.pageNumber * this.options.pageSize;
  579. if (this.pageTo > this.options.totalRows) {
  580. this.pageTo = this.options.totalRows;
  581. }
  582. html.push(
  583. '<div class="pull-left pagination-detail">',
  584. '<span class="pagination-info">',
  585. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  586. '</span>');
  587. html.push('<span class="page-list">');
  588. var pageNumber = [
  589. '<span class="btn-group dropup">',
  590. '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">',
  591. '<span class="page-size">',
  592. this.options.pageSize,
  593. '</span>',
  594. ' <span class="caret"></span>',
  595. '</button>',
  596. '<ul class="dropdown-menu" role="menu">'],
  597. pageList = this.options.pageList;
  598. if (typeof this.options.pageList === 'string') {
  599. var list = this.options.pageList.slice(1, -1).replace(/ /g, '').split(',');
  600. pageList = [];
  601. $.each(list, function (i, value) {
  602. pageList.push(+value);
  603. });
  604. }
  605. $.each(pageList, function (i, page) {
  606. var active = page === that.options.pageSize ? ' class="active"' : '';
  607. pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
  608. });
  609. pageNumber.push('</ul></span>');
  610. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  611. html.push('</span>');
  612. html.push('</div>',
  613. '<div class="pull-right pagination">',
  614. '<ul class="pagination">',
  615. '<li class="page-first"><a href="javascript:void(0)">&lt;&lt;</a></li>',
  616. '<li class="page-pre"><a href="javascript:void(0)">&lt;</a></li>');
  617. if (this.totalPages < 5) {
  618. from = 1;
  619. to = this.totalPages;
  620. } else {
  621. from = this.options.pageNumber - 2;
  622. to = from + 4;
  623. if (from < 1) {
  624. from = 1;
  625. to = 5;
  626. }
  627. if (to > this.totalPages) {
  628. to = this.totalPages;
  629. from = to - 4;
  630. }
  631. }
  632. for (i = from; i <= to; i++) {
  633. html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active disabled' : '') + '">',
  634. '<a href="javascript:void(0)">', i ,'</a>',
  635. '</li>');
  636. }
  637. html.push(
  638. '<li class="page-next"><a href="javascript:void(0)">&gt;</a></li>',
  639. '<li class="page-last"><a href="javascript:void(0)">&gt;&gt;</a></li>',
  640. '</ul>',
  641. '</div>');
  642. this.$pagination.html(html.join(''));
  643. $pageList = this.$pagination.find('.page-list a');
  644. $first = this.$pagination.find('.page-first');
  645. $pre = this.$pagination.find('.page-pre');
  646. $next = this.$pagination.find('.page-next');
  647. $last = this.$pagination.find('.page-last');
  648. $number = this.$pagination.find('.page-number');
  649. if (this.options.pageNumber <= 1) {
  650. $first.addClass('disabled');
  651. $pre.addClass('disabled');
  652. }
  653. if (this.options.pageNumber >= this.totalPages) {
  654. $next.addClass('disabled');
  655. $last.addClass('disabled');
  656. }
  657. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  658. $first.off('click').on('click', $.proxy(this.onPageFirst, this));
  659. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  660. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  661. $last.off('click').on('click', $.proxy(this.onPageLast, this));
  662. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  663. };
  664. BootstrapTable.prototype.updatePagination = function (event) {
  665. // Fix #171: IE disabled button can be clicked bug.
  666. if (event && $(event.currentTarget).hasClass('disabled')) {
  667. return;
  668. }
  669. if (!this.options.maintainSelected) {
  670. this.resetRows();
  671. }
  672. this.initPagination();
  673. if (this.options.sidePagination === 'server') {
  674. this.initServer();
  675. } else {
  676. this.initBody();
  677. }
  678. };
  679. BootstrapTable.prototype.onPageListChange = function (event) {
  680. var $this = $(event.currentTarget);
  681. $this.parent().addClass('active').siblings().removeClass('active');
  682. this.options.pageSize = +$this.text();
  683. this.$toolbar.find('.page-size').text(this.options.pageSize);
  684. this.updatePagination(event);
  685. };
  686. BootstrapTable.prototype.onPageFirst = function (event) {
  687. this.options.pageNumber = 1;
  688. this.updatePagination(event);
  689. };
  690. BootstrapTable.prototype.onPagePre = function (event) {
  691. this.options.pageNumber--;
  692. this.updatePagination(event);
  693. };
  694. BootstrapTable.prototype.onPageNext = function (event) {
  695. this.options.pageNumber++;
  696. this.updatePagination(event);
  697. };
  698. BootstrapTable.prototype.onPageLast = function (event) {
  699. this.options.pageNumber = this.totalPages;
  700. this.updatePagination(event);
  701. };
  702. BootstrapTable.prototype.onPageNumber = function (event) {
  703. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  704. return;
  705. }
  706. this.options.pageNumber = +$(event.currentTarget).text();
  707. this.updatePagination(event);
  708. };
  709. BootstrapTable.prototype.initBody = function (fixedScroll) {
  710. var that = this,
  711. html = [],
  712. data = this.getData();
  713. this.$body = this.$el.find('tbody');
  714. if (!this.$body.length) {
  715. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  716. }
  717. if (this.options.sidePagination === 'server') {
  718. data = this.data;
  719. }
  720. if (!this.options.pagination || this.options.sidePagination === 'server') {
  721. this.pageFrom = 1;
  722. this.pageTo = data.length;
  723. }
  724. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  725. var item = data[i],
  726. style = {},
  727. csses = [];
  728. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  729. if (style && style.css) {
  730. for (var key in style.css) {
  731. csses.push(key + ': ' + style.css[key]);
  732. }
  733. }
  734. html.push('<tr',
  735. sprintf(' class="%s"', style.classes),
  736. sprintf(' data-index="%s"', i),
  737. '>'
  738. );
  739. if (this.options.cardView) {
  740. html.push(sprintf('<td colspan="%s">', this.header.fields.length));
  741. }
  742. $.each(this.header.fields, function (j, field) {
  743. var text = '',
  744. value = item[field],
  745. type = '',
  746. cellStyle = {},
  747. class_ = that.header.classes[j];
  748. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  749. value = calculateObjectValue(that.header,
  750. that.header.formatters[j], [value, item, i], value);
  751. cellStyle = calculateObjectValue(that.header,
  752. that.header.cellStyles[j], [value, item, i], cellStyle);
  753. if (cellStyle.classes) {
  754. class_ = sprintf(' class="%s"', cellStyle.classes);
  755. }
  756. if (cellStyle.css) {
  757. csses = [];
  758. for (var key in cellStyle.css) {
  759. csses.push(key + ': ' + cellStyle.css[key]);
  760. }
  761. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  762. }
  763. if (that.options.columns[j].checkbox || that.options.columns[j].radio) {
  764. //if card view mode bypass
  765. if (that.options.cardView) {
  766. return true;
  767. }
  768. type = that.options.columns[j].checkbox ? 'checkbox' : type;
  769. type = that.options.columns[j].radio ? 'radio' : type;
  770. text = ['<td class="bs-checkbox">',
  771. '<input' +
  772. sprintf(' data-index="%s"', i) +
  773. sprintf(' name="%s"', that.options.selectItemName) +
  774. sprintf(' type="%s"', type) +
  775. sprintf(' value="%s"', item[that.options.idField]) +
  776. sprintf(' checked="%s"', value === true ||
  777. (value && value.checked) ? 'checked' : undefined) +
  778. sprintf(' disabled="%s"', !that.options.columns[j].checkboxEnabled ||
  779. (value && value.disabled) ? 'disabled' : undefined) +
  780. ' />',
  781. '</td>'].join('');
  782. } else {
  783. value = typeof value === 'undefined' ? that.options.undefinedText : value;
  784. text = that.options.cardView ?
  785. ['<div class="card-view">',
  786. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  787. getPropertyFromOther(that.options.columns, 'field', 'title', field)) : '',
  788. sprintf('<span class="value">%s</span>', value),
  789. '</div>'].join('') :
  790. [sprintf('<td%s %s>', class_, style),
  791. value,
  792. '</td>'].join('');
  793. }
  794. html.push(text);
  795. });
  796. if (this.options.cardView) {
  797. html.push('</td>');
  798. }
  799. html.push('</tr>');
  800. }
  801. // show no records
  802. if (!html.length) {
  803. html.push('<tr class="no-records-found">',
  804. sprintf('<td colspan="%s">%s</td>', this.header.fields.length, this.options.formatNoMatches()),
  805. '</tr>');
  806. }
  807. this.$body.html(html.join(''));
  808. if (!fixedScroll) {
  809. this.$container.find('.fixed-table-body').scrollTop(0);
  810. }
  811. // click to select by column
  812. this.$body.find('> tr > td').off('click').on('click', function () {
  813. var $tr = $(this).parent();
  814. that.trigger('click-row', that.data[$tr.data('index')], $tr);
  815. // if click to select - then trigger the checkbox/radio click
  816. if (that.options.clickToSelect) {
  817. if (that.header.clickToSelects[$tr.children().index($(this))]) {
  818. $tr.find(sprintf('[name="%s"]',
  819. that.options.selectItemName)).trigger('click');
  820. }
  821. }
  822. });
  823. this.$body.find('tr').off('dblclick').on('dblclick', function () {
  824. that.trigger('dbl-click-row', that.data[$(this).data('index')], $(this));
  825. });
  826. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  827. this.$selectItem.off('click').on('click', function (event) {
  828. event.stopImmediatePropagation();
  829. // radio trigger click event bug!
  830. if ($(this).is(':radio')) {
  831. $(this).prop('checked', true);
  832. }
  833. var checkAll = that.$selectItem.filter(':enabled').length ===
  834. that.$selectItem.filter(':enabled').filter(':checked').length,
  835. checked = $(this).prop('checked'),
  836. row = that.data[$(this).data('index')];
  837. that.$selectAll.add(that.$selectAll_).prop('checked', checkAll);
  838. row[that.header.stateField] = checked;
  839. that.trigger(checked ? 'check' : 'uncheck', row);
  840. if (that.options.singleSelect) {
  841. that.$selectItem.not(this).each(function () {
  842. that.data[$(this).data('index')][that.header.stateField] = false;
  843. });
  844. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  845. }
  846. that.updateSelected();
  847. });
  848. $.each(this.header.events, function (i, events) {
  849. if (!events) {
  850. return;
  851. }
  852. // fix bug, if events is defined with namespace
  853. if (typeof events === 'string') {
  854. events = calculateObjectValue(null, events);
  855. }
  856. for (var key in events) {
  857. that.$body.find('tr').each(function () {
  858. var $tr = $(this),
  859. $td = $tr.find('td').eq(i),
  860. index = key.indexOf(' '),
  861. name = key.substring(0, index),
  862. el = key.substring(index + 1),
  863. func = events[key];
  864. $td.find(el).off(name).on(name, function (e) {
  865. var index = $tr.data('index'),
  866. row = that.data[index],
  867. value = row[that.header.fields[i]];
  868. func(e, value, row, index);
  869. });
  870. });
  871. }
  872. });
  873. this.updateSelected();
  874. this.resetView();
  875. };
  876. BootstrapTable.prototype.initServer = function (silent) {
  877. var that = this,
  878. data = {},
  879. params = {
  880. pageSize: this.options.pageSize,
  881. pageNumber: this.options.pageNumber,
  882. searchText: this.searchText,
  883. sortName: this.options.sortName,
  884. sortOrder: this.options.sortOrder
  885. };
  886. if (!this.options.url) {
  887. return;
  888. }
  889. if (this.options.queryParamsType === 'limit') {
  890. params = {
  891. limit: params.pageSize,
  892. offset: params.pageSize * (params.pageNumber - 1),
  893. search: params.searchText,
  894. sort: params.sortName,
  895. order: params.sortOrder
  896. };
  897. }
  898. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  899. // false to stop request
  900. if (data === false) {
  901. return;
  902. }
  903. if (!silent) {
  904. this.$loading.show();
  905. }
  906. $.ajax({
  907. type: this.options.method,
  908. url: this.options.url,
  909. data: data,
  910. cache: this.options.cache,
  911. contentType: this.options.contentType,
  912. dataType: 'json',
  913. success: function (res) {
  914. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  915. var data = res;
  916. if (that.options.sidePagination === 'server') {
  917. that.options.totalRows = res.total;
  918. data = res.rows;
  919. }
  920. that.load(data);
  921. that.trigger('load-success', data);
  922. },
  923. error: function (res) {
  924. that.trigger('load-error', res.status);
  925. },
  926. complete: function () {
  927. if (!silent) {
  928. that.$loading.hide();
  929. }
  930. }
  931. });
  932. };
  933. BootstrapTable.prototype.getCaretHtml = function () {
  934. return ['<span class="order' + (this.options.sortOrder === 'desc' ? '' : ' dropup') + '">',
  935. '<span class="caret" style="margin: 10px 5px;"></span>',
  936. '</span>'].join('');
  937. };
  938. BootstrapTable.prototype.updateSelected = function () {
  939. this.$selectItem.each(function () {
  940. $(this).parents('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  941. });
  942. };
  943. BootstrapTable.prototype.updateRows = function (checked) {
  944. var that = this;
  945. this.$selectItem.each(function () {
  946. that.data[$(this).data('index')][that.header.stateField] = checked;
  947. });
  948. };
  949. BootstrapTable.prototype.resetRows = function () {
  950. var that = this;
  951. $.each(this.data, function (i, row) {
  952. that.$selectAll.prop('checked', false);
  953. that.$selectItem.prop('checked', false);
  954. row[that.header.stateField] = false;
  955. });
  956. };
  957. BootstrapTable.prototype.trigger = function (name) {
  958. var args = Array.prototype.slice.call(arguments, 1);
  959. name += '.bs.table';
  960. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  961. this.$el.trigger($.Event(name), args);
  962. this.options.onAll(name, args);
  963. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  964. };
  965. BootstrapTable.prototype.resetHeader = function () {
  966. var that = this,
  967. $fixedHeader = this.$container.find('.fixed-table-header'),
  968. $fixedBody = this.$container.find('.fixed-table-body'),
  969. scrollWidth = this.$el.width() > $fixedBody.width() ? getScrollBarWidth() : 0;
  970. // fix #61: the hidden table reset header bug.
  971. if (this.$el.is(':hidden')) {
  972. clearTimeout(this.timeoutId_); // doesn't matter if it's 0
  973. this.timeoutId_ = setTimeout($.proxy(this.resetHeader, this), 100); // 100ms
  974. return;
  975. }
  976. this.$header_ = this.$header.clone(true, true);
  977. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  978. // fix bug: get $el.css('width') error sometime (height = 500)
  979. setTimeout(function () {
  980. $fixedHeader.css({
  981. 'height': '37px',
  982. 'border-bottom': '1px solid #dddddd',
  983. 'margin-right': scrollWidth
  984. }).find('table').css('width', that.$el.css('width'))
  985. .html('').attr('class', that.$el.attr('class'))
  986. .append(that.$header_);
  987. // fix bug: $.data() is not working as expected after $.append()
  988. that.$header.find('th').each(function (i) {
  989. that.$header_.find('th').eq(i).data($(this).data());
  990. });
  991. that.$body.find('tr:first-child:not(.no-records-found) > *').each(function(i) {
  992. that.$header_.find('div.fht-cell').eq(i).width($(this).innerWidth());
  993. });
  994. that.$el.css('margin-top', -that.$header.height());
  995. // horizontal scroll event
  996. $fixedBody.off('scroll').on('scroll', function () {
  997. $fixedHeader.scrollLeft($(this).scrollLeft());
  998. });
  999. });
  1000. };
  1001. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  1002. if (index === -1) {
  1003. return;
  1004. }
  1005. this.options.columns[index].visible = checked;
  1006. this.initHeader();
  1007. this.initSearch();
  1008. this.initPagination();
  1009. this.initBody();
  1010. if (this.options.showColumns) {
  1011. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  1012. if (needUpdate) {
  1013. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  1014. }
  1015. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  1016. $items.filter(':checked').prop('disabled', true);
  1017. }
  1018. }
  1019. };
  1020. // PUBLIC FUNCTION DEFINITION
  1021. // =======================
  1022. BootstrapTable.prototype.resetView = function (params) {
  1023. var that = this,
  1024. header = this.header;
  1025. if (params && params.height) {
  1026. this.options.height = params.height;
  1027. }
  1028. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  1029. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  1030. if (this.options.height) {
  1031. var toolbarHeight = +this.$toolbar.children().outerHeight(true),
  1032. paginationHeight = +this.$pagination.children().outerHeight(true),
  1033. height = this.options.height - toolbarHeight - paginationHeight;
  1034. this.$container.find('.fixed-table-container').css('height', height + 'px');
  1035. }
  1036. if (this.options.cardView) {
  1037. // remove the element css
  1038. that.$el.css('margin-top', '0');
  1039. that.$container.find('.fixed-table-container').css('padding-bottom', '0');
  1040. return;
  1041. }
  1042. if (this.options.showHeader && this.options.height) {
  1043. this.resetHeader();
  1044. }
  1045. if (this.options.height && this.options.showHeader) {
  1046. this.$container.find('.fixed-table-container').css('padding-bottom', '37px');
  1047. }
  1048. };
  1049. BootstrapTable.prototype.getData = function () {
  1050. return this.searchText ? this.data : this.options.data;
  1051. };
  1052. BootstrapTable.prototype.load = function (data) {
  1053. this.initData(data);
  1054. this.initSearch();
  1055. this.initPagination();
  1056. this.initBody();
  1057. };
  1058. BootstrapTable.prototype.append = function (data) {
  1059. this.initData(data, true);
  1060. this.initSearch();
  1061. this.initPagination();
  1062. this.initBody(true);
  1063. };
  1064. BootstrapTable.prototype.remove = function (params) {
  1065. var len = this.options.data.length,
  1066. i, row;
  1067. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  1068. return;
  1069. }
  1070. for (i = len - 1; i >= 0; i--) {
  1071. row = this.options.data[i];
  1072. if (!row.hasOwnProperty(params.field)) {
  1073. return;
  1074. }
  1075. if ($.inArray(row[params.field], params.values) !== -1) {
  1076. this.options.data.splice(i, 1);
  1077. }
  1078. }
  1079. if (len === this.options.data.length) {
  1080. return;
  1081. }
  1082. this.initSearch();
  1083. this.initPagination();
  1084. this.initBody(true);
  1085. };
  1086. BootstrapTable.prototype.updateRow = function (params) {
  1087. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1088. return;
  1089. }
  1090. $.extend(this.data[params.index], params.row);
  1091. this.initBody();
  1092. };
  1093. BootstrapTable.prototype.mergeCells = function (options) {
  1094. var row = options.index,
  1095. col = $.inArray(options.field, this.header.fields),
  1096. rowspan = options.rowspan || 1,
  1097. colspan = options.colspan || 1,
  1098. i, j,
  1099. $tr = this.$body.find('tr'),
  1100. $td = $tr.eq(row).find('td').eq(col);
  1101. if (row < 0 || col < 0 || row >= this.data.length) {
  1102. return;
  1103. }
  1104. for (i = row; i < row + rowspan; i++) {
  1105. for (j = col; j < col + colspan; j++) {
  1106. $tr.eq(i).find('td').eq(j).hide();
  1107. }
  1108. }
  1109. $td.attr('rowspan', rowspan).attr('colspan', colspan)
  1110. .show(10, $.proxy(this.resetView, this));
  1111. };
  1112. BootstrapTable.prototype.getSelections = function () {
  1113. var that = this;
  1114. return $.grep(this.data, function (row) {
  1115. return row[that.header.stateField];
  1116. });
  1117. };
  1118. BootstrapTable.prototype.checkAll = function () {
  1119. this.$selectAll.add(this.$selectAll_).prop('checked', true);
  1120. this.$selectItem.filter(':enabled').prop('checked', true);
  1121. this.updateRows(true);
  1122. this.updateSelected();
  1123. this.trigger('check-all');
  1124. };
  1125. BootstrapTable.prototype.uncheckAll = function () {
  1126. this.$selectAll.add(this.$selectAll_).prop('checked', false);
  1127. this.$selectItem.filter(':enabled').prop('checked', false);
  1128. this.updateRows(false);
  1129. this.updateSelected();
  1130. this.trigger('uncheck-all');
  1131. };
  1132. BootstrapTable.prototype.destroy = function () {
  1133. this.$el.insertBefore(this.$container);
  1134. $(this.options.toolbar).insertBefore(this.$el);
  1135. this.$container.next().remove();
  1136. this.$container.remove();
  1137. this.$el.html(this.$el_.html())
  1138. .attr('class', this.$el_.attr('class') || ''); // reset the class
  1139. };
  1140. BootstrapTable.prototype.showLoading = function () {
  1141. this.$loading.show();
  1142. };
  1143. BootstrapTable.prototype.hideLoading = function () {
  1144. this.$loading.hide();
  1145. };
  1146. BootstrapTable.prototype.refresh = function (params) {
  1147. if (params && params.url) {
  1148. this.options.url = params.url;
  1149. }
  1150. this.initServer(params && params.silent);
  1151. };
  1152. BootstrapTable.prototype.showColumn = function (field) {
  1153. this.toggleColumn(getFieldIndex(this.options.columns, field), true, true);
  1154. };
  1155. BootstrapTable.prototype.hideColumn = function (field) {
  1156. this.toggleColumn(getFieldIndex(this.options.columns, field), false, true);
  1157. };
  1158. // BOOTSTRAP TABLE PLUGIN DEFINITION
  1159. // =======================
  1160. var allowedMethods = [
  1161. 'getSelections', 'getData',
  1162. 'load', 'append', 'remove',
  1163. 'updateRow',
  1164. 'mergeCells',
  1165. 'checkAll', 'uncheckAll',
  1166. 'refresh',
  1167. 'resetView',
  1168. 'destroy',
  1169. 'showLoading', 'hideLoading',
  1170. 'showColumn', 'hideColumn'
  1171. ];
  1172. $.fn.bootstrapTable = function (option, _relatedTarget) {
  1173. var value;
  1174. this.each(function () {
  1175. var $this = $(this),
  1176. data = $this.data('bootstrap.table'),
  1177. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  1178. typeof option === 'object' && option);
  1179. if (typeof option === 'string') {
  1180. if ($.inArray(option, allowedMethods) < 0) {
  1181. throw "Unknown method: " + option;
  1182. }
  1183. if (!data) {
  1184. return;
  1185. }
  1186. value = data[option](_relatedTarget);
  1187. if (option === 'destroy') {
  1188. $this.removeData('bootstrap.table');
  1189. }
  1190. }
  1191. if (!data) {
  1192. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  1193. }
  1194. });
  1195. return typeof value === 'undefined' ? this : value;
  1196. };
  1197. $.fn.bootstrapTable.Constructor = BootstrapTable;
  1198. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  1199. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  1200. $.fn.bootstrapTable.methods = allowedMethods;
  1201. // BOOTSTRAP TABLE INIT
  1202. // =======================
  1203. $(function () {
  1204. $('[data-toggle="table"]').bootstrapTable();
  1205. });
  1206. }(jQuery);