bootstrap-table.js 114 KB

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