bootstrap-table.js 92 KB

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