bootstrap-table.js 94 KB

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