bootstrap-table.js 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647
  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. that.updateSelected();
  711. });
  712. };
  713. BootstrapTable.prototype.initFooter = function () {
  714. if (!this.options.showFooter || this.options.cardView) {
  715. this.$tableFooter.hide();
  716. } else {
  717. this.$tableFooter.show();
  718. }
  719. };
  720. /**
  721. * @param data
  722. * @param type: append / prepend
  723. */
  724. BootstrapTable.prototype.initData = function (data, type) {
  725. if (type === 'append') {
  726. this.data = this.data.concat(data);
  727. } else if (type === 'prepend') {
  728. this.data = [].concat(data).concat(this.data);
  729. } else {
  730. this.data = data || this.options.data;
  731. }
  732. // Fix #839 Records deleted when adding new row on filtered table
  733. if (type === 'append') {
  734. this.options.data = this.options.data.concat(data);
  735. } else if (type === 'prepend') {
  736. this.options.data = [].concat(data).concat(this.options.data);
  737. } else {
  738. this.options.data = this.data;
  739. }
  740. if (this.options.sidePagination === 'server') {
  741. return;
  742. }
  743. this.initSort();
  744. };
  745. BootstrapTable.prototype.initSort = function () {
  746. var that = this,
  747. name = this.options.sortName,
  748. order = this.options.sortOrder === 'desc' ? -1 : 1,
  749. index = $.inArray(this.options.sortName, this.header.fields);
  750. if (index !== -1) {
  751. this.data.sort(function (a, b) {
  752. if (that.header.sortNames[index]) {
  753. name = that.header.sortNames[index];
  754. }
  755. var aa = getItemField(a, name),
  756. bb = getItemField(b, name),
  757. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
  758. if (value !== undefined) {
  759. return order * value;
  760. }
  761. // Fix #161: undefined or null string sort bug.
  762. if (aa === undefined || aa === null) {
  763. aa = '';
  764. }
  765. if (bb === undefined || bb === null) {
  766. bb = '';
  767. }
  768. // IF both values are numeric, do a numeric comparison
  769. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  770. // Convert numerical values form string to float.
  771. aa = parseFloat(aa);
  772. bb = parseFloat(bb);
  773. if (aa < bb) {
  774. return order * -1;
  775. }
  776. return order;
  777. }
  778. if (aa === bb) {
  779. return 0;
  780. }
  781. // If value is not a string, convert to string
  782. if (typeof aa !== 'string') {
  783. aa = aa.toString();
  784. }
  785. if (aa.localeCompare(bb) === -1) {
  786. return order * -1;
  787. }
  788. return order;
  789. });
  790. }
  791. };
  792. BootstrapTable.prototype.onSort = function (event) {
  793. var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(),
  794. $this_ = this.$header.find('th').eq($this.index());
  795. this.$header.add(this.$header_).find('span.order').remove();
  796. if (this.options.sortName === $this.data('field')) {
  797. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  798. } else {
  799. this.options.sortName = $this.data('field');
  800. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  801. }
  802. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  803. $this.add($this_).data('order', this.options.sortOrder);
  804. // Assign the correct sortable arrow
  805. this.getCaret();
  806. if (this.options.sidePagination === 'server') {
  807. this.initServer(this.options.silentSort);
  808. return;
  809. }
  810. this.initSort();
  811. this.initBody();
  812. };
  813. BootstrapTable.prototype.initToolbar = function () {
  814. var that = this,
  815. html = [],
  816. timeoutId = 0,
  817. $keepOpen,
  818. $search,
  819. switchableCount = 0;
  820. this.$toolbar.html('');
  821. if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
  822. $(sprintf('<div class="bars pull-%s"></div>', this.options.toolbarAlign))
  823. .appendTo(this.$toolbar)
  824. .append($(this.options.toolbar));
  825. }
  826. // showColumns, showToggle, showRefresh
  827. html = [sprintf('<div class="columns columns-%s btn-group pull-%s">',
  828. this.options.buttonsAlign, this.options.buttonsAlign)];
  829. if (typeof this.options.icons === 'string') {
  830. this.options.icons = calculateObjectValue(null, this.options.icons);
  831. }
  832. if (this.options.showPaginationSwitch) {
  833. html.push(sprintf('<button class="btn btn-default" type="button" name="paginationSwitch" title="%s">',
  834. this.options.formatPaginationSwitch()),
  835. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
  836. '</button>');
  837. }
  838. if (this.options.showRefresh) {
  839. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="refresh" title="%s">',
  840. this.options.formatRefresh()),
  841. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
  842. '</button>');
  843. }
  844. if (this.options.showToggle) {
  845. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="toggle" title="%s">',
  846. this.options.formatToggle()),
  847. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
  848. '</button>');
  849. }
  850. if (this.options.showColumns) {
  851. html.push(sprintf('<div class="keep-open btn-group" title="%s">',
  852. this.options.formatColumns()),
  853. '<button type="button" class="btn btn-default' + (this.options.iconSize == undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
  854. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
  855. ' <span class="caret"></span>',
  856. '</button>',
  857. '<ul class="dropdown-menu" role="menu">');
  858. $.each(this.columns, function (i, column) {
  859. if (column.radio || column.checkbox) {
  860. return;
  861. }
  862. if (that.options.cardView && (!column.cardVisible)) {
  863. return;
  864. }
  865. var checked = column.visible ? ' checked="checked"' : '';
  866. if (column.switchable) {
  867. html.push(sprintf('<li>' +
  868. '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
  869. '</li>', column.field, i, checked, column.title));
  870. switchableCount++;
  871. }
  872. });
  873. html.push('</ul>',
  874. '</div>');
  875. }
  876. html.push('</div>');
  877. // Fix #188: this.showToolbar is for extentions
  878. if (this.showToolbar || html.length > 2) {
  879. this.$toolbar.append(html.join(''));
  880. }
  881. if (this.options.showPaginationSwitch) {
  882. this.$toolbar.find('button[name="paginationSwitch"]')
  883. .off('click').on('click', $.proxy(this.togglePagination, this));
  884. }
  885. if (this.options.showRefresh) {
  886. this.$toolbar.find('button[name="refresh"]')
  887. .off('click').on('click', $.proxy(this.refresh, this));
  888. }
  889. if (this.options.showToggle) {
  890. this.$toolbar.find('button[name="toggle"]')
  891. .off('click').on('click', function () {
  892. that.toggleView();
  893. });
  894. }
  895. if (this.options.showColumns) {
  896. $keepOpen = this.$toolbar.find('.keep-open');
  897. if (switchableCount <= this.options.minimumCountColumns) {
  898. $keepOpen.find('input').prop('disabled', true);
  899. }
  900. $keepOpen.find('li').off('click').on('click', function (event) {
  901. event.stopImmediatePropagation();
  902. });
  903. $keepOpen.find('input').off('click').on('click', function () {
  904. var $this = $(this);
  905. that.toggleColumn(getFieldIndex(that.columns,
  906. $(this).data('field')), $this.prop('checked'), false);
  907. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  908. });
  909. }
  910. if (this.options.search) {
  911. html = [];
  912. html.push(
  913. '<div class="pull-' + this.options.searchAlign + ' search">',
  914. sprintf('<input class="form-control' + (this.options.iconSize === undefined ? '' : ' input-' + this.options.iconSize) + '" type="text" placeholder="%s">',
  915. this.options.formatSearch()),
  916. '</div>');
  917. this.$toolbar.append(html.join(''));
  918. $search = this.$toolbar.find('.search input');
  919. $search.off('keyup drop').on('keyup drop', function (event) {
  920. clearTimeout(timeoutId); // doesn't matter if it's 0
  921. timeoutId = setTimeout(function () {
  922. that.onSearch(event);
  923. }, that.options.searchTimeOut);
  924. });
  925. }
  926. };
  927. BootstrapTable.prototype.onSearch = function (event) {
  928. var text = $.trim($(event.currentTarget).val());
  929. // trim search input
  930. if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
  931. $(event.currentTarget).val(text);
  932. }
  933. if (text === this.searchText) {
  934. return;
  935. }
  936. this.searchText = text;
  937. this.options.pageNumber = 1;
  938. this.initSearch();
  939. this.updatePagination();
  940. this.trigger('search', text);
  941. };
  942. BootstrapTable.prototype.initSearch = function () {
  943. var that = this;
  944. if (this.options.sidePagination !== 'server') {
  945. var s = this.searchText && this.searchText.toLowerCase();
  946. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  947. // Check filter
  948. this.data = f ? $.grep(this.options.data, function (item, i) {
  949. for (var key in f) {
  950. if (item[key] !== f[key]) {
  951. return false;
  952. }
  953. }
  954. return true;
  955. }) : this.options.data;
  956. this.data = s ? $.grep(this.data, function (item, i) {
  957. for (var key in item) {
  958. key = $.isNumeric(key) ? parseInt(key, 10) : key;
  959. var value = item[key],
  960. column = that.columns[getFieldIndex(that.columns, key)],
  961. j = $.inArray(key, that.header.fields);
  962. // Fix #142: search use formated data
  963. if (column && column.searchFormatter) {
  964. value = calculateObjectValue(column,
  965. that.header.formatters[j], [value, item, i], value);
  966. }
  967. var index = $.inArray(key, that.header.fields);
  968. if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
  969. if (that.options.strictSearch) {
  970. if ((value + '').toLowerCase() === s) {
  971. return true;
  972. }
  973. } else {
  974. if ((value + '').toLowerCase().indexOf(s) !== -1) {
  975. return true;
  976. }
  977. }
  978. }
  979. }
  980. return false;
  981. }) : this.data;
  982. }
  983. };
  984. BootstrapTable.prototype.initPagination = function () {
  985. if (!this.options.pagination) {
  986. this.$pagination.hide();
  987. return;
  988. } else {
  989. this.$pagination.show();
  990. }
  991. var that = this,
  992. html = [],
  993. $allSelected = false,
  994. i, from, to,
  995. $pageList,
  996. $first, $pre,
  997. $next, $last,
  998. $number,
  999. data = this.getData();
  1000. if (this.options.sidePagination !== 'server') {
  1001. this.options.totalRows = data.length;
  1002. }
  1003. this.totalPages = 0;
  1004. if (this.options.totalRows) {
  1005. if (this.options.pageSize === this.options.formatAllRows()) {
  1006. this.options.pageSize = this.options.totalRows;
  1007. $allSelected = true;
  1008. } else if (this.options.pageSize === this.options.totalRows) {
  1009. // Fix #667 Table with pagination,
  1010. // multiple pages and a search that matches to one page throws exception
  1011. var pageLst = typeof this.options.pageList === 'string' ?
  1012. this.options.pageList.replace('[', '').replace(']', '')
  1013. .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
  1014. if ($.inArray(this.options.formatAllRows().toLowerCase(), pageLst) > -1) {
  1015. $allSelected = true;
  1016. }
  1017. }
  1018. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  1019. this.options.totalPages = this.totalPages;
  1020. }
  1021. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  1022. this.options.pageNumber = this.totalPages;
  1023. }
  1024. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  1025. this.pageTo = this.options.pageNumber * this.options.pageSize;
  1026. if (this.pageTo > this.options.totalRows) {
  1027. this.pageTo = this.options.totalRows;
  1028. }
  1029. html.push(
  1030. '<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
  1031. '<span class="pagination-info">',
  1032. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  1033. '</span>');
  1034. html.push('<span class="page-list">');
  1035. var pageNumber = [
  1036. sprintf('<span class="btn-group %s">',
  1037. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  1038. 'dropdown' : 'dropup'),
  1039. '<button type="button" class="btn btn-default ' +
  1040. (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) +
  1041. ' dropdown-toggle" data-toggle="dropdown">',
  1042. '<span class="page-size">',
  1043. $allSelected ? this.options.formatAllRows() : this.options.pageSize,
  1044. '</span>',
  1045. ' <span class="caret"></span>',
  1046. '</button>',
  1047. '<ul class="dropdown-menu" role="menu">'
  1048. ],
  1049. pageList = this.options.pageList;
  1050. if (typeof this.options.pageList === 'string') {
  1051. var list = this.options.pageList.replace('[', '').replace(']', '')
  1052. .replace(/ /g, '').split(',');
  1053. pageList = [];
  1054. $.each(list, function (i, value) {
  1055. pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
  1056. that.options.formatAllRows() : +value);
  1057. });
  1058. }
  1059. $.each(pageList, function (i, page) {
  1060. if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
  1061. var active;
  1062. if ($allSelected) {
  1063. active = page === that.options.formatAllRows() ? ' class="active"' : '';
  1064. } else {
  1065. active = page === that.options.pageSize ? ' class="active"' : '';
  1066. }
  1067. pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
  1068. }
  1069. });
  1070. pageNumber.push('</ul></span>');
  1071. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  1072. html.push('</span>');
  1073. html.push('</div>',
  1074. '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
  1075. '<ul class="pagination' + (this.options.iconSize === undefined ? '' : ' pagination-' + this.options.iconSize) + '">',
  1076. '<li class="page-first"><a href="javascript:void(0)">' + this.options.paginationFirstText + '</a></li>',
  1077. '<li class="page-pre"><a href="javascript:void(0)">' + this.options.paginationPreText + '</a></li>');
  1078. if (this.totalPages < 5) {
  1079. from = 1;
  1080. to = this.totalPages;
  1081. } else {
  1082. from = this.options.pageNumber - 2;
  1083. to = from + 4;
  1084. if (from < 1) {
  1085. from = 1;
  1086. to = 5;
  1087. }
  1088. if (to > this.totalPages) {
  1089. to = this.totalPages;
  1090. from = to - 4;
  1091. }
  1092. }
  1093. for (i = from; i <= to; i++) {
  1094. html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
  1095. '<a href="javascript:void(0)">', i, '</a>',
  1096. '</li>');
  1097. }
  1098. html.push(
  1099. '<li class="page-next"><a href="javascript:void(0)">' + this.options.paginationNextText + '</a></li>',
  1100. '<li class="page-last"><a href="javascript:void(0)">' + this.options.paginationLastText + '</a></li>',
  1101. '</ul>',
  1102. '</div>');
  1103. this.$pagination.html(html.join(''));
  1104. $pageList = this.$pagination.find('.page-list a');
  1105. $first = this.$pagination.find('.page-first');
  1106. $pre = this.$pagination.find('.page-pre');
  1107. $next = this.$pagination.find('.page-next');
  1108. $last = this.$pagination.find('.page-last');
  1109. $number = this.$pagination.find('.page-number');
  1110. if (this.options.pageNumber <= 1) {
  1111. $first.addClass('disabled');
  1112. $pre.addClass('disabled');
  1113. }
  1114. if (this.options.pageNumber >= this.totalPages) {
  1115. $next.addClass('disabled');
  1116. $last.addClass('disabled');
  1117. }
  1118. if (this.options.smartDisplay) {
  1119. if (this.totalPages <= 1) {
  1120. this.$pagination.find('div.pagination').hide();
  1121. }
  1122. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  1123. this.$pagination.find('span.page-list').hide();
  1124. }
  1125. // when data is empty, hide the pagination
  1126. this.$pagination[this.getData().length ? 'show' : 'hide']();
  1127. }
  1128. if ($allSelected) {
  1129. this.options.pageSize = this.options.formatAllRows();
  1130. }
  1131. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  1132. $first.off('click').on('click', $.proxy(this.onPageFirst, this));
  1133. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1134. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1135. $last.off('click').on('click', $.proxy(this.onPageLast, this));
  1136. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1137. };
  1138. BootstrapTable.prototype.updatePagination = function (event) {
  1139. // Fix #171: IE disabled button can be clicked bug.
  1140. if (event && $(event.currentTarget).hasClass('disabled')) {
  1141. return;
  1142. }
  1143. if (!this.options.maintainSelected) {
  1144. this.resetRows();
  1145. }
  1146. this.initPagination();
  1147. if (this.options.sidePagination === 'server') {
  1148. this.initServer();
  1149. } else {
  1150. this.initBody();
  1151. }
  1152. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1153. };
  1154. BootstrapTable.prototype.onPageListChange = function (event) {
  1155. var $this = $(event.currentTarget);
  1156. $this.parent().addClass('active').siblings().removeClass('active');
  1157. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
  1158. this.options.formatAllRows() : +$this.text();
  1159. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1160. this.updatePagination(event);
  1161. };
  1162. BootstrapTable.prototype.onPageFirst = function (event) {
  1163. this.options.pageNumber = 1;
  1164. this.updatePagination(event);
  1165. };
  1166. BootstrapTable.prototype.onPagePre = function (event) {
  1167. this.options.pageNumber--;
  1168. this.updatePagination(event);
  1169. };
  1170. BootstrapTable.prototype.onPageNext = function (event) {
  1171. this.options.pageNumber++;
  1172. this.updatePagination(event);
  1173. };
  1174. BootstrapTable.prototype.onPageLast = function (event) {
  1175. this.options.pageNumber = this.totalPages;
  1176. this.updatePagination(event);
  1177. };
  1178. BootstrapTable.prototype.onPageNumber = function (event) {
  1179. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1180. return;
  1181. }
  1182. this.options.pageNumber = +$(event.currentTarget).text();
  1183. this.updatePagination(event);
  1184. };
  1185. BootstrapTable.prototype.initBody = function (fixedScroll) {
  1186. var that = this,
  1187. html = [],
  1188. data = this.getData();
  1189. this.trigger('pre-body', data);
  1190. this.$body = this.$el.find('>tbody');
  1191. if (!this.$body.length) {
  1192. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1193. }
  1194. //Fix #389 Bootstrap-table-flatJSON is not working
  1195. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1196. this.pageFrom = 1;
  1197. this.pageTo = data.length;
  1198. }
  1199. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1200. var key,
  1201. item = data[i],
  1202. style = {},
  1203. csses = [],
  1204. data_ = '',
  1205. attributes = {},
  1206. htmlAttributes = [];
  1207. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1208. if (style && style.css) {
  1209. for (key in style.css) {
  1210. csses.push(key + ': ' + style.css[key]);
  1211. }
  1212. }
  1213. attributes = calculateObjectValue(this.options,
  1214. this.options.rowAttributes, [item, i], attributes);
  1215. if (attributes) {
  1216. for (key in attributes) {
  1217. htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
  1218. }
  1219. }
  1220. if (item._data && !$.isEmptyObject(item._data)) {
  1221. $.each(item._data, function (k, v) {
  1222. // ignore data-index
  1223. if (k === 'index') {
  1224. return;
  1225. }
  1226. data_ += sprintf(' data-%s="%s"', k, v);
  1227. });
  1228. }
  1229. html.push('<tr',
  1230. sprintf(' %s', htmlAttributes.join(' ')),
  1231. sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
  1232. sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
  1233. sprintf(' data-index="%s"', i),
  1234. sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
  1235. sprintf('%s', data_),
  1236. '>'
  1237. );
  1238. if (this.options.cardView) {
  1239. html.push(sprintf('<td colspan="%s">', this.header.fields.length));
  1240. }
  1241. if (!this.options.cardView && this.options.detailView) {
  1242. html.push('<td>',
  1243. '<a class="detail-icon" href="javascript:">',
  1244. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
  1245. '</a>',
  1246. '</td>');
  1247. }
  1248. $.each(this.header.fields, function (j, field) {
  1249. var text = '',
  1250. value = getItemField(item, field),
  1251. type = '',
  1252. cellStyle = {},
  1253. id_ = '',
  1254. class_ = that.header.classes[j],
  1255. data_ = '',
  1256. rowspan_ = '',
  1257. title_ = '',
  1258. column = that.columns[getFieldIndex(that.columns, field)];
  1259. if (!column.visible) {
  1260. return;
  1261. }
  1262. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  1263. value = calculateObjectValue(column,
  1264. that.header.formatters[j], [value, item, i], value);
  1265. // handle td's id and class
  1266. if (item['_' + field + '_id']) {
  1267. id_ = sprintf(' id="%s"', item['_' + field + '_id']);
  1268. }
  1269. if (item['_' + field + '_class']) {
  1270. class_ = sprintf(' class="%s"', item['_' + field + '_class']);
  1271. }
  1272. if (item['_' + field + '_rowspan']) {
  1273. rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1274. }
  1275. if (item['_' + field + '_title']) {
  1276. title_ = sprintf(' title="%s"', item['_' + field + '_title']);
  1277. }
  1278. cellStyle = calculateObjectValue(that.header,
  1279. that.header.cellStyles[j], [value, item, i], cellStyle);
  1280. if (cellStyle.classes) {
  1281. class_ = sprintf(' class="%s"', cellStyle.classes);
  1282. }
  1283. if (cellStyle.css) {
  1284. var csses_ = [];
  1285. for (var key in cellStyle.css) {
  1286. csses_.push(key + ': ' + cellStyle.css[key]);
  1287. }
  1288. style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
  1289. }
  1290. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1291. $.each(item['_' + field + '_data'], function (k, v) {
  1292. // ignore data-index
  1293. if (k === 'index') {
  1294. return;
  1295. }
  1296. data_ += sprintf(' data-%s="%s"', k, v);
  1297. });
  1298. }
  1299. if (column.checkbox || column.radio) {
  1300. type = column.checkbox ? 'checkbox' : type;
  1301. type = column.radio ? 'radio' : type;
  1302. text = [that.options.cardView ?
  1303. '<div class="card-view">' : '<td class="bs-checkbox">',
  1304. '<input' +
  1305. sprintf(' data-index="%s"', i) +
  1306. sprintf(' name="%s"', that.options.selectItemName) +
  1307. sprintf(' type="%s"', type) +
  1308. sprintf(' value="%s"', item[that.options.idField]) +
  1309. sprintf(' checked="%s"', value === true ||
  1310. (value && value.checked) ? 'checked' : undefined) +
  1311. sprintf(' disabled="%s"', !column.checkboxEnabled ||
  1312. (value && value.disabled) ? 'disabled' : undefined) +
  1313. ' />',
  1314. that.header.formatters[j] && typeof value === 'string' ? value : '',
  1315. that.options.cardView ? '</div>' : '</td>'
  1316. ].join('');
  1317. item[that.header.stateField] = value === true || (value && value.checked);
  1318. } else {
  1319. value = typeof value === 'undefined' || value === null ?
  1320. that.options.undefinedText : value;
  1321. text = that.options.cardView ? ['<div class="card-view">',
  1322. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  1323. getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
  1324. sprintf('<span class="value">%s</span>', value),
  1325. '</div>'
  1326. ].join('') : [sprintf('<td%s %s %s %s %s %s>', id_, class_, style, data_, rowspan_, title_),
  1327. value,
  1328. '</td>'
  1329. ].join('');
  1330. // Hide empty data on Card view when smartDisplay is set to true.
  1331. if (that.options.cardView && that.options.smartDisplay && value === '') {
  1332. // Should set a placeholder for event binding correct fieldIndex
  1333. text = '<div class="card-view"></div>';
  1334. }
  1335. }
  1336. html.push(text);
  1337. });
  1338. if (this.options.cardView) {
  1339. html.push('</td>');
  1340. }
  1341. html.push('</tr>');
  1342. }
  1343. // show no records
  1344. if (!html.length) {
  1345. html.push('<tr class="no-records-found">',
  1346. sprintf('<td colspan="%s">%s</td>',
  1347. this.$header.find('th').length, this.options.formatNoMatches()),
  1348. '</tr>');
  1349. }
  1350. this.$body.html(html.join(''));
  1351. if (!fixedScroll) {
  1352. this.scrollTo(0);
  1353. }
  1354. // click to select by column
  1355. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
  1356. var $td = $(this),
  1357. $tr = $td.parent(),
  1358. item = that.data[$tr.data('index')],
  1359. index = $td[0].cellIndex,
  1360. field = that.header.fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
  1361. column = that.columns[getFieldIndex(that.columns, field)],
  1362. value = getItemField(item, field);
  1363. if ($td.find('.detail-icon').length) {
  1364. return;
  1365. }
  1366. that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  1367. that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr);
  1368. // if click to select - then trigger the checkbox/radio click
  1369. if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect) {
  1370. var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
  1371. if ($selectItem.length) {
  1372. $selectItem[0].click(); // #144: .trigger('click') bug
  1373. }
  1374. }
  1375. });
  1376. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function () {
  1377. var $this = $(this),
  1378. $tr = $this.parent().parent(),
  1379. index = $tr.data('index'),
  1380. row = data[index]; // Fix #980 Detail view, when searching, returns wrong row
  1381. // remove and update
  1382. if ($tr.next().is('tr.detail-view')) {
  1383. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailOpen));
  1384. $tr.next().remove();
  1385. that.trigger('collapse-row', index, row);
  1386. } else {
  1387. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
  1388. $tr.after(sprintf('<tr class="detail-view"><td colspan="%s">%s</td></tr>',
  1389. $tr.find('td').length, calculateObjectValue(that.options,
  1390. that.options.detailFormatter, [index, row], '')));
  1391. that.trigger('expand-row', index, row, $tr.next().find('td'));
  1392. }
  1393. that.resetView();
  1394. });
  1395. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  1396. this.$selectItem.off('click').on('click', function (event) {
  1397. event.stopImmediatePropagation();
  1398. var $this = $(this),
  1399. checked = $this.prop('checked'),
  1400. row = that.data[$this.data('index')];
  1401. if (that.options.maintainSelected && $(this).is(':radio')) {
  1402. $.each(that.options.data, function (i, row) {
  1403. row[that.header.stateField] = false;
  1404. });
  1405. }
  1406. row[that.header.stateField] = checked;
  1407. if (that.options.singleSelect) {
  1408. that.$selectItem.not(this).each(function () {
  1409. that.data[$(this).data('index')][that.header.stateField] = false;
  1410. });
  1411. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  1412. }
  1413. that.updateSelected();
  1414. that.trigger(checked ? 'check' : 'uncheck', row, $this);
  1415. });
  1416. $.each(this.header.events, function (i, events) {
  1417. if (!events) {
  1418. return;
  1419. }
  1420. // fix bug, if events is defined with namespace
  1421. if (typeof events === 'string') {
  1422. events = calculateObjectValue(null, events);
  1423. }
  1424. var field = that.header.fields[i],
  1425. fieldIndex = $.inArray(field, that.getVisibleFields());
  1426. if (that.options.detailView && !that.options.cardView) {
  1427. fieldIndex += 1;
  1428. }
  1429. for (var key in events) {
  1430. that.$body.find('>tr:not(.no-records-found)').each(function () {
  1431. var $tr = $(this),
  1432. $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
  1433. index = key.indexOf(' '),
  1434. name = key.substring(0, index),
  1435. el = key.substring(index + 1),
  1436. func = events[key];
  1437. $td.find(el).off(name).on(name, function (e) {
  1438. var index = $tr.data('index'),
  1439. row = that.data[index],
  1440. value = row[field];
  1441. func.apply(this, [e, value, row, index]);
  1442. });
  1443. });
  1444. }
  1445. });
  1446. this.updateSelected();
  1447. this.resetView();
  1448. this.trigger('post-body');
  1449. };
  1450. BootstrapTable.prototype.initServer = function (silent, query) {
  1451. var that = this,
  1452. data = {},
  1453. params = {
  1454. pageSize: this.options.pageSize === this.options.formatAllRows() ?
  1455. this.options.totalRows : this.options.pageSize,
  1456. pageNumber: this.options.pageNumber,
  1457. searchText: this.searchText,
  1458. sortName: this.options.sortName,
  1459. sortOrder: this.options.sortOrder
  1460. },
  1461. request;
  1462. if (!this.options.url && !this.options.ajax) {
  1463. return;
  1464. }
  1465. if (this.options.queryParamsType === 'limit') {
  1466. params = {
  1467. search: params.searchText,
  1468. sort: params.sortName,
  1469. order: params.sortOrder
  1470. };
  1471. if (this.options.pagination) {
  1472. params.limit = this.options.pageSize === this.options.formatAllRows() ?
  1473. this.options.totalRows : this.options.pageSize;
  1474. params.offset = this.options.pageSize === this.options.formatAllRows() ?
  1475. 0 : this.options.pageSize * (this.options.pageNumber - 1);
  1476. }
  1477. }
  1478. if (!($.isEmptyObject(this.filterColumnsPartial))) {
  1479. params['filter'] = JSON.stringify(this.filterColumnsPartial, null);
  1480. }
  1481. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  1482. $.extend(data, query || {});
  1483. // false to stop request
  1484. if (data === false) {
  1485. return;
  1486. }
  1487. if (!silent) {
  1488. this.$tableLoading.show();
  1489. }
  1490. request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
  1491. type: this.options.method,
  1492. url: this.options.url,
  1493. data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
  1494. JSON.stringify(data) : data,
  1495. cache: this.options.cache,
  1496. contentType: this.options.contentType,
  1497. dataType: this.options.dataType,
  1498. success: function (res) {
  1499. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  1500. that.load(res);
  1501. that.trigger('load-success', res);
  1502. },
  1503. error: function (res) {
  1504. that.trigger('load-error', res.status, res);
  1505. },
  1506. complete: function () {
  1507. if (!silent) {
  1508. that.$tableLoading.hide();
  1509. }
  1510. }
  1511. });
  1512. if (this.options.ajax) {
  1513. calculateObjectValue(this, this.options.ajax, [request], null);
  1514. } else {
  1515. $.ajax(request);
  1516. }
  1517. };
  1518. BootstrapTable.prototype.initSearchText = function () {
  1519. if (this.options.search) {
  1520. if (this.options.searchText !== '') {
  1521. var $search = this.$toolbar.find('.search input');
  1522. $search.val(this.options.searchText);
  1523. this.onSearch({currentTarget: $search});
  1524. }
  1525. }
  1526. };
  1527. BootstrapTable.prototype.getCaret = function () {
  1528. var that = this;
  1529. $.each(this.$header.find('th'), function (i, th) {
  1530. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === that.options.sortName ? that.options.sortOrder : 'both');
  1531. });
  1532. };
  1533. BootstrapTable.prototype.updateSelected = function () {
  1534. var checkAll = this.$selectItem.filter(':enabled').length &&
  1535. this.$selectItem.filter(':enabled').length ===
  1536. this.$selectItem.filter(':enabled').filter(':checked').length;
  1537. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  1538. this.$selectItem.each(function () {
  1539. $(this).closest('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  1540. });
  1541. };
  1542. BootstrapTable.prototype.updateRows = function () {
  1543. var that = this;
  1544. this.$selectItem.each(function () {
  1545. that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
  1546. });
  1547. };
  1548. BootstrapTable.prototype.resetRows = function () {
  1549. var that = this;
  1550. $.each(this.data, function (i, row) {
  1551. that.$selectAll.prop('checked', false);
  1552. that.$selectItem.prop('checked', false);
  1553. if (that.header.stateField) {
  1554. row[that.header.stateField] = false;
  1555. }
  1556. });
  1557. };
  1558. BootstrapTable.prototype.trigger = function (name) {
  1559. var args = Array.prototype.slice.call(arguments, 1);
  1560. name += '.bs.table';
  1561. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  1562. this.$el.trigger($.Event(name), args);
  1563. this.options.onAll(name, args);
  1564. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  1565. };
  1566. BootstrapTable.prototype.resetHeader = function () {
  1567. // fix #61: the hidden table reset header bug.
  1568. // fix bug: get $el.css('width') error sometime (height = 500)
  1569. clearTimeout(this.timeoutId_);
  1570. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  1571. };
  1572. BootstrapTable.prototype.fitHeader = function () {
  1573. var that = this,
  1574. fixedBody,
  1575. scrollWidth,
  1576. focused,
  1577. focusedTemp;
  1578. if (that.$el.is(':hidden')) {
  1579. that.timeoutId_ = setTimeout($.proxy(that.fitHeader, that), 100);
  1580. return;
  1581. }
  1582. fixedBody = this.$tableBody.get(0);
  1583. scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
  1584. fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
  1585. getScrollBarWidth() : 0;
  1586. this.$el.css('margin-top', -this.$header.outerHeight());
  1587. focused = $(':focus');
  1588. if (focused.length > 0) {
  1589. var $th = focused.parents('th');
  1590. if ($th.length > 0) {
  1591. var dataField = $th.attr('data-field');
  1592. if (dataField !== undefined) {
  1593. var $headerTh = this.$header.find("[data-field='" + dataField + "']");
  1594. if ($headerTh.length > 0) {
  1595. $headerTh.find(":input").addClass("focus-temp");
  1596. }
  1597. }
  1598. }
  1599. }
  1600. this.$header_ = this.$header.clone(true, true);
  1601. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  1602. this.$tableHeader.css({
  1603. 'margin-right': scrollWidth
  1604. }).find('table').css('width', this.$el.outerWidth())
  1605. .html('').attr('class', this.$el.attr('class'))
  1606. .append(this.$header_);
  1607. focusedTemp = $('.focus-temp:visible:eq(0)');
  1608. if (focusedTemp.length > 0) {
  1609. focusedTemp.focus();
  1610. this.$header.find('.focus-temp').removeClass('focus-temp');
  1611. }
  1612. // fix bug: $.data() is not working as expected after $.append()
  1613. this.$header.find('th[data-field]').each(function (i) {
  1614. that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
  1615. });
  1616. var visibleFields = this.getVisibleFields();
  1617. this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
  1618. var $this = $(this),
  1619. index = i;
  1620. if (that.options.detailView && !that.options.cardView) {
  1621. if (i === 0) {
  1622. that.$header_.find('th.detail').find('.fht-cell').width($this.innerWidth());
  1623. }
  1624. index = i - 1;
  1625. }
  1626. that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]))
  1627. .find('.fht-cell').width($this.innerWidth());
  1628. });
  1629. // horizontal scroll event
  1630. // TODO: it's probably better improving the layout than binding to scroll event
  1631. this.$tableBody.off('scroll').on('scroll', function () {
  1632. that.$tableHeader.scrollLeft($(this).scrollLeft());
  1633. if (that.options.showFooter && !that.options.cardView) {
  1634. that.$tableFooter.scrollLeft($(this).scrollLeft());
  1635. }
  1636. });
  1637. that.trigger('post-header');
  1638. };
  1639. BootstrapTable.prototype.resetFooter = function () {
  1640. var that = this,
  1641. data = that.getData(),
  1642. html = [];
  1643. if (!this.options.showFooter || this.options.cardView) { //do nothing
  1644. return;
  1645. }
  1646. if (!this.options.cardView && this.options.detailView) {
  1647. html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
  1648. }
  1649. $.each(this.columns, function (i, column) {
  1650. var falign = '', // footer align style
  1651. style = '',
  1652. class_ = sprintf(' class="%s"', column['class']);
  1653. if (!column.visible) {
  1654. return;
  1655. }
  1656. if (that.options.cardView && (!column.cardVisible)) {
  1657. return;
  1658. }
  1659. falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  1660. style = sprintf('vertical-align: %s; ', column.valign);
  1661. html.push('<td', class_, sprintf(' style="%s"', falign + style), '>');
  1662. html.push('<div class="th-inner">');
  1663. html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  1664. html.push('</div>');
  1665. html.push('<div class="fht-cell"></div>');
  1666. html.push('</div>');
  1667. html.push('</td>');
  1668. });
  1669. this.$tableFooter.find('tr').html(html.join(''));
  1670. clearTimeout(this.timeoutFooter_);
  1671. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
  1672. this.$el.is(':hidden') ? 100 : 0);
  1673. };
  1674. BootstrapTable.prototype.fitFooter = function () {
  1675. var that = this,
  1676. $footerTd,
  1677. elWidth,
  1678. scrollWidth;
  1679. clearTimeout(this.timeoutFooter_);
  1680. if (this.$el.is(':hidden')) {
  1681. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  1682. return;
  1683. }
  1684. elWidth = this.$el.css('width');
  1685. scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
  1686. this.$tableFooter.css({
  1687. 'margin-right': scrollWidth
  1688. }).find('table').css('width', elWidth)
  1689. .attr('class', this.$el.attr('class'));
  1690. $footerTd = this.$tableFooter.find('td');
  1691. this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
  1692. var $this = $(this);
  1693. $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
  1694. });
  1695. };
  1696. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  1697. if (index === -1) {
  1698. return;
  1699. }
  1700. this.columns[index].visible = checked;
  1701. this.initHeader();
  1702. this.initSearch();
  1703. this.initPagination();
  1704. this.initBody();
  1705. if (this.options.showColumns) {
  1706. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  1707. if (needUpdate) {
  1708. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  1709. }
  1710. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  1711. $items.filter(':checked').prop('disabled', true);
  1712. }
  1713. }
  1714. };
  1715. BootstrapTable.prototype.toggleRow = function (index, uniqueId, visible) {
  1716. if (index === -1) {
  1717. return;
  1718. }
  1719. this.$body.find(typeof index !== 'undefined' ?
  1720. sprintf('tr[data-index="%s"]', index) :
  1721. sprintf('tr[data-uniqueid="%s"]', uniqueId))
  1722. [visible ? 'show' : 'hide']();
  1723. };
  1724. BootstrapTable.prototype.getVisibleFields = function () {
  1725. var that = this,
  1726. visibleFields = [];
  1727. $.each(this.header.fields, function (j, field) {
  1728. var column = that.columns[getFieldIndex(that.columns, field)];
  1729. if (!column.visible) {
  1730. return;
  1731. }
  1732. visibleFields.push(field);
  1733. });
  1734. return visibleFields;
  1735. };
  1736. // PUBLIC FUNCTION DEFINITION
  1737. // =======================
  1738. BootstrapTable.prototype.resetView = function (params) {
  1739. var padding = 0;
  1740. if (params && params.height) {
  1741. this.options.height = params.height;
  1742. }
  1743. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  1744. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  1745. if (this.options.height) {
  1746. var toolbarHeight = getRealHeight(this.$toolbar),
  1747. paginationHeight = getRealHeight(this.$pagination),
  1748. height = this.options.height - toolbarHeight - paginationHeight;
  1749. this.$tableContainer.css('height', height + 'px');
  1750. }
  1751. if (this.options.cardView) {
  1752. // remove the element css
  1753. this.$el.css('margin-top', '0');
  1754. this.$tableContainer.css('padding-bottom', '0');
  1755. return;
  1756. }
  1757. if (this.options.showHeader && this.options.height) {
  1758. this.$tableHeader.show();
  1759. this.resetHeader();
  1760. padding += this.$header.outerHeight();
  1761. } else {
  1762. this.$tableHeader.hide();
  1763. this.trigger('post-header');
  1764. }
  1765. if (this.options.showFooter) {
  1766. this.resetFooter();
  1767. if (this.options.height) {
  1768. padding += this.$tableFooter.outerHeight() + 1;
  1769. }
  1770. }
  1771. // Assign the correct sortable arrow
  1772. this.getCaret();
  1773. this.$tableContainer.css('padding-bottom', padding + 'px');
  1774. this.trigger('reset-view');
  1775. };
  1776. BootstrapTable.prototype.getData = function (useCurrentPage) {
  1777. return (this.searchText || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) ?
  1778. (useCurrentPage ? this.data.slice(this.pageFrom - 1, this.pageTo) : this.data) :
  1779. (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo) : this.options.data);
  1780. };
  1781. BootstrapTable.prototype.load = function (data) {
  1782. var fixedScroll = false;
  1783. // #431: support pagination
  1784. if (this.options.sidePagination === 'server') {
  1785. this.options.totalRows = data.total;
  1786. fixedScroll = data.fixedScroll;
  1787. data = data[this.options.dataField];
  1788. } else if (!$.isArray(data)) { // support fixedScroll
  1789. fixedScroll = data.fixedScroll;
  1790. data = data.data;
  1791. }
  1792. this.initData(data);
  1793. this.initSearch();
  1794. this.initPagination();
  1795. this.initBody(fixedScroll);
  1796. };
  1797. BootstrapTable.prototype.append = function (data) {
  1798. this.initData(data, 'append');
  1799. this.initSearch();
  1800. this.initPagination();
  1801. this.initBody(true);
  1802. };
  1803. BootstrapTable.prototype.prepend = function (data) {
  1804. this.initData(data, 'prepend');
  1805. this.initSearch();
  1806. this.initPagination();
  1807. this.initBody(true);
  1808. };
  1809. BootstrapTable.prototype.remove = function (params) {
  1810. var len = this.options.data.length,
  1811. i, row;
  1812. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  1813. return;
  1814. }
  1815. for (i = len - 1; i >= 0; i--) {
  1816. row = this.options.data[i];
  1817. if (!row.hasOwnProperty(params.field)) {
  1818. continue;
  1819. }
  1820. if ($.inArray(row[params.field], params.values) !== -1) {
  1821. this.options.data.splice(i, 1);
  1822. }
  1823. }
  1824. if (len === this.options.data.length) {
  1825. return;
  1826. }
  1827. this.initSearch();
  1828. this.initPagination();
  1829. this.initBody(true);
  1830. };
  1831. BootstrapTable.prototype.removeAll = function () {
  1832. if (this.options.data.length > 0) {
  1833. this.options.data.splice(0, this.options.data.length);
  1834. this.initSearch();
  1835. this.initPagination();
  1836. this.initBody(true);
  1837. }
  1838. };
  1839. BootstrapTable.prototype.getRowByUniqueId = function (id) {
  1840. var uniqueId = this.options.uniqueId,
  1841. len = this.options.data.length,
  1842. dataRow = null,
  1843. i, row;
  1844. for (i = len - 1; i >= 0; i--) {
  1845. row = this.options.data[i];
  1846. if (!row.hasOwnProperty(uniqueId)) {
  1847. continue;
  1848. }
  1849. if (typeof row[uniqueId] === 'string') {
  1850. id = id.toString();
  1851. } else if (typeof row[uniqueId] === 'number') {
  1852. if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
  1853. id = parseInt(id);
  1854. } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
  1855. id = parseFloat(id);
  1856. }
  1857. }
  1858. if (row[uniqueId] === id) {
  1859. dataRow = row;
  1860. break;
  1861. }
  1862. }
  1863. return dataRow;
  1864. };
  1865. BootstrapTable.prototype.removeByUniqueId = function (id) {
  1866. var len = this.options.data.length,
  1867. row = this.getRowByUniqueId(id);
  1868. if (row) {
  1869. this.options.data.splice(this.options.data.indexOf(row), 1);
  1870. }
  1871. if (len === this.options.data.length) {
  1872. return;
  1873. }
  1874. this.initSearch();
  1875. this.initPagination();
  1876. this.initBody(true);
  1877. };
  1878. BootstrapTable.prototype.insertRow = function (params) {
  1879. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1880. return;
  1881. }
  1882. this.data.splice(params.index, 0, params.row);
  1883. this.initSearch();
  1884. this.initPagination();
  1885. this.initSort();
  1886. this.initBody(true);
  1887. };
  1888. BootstrapTable.prototype.updateRow = function (params) {
  1889. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1890. return;
  1891. }
  1892. $.extend(this.data[params.index], params.row);
  1893. this.initSort();
  1894. this.initBody(true);
  1895. };
  1896. BootstrapTable.prototype.showRow = function (params) {
  1897. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('uniqueId')) {
  1898. return;
  1899. }
  1900. this.toggleRow(params.index, params.uniqueId, true);
  1901. };
  1902. BootstrapTable.prototype.hideRow = function (params) {
  1903. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('uniqueId')) {
  1904. return;
  1905. }
  1906. this.toggleRow(params.index, params.uniqueId, false);
  1907. };
  1908. BootstrapTable.prototype.getRowsHidden = function (show) {
  1909. var rows = $(this.$body[0]).children().filter(':hidden'),
  1910. i = 0;
  1911. if (show) {
  1912. for (; i < rows.length; i++) {
  1913. $(rows[i]).show();
  1914. }
  1915. }
  1916. return rows;
  1917. };
  1918. BootstrapTable.prototype.mergeCells = function (options) {
  1919. var row = options.index,
  1920. col = $.inArray(options.field, this.getVisibleFields()),
  1921. rowspan = options.rowspan || 1,
  1922. colspan = options.colspan || 1,
  1923. i, j,
  1924. $tr = this.$body.find('>tr'),
  1925. $td;
  1926. if (this.options.detailView && !this.options.cardView) {
  1927. col += 1;
  1928. }
  1929. $td = $tr.eq(row).find('>td').eq(col);
  1930. if (row < 0 || col < 0 || row >= this.data.length) {
  1931. return;
  1932. }
  1933. for (i = row; i < row + rowspan; i++) {
  1934. for (j = col; j < col + colspan; j++) {
  1935. $tr.eq(i).find('>td').eq(j).hide();
  1936. }
  1937. }
  1938. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  1939. };
  1940. BootstrapTable.prototype.updateCell = function (params) {
  1941. if (!params.hasOwnProperty('index') ||
  1942. !params.hasOwnProperty('field') ||
  1943. !params.hasOwnProperty('value')) {
  1944. return;
  1945. }
  1946. this.data[params.index][params.field] = params.value;
  1947. this.initSort();
  1948. this.initBody(true);
  1949. };
  1950. BootstrapTable.prototype.getOptions = function () {
  1951. return this.options;
  1952. };
  1953. BootstrapTable.prototype.getSelections = function () {
  1954. var that = this;
  1955. return $.grep(this.data, function (row) {
  1956. return row[that.header.stateField];
  1957. });
  1958. };
  1959. BootstrapTable.prototype.getAllSelections = function () {
  1960. var that = this;
  1961. return $.grep(this.options.data, function (row) {
  1962. return row[that.header.stateField];
  1963. });
  1964. };
  1965. BootstrapTable.prototype.checkAll = function () {
  1966. this.checkAll_(true);
  1967. };
  1968. BootstrapTable.prototype.uncheckAll = function () {
  1969. this.checkAll_(false);
  1970. };
  1971. BootstrapTable.prototype.checkAll_ = function (checked) {
  1972. var rows;
  1973. if (!checked) {
  1974. rows = this.getSelections();
  1975. }
  1976. this.$selectAll.add(this.$selectAll_).prop('checked', checked);
  1977. this.$selectItem.filter(':enabled').prop('checked', checked);
  1978. this.updateRows();
  1979. if (checked) {
  1980. rows = this.getSelections();
  1981. }
  1982. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  1983. };
  1984. BootstrapTable.prototype.check = function (index) {
  1985. this.check_(true, index);
  1986. };
  1987. BootstrapTable.prototype.uncheck = function (index) {
  1988. this.check_(false, index);
  1989. };
  1990. BootstrapTable.prototype.check_ = function (checked, index) {
  1991. this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1992. this.data[index][this.header.stateField] = checked;
  1993. this.updateSelected();
  1994. this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
  1995. };
  1996. BootstrapTable.prototype.checkBy = function (obj) {
  1997. this.checkBy_(true, obj);
  1998. };
  1999. BootstrapTable.prototype.uncheckBy = function (obj) {
  2000. this.checkBy_(false, obj);
  2001. };
  2002. BootstrapTable.prototype.checkBy_ = function (checked, obj) {
  2003. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  2004. return;
  2005. }
  2006. var that = this,
  2007. rows = [];
  2008. $.each(this.options.data, function (index, row) {
  2009. if (!row.hasOwnProperty(obj.field)) {
  2010. return false;
  2011. }
  2012. if ($.inArray(row[obj.field], obj.values) !== -1) {
  2013. that.$selectItem.filter(':enabled')
  2014. .filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  2015. row[that.header.stateField] = checked;
  2016. rows.push(row);
  2017. that.trigger(checked ? 'check' : 'uncheck', row);
  2018. }
  2019. });
  2020. this.updateSelected();
  2021. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  2022. };
  2023. BootstrapTable.prototype.destroy = function () {
  2024. this.$el.insertBefore(this.$container);
  2025. $(this.options.toolbar).insertBefore(this.$el);
  2026. this.$container.next().remove();
  2027. this.$container.remove();
  2028. this.$el.html(this.$el_.html())
  2029. .css('margin-top', '0')
  2030. .attr('class', this.$el_.attr('class') || ''); // reset the class
  2031. };
  2032. BootstrapTable.prototype.showLoading = function () {
  2033. this.$tableLoading.show();
  2034. };
  2035. BootstrapTable.prototype.hideLoading = function () {
  2036. this.$tableLoading.hide();
  2037. };
  2038. BootstrapTable.prototype.togglePagination = function () {
  2039. this.options.pagination = !this.options.pagination;
  2040. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  2041. if (this.options.pagination) {
  2042. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
  2043. } else {
  2044. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
  2045. }
  2046. this.updatePagination();
  2047. };
  2048. BootstrapTable.prototype.refresh = function (params) {
  2049. if (params && params.url) {
  2050. this.options.url = params.url;
  2051. this.options.pageNumber = 1;
  2052. }
  2053. this.initServer(params && params.silent, params && params.query);
  2054. };
  2055. BootstrapTable.prototype.resetWidth = function () {
  2056. if (this.options.showHeader && this.options.height) {
  2057. this.fitHeader();
  2058. }
  2059. if (this.options.showFooter) {
  2060. this.fitFooter();
  2061. }
  2062. };
  2063. BootstrapTable.prototype.showColumn = function (field) {
  2064. this.toggleColumn(getFieldIndex(this.columns, field), true, true);
  2065. };
  2066. BootstrapTable.prototype.hideColumn = function (field) {
  2067. this.toggleColumn(getFieldIndex(this.columns, field), false, true);
  2068. };
  2069. BootstrapTable.prototype.getHiddenColumns = function () {
  2070. return $.grep(this.columns, function (column) {
  2071. return !column.visible;
  2072. });
  2073. };
  2074. BootstrapTable.prototype.filterBy = function (columns) {
  2075. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  2076. this.options.pageNumber = 1;
  2077. this.initSearch();
  2078. this.updatePagination();
  2079. };
  2080. BootstrapTable.prototype.scrollTo = function (value) {
  2081. if (typeof value === 'string') {
  2082. value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
  2083. }
  2084. if (typeof value === 'number') {
  2085. this.$tableBody.scrollTop(value);
  2086. }
  2087. if (typeof value === 'undefined') {
  2088. return this.$tableBody.scrollTop();
  2089. }
  2090. };
  2091. BootstrapTable.prototype.getScrollPosition = function () {
  2092. return this.scrollTo();
  2093. };
  2094. BootstrapTable.prototype.selectPage = function (page) {
  2095. if (page > 0 && page <= this.options.totalPages) {
  2096. this.options.pageNumber = page;
  2097. this.updatePagination();
  2098. }
  2099. };
  2100. BootstrapTable.prototype.prevPage = function () {
  2101. if (this.options.pageNumber > 1) {
  2102. this.options.pageNumber--;
  2103. this.updatePagination();
  2104. }
  2105. };
  2106. BootstrapTable.prototype.nextPage = function () {
  2107. if (this.options.pageNumber < this.options.totalPages) {
  2108. this.options.pageNumber++;
  2109. this.updatePagination();
  2110. }
  2111. };
  2112. BootstrapTable.prototype.toggleView = function () {
  2113. this.options.cardView = !this.options.cardView;
  2114. this.initHeader();
  2115. // Fixed remove toolbar when click cardView button.
  2116. //that.initToolbar();
  2117. this.initBody();
  2118. this.trigger('toggle', this.options.cardView);
  2119. };
  2120. BootstrapTable.prototype.refreshOptions = function (options) {
  2121. //If the objects are equivalent then avoid the call of destroy / init methods
  2122. if (compareObjects(this.options, options, false)) {
  2123. return;
  2124. }
  2125. this.options = $.extend(this.options, options);
  2126. this.trigger('refresh-options', this.options);
  2127. this.destroy();
  2128. this.init();
  2129. };
  2130. BootstrapTable.prototype.resetSearch = function (text) {
  2131. var $search = this.$toolbar.find('.search input');
  2132. $search.val(text || '');
  2133. this.onSearch({currentTarget: $search});
  2134. };
  2135. BootstrapTable.prototype.expandRow_ = function (expand, index) {
  2136. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
  2137. if ($tr.next().is('tr.detail-view') === (expand ? false : true)) {
  2138. $tr.find('> td > .detail-icon').click();
  2139. }
  2140. };
  2141. BootstrapTable.prototype.expandRow = function (index) {
  2142. this.expandRow_(true, index);
  2143. };
  2144. BootstrapTable.prototype.collapseRow = function (index) {
  2145. this.expandRow_(false, index);
  2146. };
  2147. BootstrapTable.prototype.expandAllRows = function (isSubTable) {
  2148. if (isSubTable) {
  2149. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', 0)),
  2150. that = this,
  2151. detailIcon = null,
  2152. executeInterval = false,
  2153. idInterval = -1;
  2154. if (!$tr.next().is('tr.detail-view')) {
  2155. $tr.find('> td > .detail-icon').click();
  2156. executeInterval = true;
  2157. } else if (!$tr.next().next().is('tr.detail-view')) {
  2158. $tr.next().find(".detail-icon").click();
  2159. executeInterval = true;
  2160. }
  2161. if (executeInterval) {
  2162. try {
  2163. idInterval = setInterval(function () {
  2164. detailIcon = that.$body.find("tr.detail-view").last().find(".detail-icon");
  2165. if (detailIcon.length > 0) {
  2166. detailIcon.click();
  2167. } else {
  2168. clearInterval(idInterval);
  2169. }
  2170. }, 1);
  2171. } catch (ex) {
  2172. clearInterval(idInterval);
  2173. }
  2174. }
  2175. } else {
  2176. var trs = this.$body.children();
  2177. for (var i = 0; i < trs.length; i++) {
  2178. this.expandRow_(true, $(trs[i]).data("index"));
  2179. }
  2180. }
  2181. };
  2182. BootstrapTable.prototype.collapseAllRows = function (isSubTable) {
  2183. if (isSubTable) {
  2184. this.expandRow_(false, 0);
  2185. } else {
  2186. var trs = this.$body.children();
  2187. for (var i = 0; i < trs.length; i++) {
  2188. this.expandRow_(false, $(trs[i]).data("index"));
  2189. }
  2190. }
  2191. };
  2192. // BOOTSTRAP TABLE PLUGIN DEFINITION
  2193. // =======================
  2194. var allowedMethods = [
  2195. 'getOptions',
  2196. 'getSelections', 'getAllSelections', 'getData',
  2197. 'load', 'append', 'prepend', 'remove', 'removeAll',
  2198. 'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
  2199. 'getRowByUniqueId', 'showRow', 'hideRow', 'getRowsHidden',
  2200. 'mergeCells',
  2201. 'checkAll', 'uncheckAll',
  2202. 'check', 'uncheck',
  2203. 'checkBy', 'uncheckBy',
  2204. 'refresh',
  2205. 'resetView',
  2206. 'resetWidth',
  2207. 'destroy',
  2208. 'showLoading', 'hideLoading',
  2209. 'showColumn', 'hideColumn', 'getHiddenColumns',
  2210. 'filterBy',
  2211. 'scrollTo',
  2212. 'getScrollPosition',
  2213. 'selectPage', 'prevPage', 'nextPage',
  2214. 'togglePagination',
  2215. 'toggleView',
  2216. 'refreshOptions',
  2217. 'resetSearch',
  2218. 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows'
  2219. ];
  2220. $.fn.bootstrapTable = function (option) {
  2221. var value,
  2222. args = Array.prototype.slice.call(arguments, 1);
  2223. this.each(function () {
  2224. var $this = $(this),
  2225. data = $this.data('bootstrap.table'),
  2226. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  2227. typeof option === 'object' && option);
  2228. if (typeof option === 'string') {
  2229. if ($.inArray(option, allowedMethods) < 0) {
  2230. throw new Error("Unknown method: " + option);
  2231. }
  2232. if (!data) {
  2233. return;
  2234. }
  2235. value = data[option].apply(data, args);
  2236. if (option === 'destroy') {
  2237. $this.removeData('bootstrap.table');
  2238. }
  2239. }
  2240. if (!data) {
  2241. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  2242. }
  2243. });
  2244. return typeof value === 'undefined' ? this : value;
  2245. };
  2246. $.fn.bootstrapTable.Constructor = BootstrapTable;
  2247. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  2248. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  2249. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  2250. $.fn.bootstrapTable.methods = allowedMethods;
  2251. $.fn.bootstrapTable.utils = {
  2252. sprintf: sprintf,
  2253. getFieldIndex: getFieldIndex,
  2254. compareObjects: compareObjects,
  2255. calculateObjectValue: calculateObjectValue
  2256. };
  2257. // BOOTSTRAP TABLE INIT
  2258. // =======================
  2259. $(function () {
  2260. $('[data-toggle="table"]').bootstrapTable();
  2261. });
  2262. }(jQuery);