bootstrap-table.js 115 KB

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