bootstrap-table.js 115 KB

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