bootstrap-table.js 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302
  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. var field = that.columns[x].field;
  707. row[field] = $(this).html();
  708. // save td's id, class and data-* attributes
  709. row['_' + field + '_id'] = $(this).attr('id');
  710. row['_' + field + '_class'] = $(this).attr('class');
  711. row['_' + field + '_rowspan'] = $(this).attr('rowspan');
  712. row['_' + field + '_colspan'] = $(this).attr('colspan');
  713. row['_' + field + '_title'] = $(this).attr('title');
  714. row['_' + field + '_data'] = getRealDataAttr($(this).data());
  715. });
  716. data.push(row);
  717. });
  718. this.options.data = data;
  719. if (data.length) this.fromHtml = true;
  720. };
  721. BootstrapTable.prototype.initHeader = function () {
  722. var that = this,
  723. visibleColumns = {},
  724. html = [];
  725. this.header = {
  726. fields: [],
  727. styles: [],
  728. classes: [],
  729. formatters: [],
  730. events: [],
  731. sorters: [],
  732. sortNames: [],
  733. cellStyles: [],
  734. searchables: []
  735. };
  736. $.each(this.options.columns, function (i, columns) {
  737. html.push('<tr>');
  738. if (i === 0 && !that.options.cardView && that.options.detailView) {
  739. html.push(sprintf('<th class="detail" rowspan="%s"><div class="fht-cell"></div></th>',
  740. that.options.columns.length));
  741. }
  742. $.each(columns, function (j, column) {
  743. var text = '',
  744. halign = '', // header align style
  745. align = '', // body align style
  746. style = '',
  747. class_ = sprintf(' class="%s"', column['class']),
  748. order = that.options.sortOrder || column.order,
  749. unitWidth = 'px',
  750. width = column.width;
  751. if (column.width !== undefined && (!that.options.cardView)) {
  752. if (typeof column.width === 'string') {
  753. if (column.width.indexOf('%') !== -1) {
  754. unitWidth = '%';
  755. }
  756. }
  757. }
  758. if (column.width && typeof column.width === 'string') {
  759. width = column.width.replace('%', '').replace('px', '');
  760. }
  761. halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  762. align = sprintf('text-align: %s; ', column.align);
  763. style = sprintf('vertical-align: %s; ', column.valign);
  764. style += sprintf('width: %s; ', (column.checkbox || column.radio) && !width ?
  765. (!column.showSelectTitle ? '36px' : undefined) :
  766. (width ? width + unitWidth : undefined));
  767. if (typeof column.fieldIndex !== 'undefined') {
  768. that.header.fields[column.fieldIndex] = column.field;
  769. that.header.styles[column.fieldIndex] = align + style;
  770. that.header.classes[column.fieldIndex] = class_;
  771. that.header.formatters[column.fieldIndex] = column.formatter;
  772. that.header.events[column.fieldIndex] = column.events;
  773. that.header.sorters[column.fieldIndex] = column.sorter;
  774. that.header.sortNames[column.fieldIndex] = column.sortName;
  775. that.header.cellStyles[column.fieldIndex] = column.cellStyle;
  776. that.header.searchables[column.fieldIndex] = column.searchable;
  777. if (!column.visible) {
  778. return;
  779. }
  780. if (that.options.cardView && (!column.cardVisible)) {
  781. return;
  782. }
  783. visibleColumns[column.field] = column;
  784. }
  785. html.push('<th' + sprintf(' title="%s"', column.titleTooltip),
  786. column.checkbox || column.radio ?
  787. sprintf(' class="bs-checkbox %s"', column['class'] || '') :
  788. class_,
  789. sprintf(' style="%s"', halign + style),
  790. sprintf(' rowspan="%s"', column.rowspan),
  791. sprintf(' colspan="%s"', column.colspan),
  792. sprintf(' data-field="%s"', column.field),
  793. j === 0 && column.fieldIndex ? ' data-not-first-th' : '',
  794. '>');
  795. html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
  796. 'sortable both' : ''));
  797. text = that.options.escape ? escapeHTML(column.title) : column.title;
  798. var title = text;
  799. if (column.checkbox) {
  800. text = '';
  801. if (!that.options.singleSelect && that.options.checkboxHeader) {
  802. text = '<input name="btSelectAll" type="checkbox" />';
  803. }
  804. that.header.stateField = column.field;
  805. }
  806. if (column.radio) {
  807. text = '';
  808. that.header.stateField = column.field;
  809. that.options.singleSelect = true;
  810. }
  811. if (!text && column.showSelectTitle) {
  812. text += title;
  813. }
  814. html.push(text);
  815. html.push('</div>');
  816. html.push('<div class="fht-cell"></div>');
  817. html.push('</div>');
  818. html.push('</th>');
  819. });
  820. html.push('</tr>');
  821. });
  822. this.$header.html(html.join(''));
  823. this.$header.find('th[data-field]').each(function (i) {
  824. $(this).data(visibleColumns[$(this).data('field')]);
  825. });
  826. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
  827. var $this = $(this);
  828. if (that.options.detailView && !$this.parent().hasClass('bs-checkbox')) {
  829. if ($this.closest('.bootstrap-table')[0] !== that.$container[0]) {
  830. return false;
  831. }
  832. }
  833. if (that.options.sortable && $this.parent().data().sortable) {
  834. that.onSort(event);
  835. }
  836. });
  837. this.$header.children().children().off('keypress').on('keypress', function (event) {
  838. if (that.options.sortable && $(this).data().sortable) {
  839. var code = event.keyCode || event.which;
  840. if (code == 13) { //Enter keycode
  841. that.onSort(event);
  842. }
  843. }
  844. });
  845. $(window).off('resize.bootstrap-table');
  846. if (!this.options.showHeader || this.options.cardView) {
  847. this.$header.hide();
  848. this.$tableHeader.hide();
  849. this.$tableLoading.css('top', 0);
  850. } else {
  851. this.$header.show();
  852. this.$tableHeader.show();
  853. this.$tableLoading.css('top', this.$header.outerHeight() + 1);
  854. // Assign the correct sortable arrow
  855. this.getCaret();
  856. $(window).on('resize.bootstrap-table', $.proxy(this.resetWidth, this));
  857. }
  858. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  859. this.$selectAll.off('click').on('click', function () {
  860. var checked = $(this).prop('checked');
  861. that[checked ? 'checkAll' : 'uncheckAll']();
  862. that.updateSelected();
  863. });
  864. };
  865. BootstrapTable.prototype.initFooter = function () {
  866. if (!this.options.showFooter || this.options.cardView) {
  867. this.$tableFooter.hide();
  868. } else {
  869. this.$tableFooter.show();
  870. }
  871. };
  872. /**
  873. * @param data
  874. * @param type: append / prepend
  875. */
  876. BootstrapTable.prototype.initData = function (data, type) {
  877. if (type === 'append') {
  878. this.options.data = this.options.data.concat(data);
  879. } else if (type === 'prepend') {
  880. this.options.data = [].concat(data).concat(this.options.data);
  881. } else {
  882. this.options.data = data || this.options.data;
  883. }
  884. this.data = this.options.data;
  885. if (this.options.sidePagination === 'server') {
  886. return;
  887. }
  888. this.initSort();
  889. };
  890. BootstrapTable.prototype.initSort = function () {
  891. var that = this,
  892. name = this.options.sortName,
  893. order = this.options.sortOrder === 'desc' ? -1 : 1,
  894. index = $.inArray(this.options.sortName, this.header.fields),
  895. timeoutId = 0;
  896. if (this.options.customSort !== $.noop) {
  897. this.options.customSort.apply(this, [this.options.sortName, this.options.sortOrder]);
  898. return;
  899. }
  900. if (index !== -1) {
  901. if (this.options.sortStable) {
  902. $.each(this.data, function (i, row) {
  903. row._position = i;
  904. });
  905. }
  906. this.data.sort(function (a, b) {
  907. if (that.header.sortNames[index]) {
  908. name = that.header.sortNames[index];
  909. }
  910. var aa = getItemField(a, name, that.options.escape),
  911. bb = getItemField(b, name, that.options.escape),
  912. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb, a, b]);
  913. if (value !== undefined) {
  914. if (that.options.sortStable && value === 0) {
  915. return a._position - b._position;
  916. }
  917. return order * value;
  918. }
  919. // Fix #161: undefined or null string sort bug.
  920. if (aa === undefined || aa === null) {
  921. aa = '';
  922. }
  923. if (bb === undefined || bb === null) {
  924. bb = '';
  925. }
  926. if (that.options.sortStable && aa === bb) {
  927. aa = a._position;
  928. bb = b._position;
  929. return a._position - b._position;
  930. }
  931. // IF both values are numeric, do a numeric comparison
  932. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  933. // Convert numerical values form string to float.
  934. aa = parseFloat(aa);
  935. bb = parseFloat(bb);
  936. if (aa < bb) {
  937. return order * -1;
  938. }
  939. return order;
  940. }
  941. if (aa === bb) {
  942. return 0;
  943. }
  944. // If value is not a string, convert to string
  945. if (typeof aa !== 'string') {
  946. aa = aa.toString();
  947. }
  948. if (aa.localeCompare(bb) === -1) {
  949. return order * -1;
  950. }
  951. return order;
  952. });
  953. if (this.options.sortClass !== undefined) {
  954. clearTimeout(timeoutId);
  955. timeoutId = setTimeout(function () {
  956. that.$el.removeClass(that.options.sortClass);
  957. var index = that.$header.find(sprintf('[data-field="%s"]',
  958. that.options.sortName).index() + 1);
  959. that.$el.find(sprintf('tr td:nth-child(%s)', index))
  960. .addClass(that.options.sortClass);
  961. }, 250);
  962. }
  963. }
  964. };
  965. BootstrapTable.prototype.onSort = function (event) {
  966. var $this = event.type === "keypress" ? $(event.currentTarget) : $(event.currentTarget).parent(),
  967. $this_ = this.$header.find('th').eq($this.index());
  968. this.$header.add(this.$header_).find('span.order').remove();
  969. if (this.options.sortName === $this.data('field')) {
  970. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  971. } else {
  972. this.options.sortName = $this.data('field');
  973. if (this.options.rememberOrder) {
  974. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  975. } else {
  976. this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].order;
  977. }
  978. }
  979. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  980. $this.add($this_).data('order', this.options.sortOrder);
  981. // Assign the correct sortable arrow
  982. this.getCaret();
  983. if (this.options.sidePagination === 'server') {
  984. this.initServer(this.options.silentSort);
  985. return;
  986. }
  987. this.initSort();
  988. this.initBody();
  989. };
  990. BootstrapTable.prototype.initToolbar = function () {
  991. var that = this,
  992. html = [],
  993. timeoutId = 0,
  994. $keepOpen,
  995. $search,
  996. switchableCount = 0;
  997. if (this.$toolbar.find('.bs-bars').children().length) {
  998. $('body').append($(this.options.toolbar));
  999. }
  1000. this.$toolbar.html('');
  1001. if (typeof this.options.toolbar === 'string' || typeof this.options.toolbar === 'object') {
  1002. $(sprintf('<div class="bs-bars %s-%s"></div>', bs.pullClass, this.options.toolbarAlign))
  1003. .appendTo(this.$toolbar)
  1004. .append($(this.options.toolbar));
  1005. }
  1006. // showColumns, showToggle, showRefresh
  1007. html = [sprintf('<div class="columns columns-%s btn-group %s-%s">',
  1008. this.options.buttonsAlign, bs.pullClass, this.options.buttonsAlign)];
  1009. if (typeof this.options.icons === 'string') {
  1010. this.options.icons = calculateObjectValue(null, this.options.icons);
  1011. }
  1012. if (this.options.showPaginationSwitch) {
  1013. html.push(sprintf('<button class="btn' +
  1014. sprintf(' btn-%s', this.options.buttonsClass) +
  1015. sprintf(' btn-%s', this.options.iconSize) +
  1016. '" type="button" name="paginationSwitch" aria-label="pagination Switch" title="%s">',
  1017. this.options.formatPaginationSwitch()),
  1018. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
  1019. '</button>');
  1020. }
  1021. if (this.options.showFullscreen) {
  1022. this.$toolbar.find('button[name="fullscreen"]')
  1023. .off('click').on('click', $.proxy(this.toggleFullscreen, this));
  1024. }
  1025. if (this.options.showRefresh) {
  1026. html.push(sprintf('<button class="btn' +
  1027. sprintf(' btn-%s', this.options.buttonsClass) +
  1028. sprintf(' btn-%s', this.options.iconSize) +
  1029. '" type="button" name="refresh" aria-label="refresh" title="%s">',
  1030. this.options.formatRefresh()),
  1031. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
  1032. '</button>');
  1033. }
  1034. if (this.options.showToggle) {
  1035. html.push(sprintf('<button class="btn' +
  1036. sprintf(' btn-%s', this.options.buttonsClass) +
  1037. sprintf(' btn-%s', this.options.iconSize) +
  1038. '" type="button" name="toggle" aria-label="toggle" title="%s">',
  1039. this.options.formatToggle()),
  1040. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
  1041. '</button>');
  1042. }
  1043. if (this.options.showFullscreen) {
  1044. html.push(sprintf('<button class="btn' +
  1045. sprintf(' btn-%s', this.options.buttonsClass) +
  1046. sprintf(' btn-%s', this.options.iconSize) +
  1047. '" type="button" name="fullscreen" aria-label="fullscreen" title="%s">',
  1048. this.options.formatFullscreen()),
  1049. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.fullscreen),
  1050. '</button>');
  1051. }
  1052. if (this.options.showColumns) {
  1053. html.push(sprintf('<div class="keep-open btn-group" title="%s">',
  1054. this.options.formatColumns()),
  1055. '<button type="button" aria-label="columns" class="btn' +
  1056. sprintf(' btn-%s', this.options.buttonsClass) +
  1057. sprintf(' btn-%s', this.options.iconSize) +
  1058. ' dropdown-toggle" data-toggle="dropdown">',
  1059. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
  1060. ' <span class="caret"></span>',
  1061. '</button>',
  1062. bs.toobarDropdowHtml[0]);
  1063. $.each(this.columns, function (i, column) {
  1064. if (column.radio || column.checkbox) {
  1065. return;
  1066. }
  1067. if (that.options.cardView && !column.cardVisible) {
  1068. return;
  1069. }
  1070. var checked = column.visible ? ' checked="checked"' : '';
  1071. if (column.switchable) {
  1072. html.push(sprintf(bs.toobarDropdowItemHtml,
  1073. sprintf('<input type="checkbox" data-field="%s" value="%s"%s> %s',
  1074. column.field, i, checked, column.title)));
  1075. switchableCount++;
  1076. }
  1077. });
  1078. html.push(bs.toobarDropdowHtml[1], '</div>');
  1079. }
  1080. html.push('</div>');
  1081. // Fix #188: this.showToolbar is for extensions
  1082. if (this.showToolbar || html.length > 2) {
  1083. this.$toolbar.append(html.join(''));
  1084. }
  1085. if (this.options.showPaginationSwitch) {
  1086. this.$toolbar.find('button[name="paginationSwitch"]')
  1087. .off('click').on('click', $.proxy(this.togglePagination, this));
  1088. }
  1089. if (this.options.showRefresh) {
  1090. this.$toolbar.find('button[name="refresh"]')
  1091. .off('click').on('click', $.proxy(this.refresh, this));
  1092. }
  1093. if (this.options.showToggle) {
  1094. this.$toolbar.find('button[name="toggle"]')
  1095. .off('click').on('click', function () {
  1096. that.toggleView();
  1097. });
  1098. }
  1099. if (this.options.showColumns) {
  1100. $keepOpen = this.$toolbar.find('.keep-open');
  1101. if (switchableCount <= this.options.minimumCountColumns) {
  1102. $keepOpen.find('input').prop('disabled', true);
  1103. }
  1104. $keepOpen.find('li').off('click').on('click', function (event) {
  1105. event.stopImmediatePropagation();
  1106. });
  1107. $keepOpen.find('input').off('click').on('click', function () {
  1108. var $this = $(this);
  1109. that.toggleColumn($(this).val(), $this.prop('checked'), false);
  1110. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  1111. });
  1112. }
  1113. if (this.options.search) {
  1114. html = [];
  1115. html.push(
  1116. sprintf('<div class="%s-%s search">', bs.pullClass, this.options.searchAlign),
  1117. sprintf('<input class="form-control' +
  1118. sprintf(' input-%s', this.options.iconSize) +
  1119. '" type="text" placeholder="%s">',
  1120. this.options.formatSearch()),
  1121. '</div>');
  1122. this.$toolbar.append(html.join(''));
  1123. $search = this.$toolbar.find('.search input');
  1124. $search.off('keyup drop blur').on('keyup drop blur', function (event) {
  1125. if (that.options.searchOnEnterKey && event.keyCode !== 13) {
  1126. return;
  1127. }
  1128. if ($.inArray(event.keyCode, [37, 38, 39, 40]) > -1) {
  1129. return;
  1130. }
  1131. clearTimeout(timeoutId); // doesn't matter if it's 0
  1132. timeoutId = setTimeout(function () {
  1133. that.onSearch(event);
  1134. }, that.options.searchTimeOut);
  1135. });
  1136. if (isIEBrowser()) {
  1137. $search.off('mouseup').on('mouseup', function (event) {
  1138. clearTimeout(timeoutId); // doesn't matter if it's 0
  1139. timeoutId = setTimeout(function () {
  1140. that.onSearch(event);
  1141. }, that.options.searchTimeOut);
  1142. });
  1143. }
  1144. }
  1145. };
  1146. BootstrapTable.prototype.onSearch = function (event) {
  1147. var text = $.trim($(event.currentTarget).val());
  1148. // trim search input
  1149. if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
  1150. $(event.currentTarget).val(text);
  1151. }
  1152. if (text === this.searchText) {
  1153. return;
  1154. }
  1155. this.searchText = text;
  1156. this.options.searchText = text;
  1157. this.options.pageNumber = 1;
  1158. this.initSearch();
  1159. if (event.firedByInitSearchText) {
  1160. if (this.options.sidePagination === 'client') {
  1161. this.updatePagination();
  1162. }
  1163. } else {
  1164. this.updatePagination();
  1165. }
  1166. this.trigger('search', text);
  1167. };
  1168. BootstrapTable.prototype.initSearch = function () {
  1169. var that = this;
  1170. if (this.options.sidePagination !== 'server') {
  1171. if (this.options.customSearch !== $.noop) {
  1172. window[this.options.customSearch].apply(this, [this.searchText]);
  1173. return;
  1174. }
  1175. var s = this.searchText && (this.options.escape ?
  1176. escapeHTML(this.searchText) : this.searchText).toLowerCase();
  1177. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  1178. // Check filter
  1179. this.data = f ? $.grep(this.options.data, function (item, i) {
  1180. for (var key in f) {
  1181. if ($.isArray(f[key]) && $.inArray(item[key], f[key]) === -1 ||
  1182. !$.isArray(f[key]) && item[key] !== f[key]) {
  1183. return false;
  1184. }
  1185. }
  1186. return true;
  1187. }) : this.options.data;
  1188. this.data = s ? $.grep(this.data, function (item, i) {
  1189. for (var j = 0; j < that.header.fields.length; j++) {
  1190. if (!that.header.searchables[j]) {
  1191. continue;
  1192. }
  1193. var key = $.isNumeric(that.header.fields[j]) ? parseInt(that.header.fields[j], 10) : that.header.fields[j];
  1194. var column = that.columns[that.fieldsColumnsIndex[key]];
  1195. var value;
  1196. if (typeof key === 'string') {
  1197. value = item;
  1198. var props = key.split('.');
  1199. for (var prop_index = 0; prop_index < props.length; prop_index++) {
  1200. if (value[props[prop_index]] != null) {
  1201. value = value[props[prop_index]];
  1202. }
  1203. }
  1204. // Fix #142: respect searchForamtter boolean
  1205. if (column && column.searchFormatter) {
  1206. value = calculateObjectValue(column,
  1207. that.header.formatters[j], [value, item, i], value);
  1208. }
  1209. } else {
  1210. value = item[key];
  1211. }
  1212. if (typeof value === 'string' || typeof value === 'number') {
  1213. if (that.options.strictSearch) {
  1214. if ((value + '').toLowerCase() === s) {
  1215. return true;
  1216. }
  1217. } else {
  1218. if ((value + '').toLowerCase().indexOf(s) !== -1) {
  1219. return true;
  1220. }
  1221. }
  1222. }
  1223. }
  1224. return false;
  1225. }) : this.data;
  1226. }
  1227. };
  1228. BootstrapTable.prototype.initPagination = function () {
  1229. if (!this.options.pagination) {
  1230. this.$pagination.hide();
  1231. return;
  1232. } else {
  1233. this.$pagination.show();
  1234. }
  1235. var that = this,
  1236. html = [],
  1237. $allSelected = false,
  1238. i, from, to,
  1239. $pageList,
  1240. $pre,
  1241. $next,
  1242. $number,
  1243. data = this.getData(),
  1244. pageList = this.options.pageList;
  1245. if (this.options.sidePagination !== 'server') {
  1246. this.options.totalRows = data.length;
  1247. }
  1248. this.totalPages = 0;
  1249. if (this.options.totalRows) {
  1250. if (this.options.pageSize === this.options.formatAllRows()) {
  1251. this.options.pageSize = this.options.totalRows;
  1252. $allSelected = true;
  1253. } else if (this.options.pageSize === this.options.totalRows) {
  1254. // Fix #667 Table with pagination,
  1255. // multiple pages and a search that matches to one page throws exception
  1256. var pageLst = typeof this.options.pageList === 'string' ?
  1257. this.options.pageList.replace('[', '').replace(']', '')
  1258. .replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
  1259. if ($.inArray(this.options.formatAllRows().toLowerCase(), pageLst) > -1) {
  1260. $allSelected = true;
  1261. }
  1262. }
  1263. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  1264. this.options.totalPages = this.totalPages;
  1265. }
  1266. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  1267. this.options.pageNumber = this.totalPages;
  1268. }
  1269. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  1270. this.pageTo = this.options.pageNumber * this.options.pageSize;
  1271. if (this.pageTo > this.options.totalRows) {
  1272. this.pageTo = this.options.totalRows;
  1273. }
  1274. html.push(
  1275. sprintf('<div class="%s-%s pagination-detail">', bs.pullClass, this.options.paginationDetailHAlign),
  1276. '<span class="pagination-info">',
  1277. this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) :
  1278. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  1279. '</span>');
  1280. if (!this.options.onlyInfoPagination) {
  1281. html.push('<span class="page-list">');
  1282. var pageNumber = [
  1283. sprintf('<span class="btn-group %s">',
  1284. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  1285. 'dropdown' : 'dropup'),
  1286. '<button type="button" class="btn' +
  1287. sprintf(' btn-%s', this.options.buttonsClass) +
  1288. sprintf(' btn-%s', this.options.iconSize) +
  1289. ' dropdown-toggle" data-toggle="dropdown">',
  1290. '<span class="page-size">',
  1291. $allSelected ? this.options.formatAllRows() : this.options.pageSize,
  1292. '</span>',
  1293. ' <span class="caret"></span>',
  1294. '</button>',
  1295. bs.pageDropdownHtml[0]
  1296. ];
  1297. if (typeof this.options.pageList === 'string') {
  1298. var list = this.options.pageList.replace('[', '').replace(']', '')
  1299. .replace(/ /g, '').split(',');
  1300. pageList = [];
  1301. $.each(list, function (i, value) {
  1302. pageList.push((value.toUpperCase() === that.options.formatAllRows().toUpperCase() || value.toUpperCase() === "UNLIMITED") ?
  1303. that.options.formatAllRows() : +value);
  1304. });
  1305. }
  1306. $.each(pageList, function (i, page) {
  1307. if (!that.options.smartDisplay || i === 0 || pageList[i - 1] < that.options.totalRows) {
  1308. var active;
  1309. if ($allSelected) {
  1310. active = page === that.options.formatAllRows() ? 'active' : '';
  1311. } else {
  1312. active = page === that.options.pageSize ? 'active' : '';
  1313. }
  1314. pageNumber.push(sprintf(bs.pageDropdownItemHtml, active, page));
  1315. }
  1316. });
  1317. pageNumber.push(bs.pageDropdownHtml[1] + '</span>');
  1318. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  1319. html.push('</span>');
  1320. html.push('</div>',
  1321. sprintf('<div class="%s-%s pagination">', bs.pullClass, this.options.paginationHAlign),
  1322. '<ul class="pagination' + sprintf(' pagination-%s', this.options.iconSize) + '">',
  1323. sprintf('<li class="page-item page-pre"><a class="page-link" href="#">%s</a></li>',
  1324. this.options.paginationPreText));
  1325. if (this.totalPages < 5) {
  1326. from = 1;
  1327. to = this.totalPages;
  1328. } else {
  1329. from = this.options.pageNumber - 2;
  1330. to = from + 4;
  1331. if (from < 1) {
  1332. from = 1;
  1333. to = 5;
  1334. }
  1335. if (to > this.totalPages) {
  1336. to = this.totalPages;
  1337. from = to - 4;
  1338. }
  1339. }
  1340. if (this.totalPages >= 6) {
  1341. if (this.options.pageNumber >= 3) {
  1342. html.push(
  1343. sprintf('<li class="page-item page-first%s">',
  1344. 1 === this.options.pageNumber ? ' active' : ''),
  1345. '<a class="page-link" href="#">', 1, '</a>',
  1346. '</li>');
  1347. from++;
  1348. }
  1349. if (this.options.pageNumber >= 4) {
  1350. if (this.options.pageNumber == 4 || this.totalPages == 6 || this.totalPages == 7) {
  1351. from--;
  1352. } else {
  1353. html.push('<li class="page-item page-first-separator disabled">',
  1354. '<a class="page-link" href="#">...</a>',
  1355. '</li>');
  1356. }
  1357. to--;
  1358. }
  1359. }
  1360. if (this.totalPages >= 7) {
  1361. if (this.options.pageNumber >= (this.totalPages - 2)) {
  1362. from--;
  1363. }
  1364. }
  1365. if (this.totalPages == 6) {
  1366. if (this.options.pageNumber >= (this.totalPages - 2)) {
  1367. to++;
  1368. }
  1369. } else if (this.totalPages >= 7) {
  1370. if (this.totalPages == 7 || this.options.pageNumber >= (this.totalPages - 3)) {
  1371. to++;
  1372. }
  1373. }
  1374. for (i = from; i <= to; i++) {
  1375. html.push(sprintf('<li class="page-item%s">',
  1376. i === this.options.pageNumber ? ' active' : ''),
  1377. '<a class="page-link" href="#">', i, '</a>',
  1378. '</li>');
  1379. }
  1380. if (this.totalPages >= 8) {
  1381. if (this.options.pageNumber <= (this.totalPages - 4)) {
  1382. html.push('<li class="page-item page-last-separator disabled">',
  1383. '<a class="page-link" href="#">...</a>',
  1384. '</li>');
  1385. }
  1386. }
  1387. if (this.totalPages >= 6) {
  1388. if (this.options.pageNumber <= (this.totalPages - 3)) {
  1389. html.push(sprintf('<li class="page-item page-last%s">',
  1390. this.totalPages === this.options.pageNumber ? ' active' : ''),
  1391. '<a class="page-link" href="#">', this.totalPages, '</a>',
  1392. '</li>');
  1393. }
  1394. }
  1395. html.push(
  1396. sprintf('<li class="page-item page-next"><a class="page-link" href="#">%s</a></li>',
  1397. this.options.paginationNextText),
  1398. '</ul>',
  1399. '</div>');
  1400. }
  1401. this.$pagination.html(html.join(''));
  1402. if (!this.options.onlyInfoPagination) {
  1403. $pageList = this.$pagination.find('.page-list a');
  1404. $pre = this.$pagination.find('.page-pre');
  1405. $next = this.$pagination.find('.page-next');
  1406. $number = this.$pagination.find('.page-item').not('.page-next, .page-pre');
  1407. if (this.options.smartDisplay) {
  1408. if (this.totalPages <= 1) {
  1409. this.$pagination.find('div.pagination').hide();
  1410. }
  1411. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  1412. this.$pagination.find('span.page-list').hide();
  1413. }
  1414. // when data is empty, hide the pagination
  1415. this.$pagination[this.getData().length ? 'show' : 'hide']();
  1416. }
  1417. if (!this.options.paginationLoop) {
  1418. if (this.options.pageNumber === 1) {
  1419. $pre.addClass('disabled');
  1420. }
  1421. if (this.options.pageNumber === this.totalPages) {
  1422. $next.addClass('disabled');
  1423. }
  1424. }
  1425. if ($allSelected) {
  1426. this.options.pageSize = this.options.formatAllRows();
  1427. }
  1428. // removed the events for last and first, onPageNumber executeds the same logic
  1429. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  1430. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1431. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1432. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1433. }
  1434. };
  1435. BootstrapTable.prototype.updatePagination = function (event) {
  1436. // Fix #171: IE disabled button can be clicked bug.
  1437. if (event && $(event.currentTarget).hasClass('disabled')) {
  1438. return;
  1439. }
  1440. if (!this.options.maintainSelected) {
  1441. this.resetRows();
  1442. }
  1443. this.initPagination();
  1444. if (this.options.sidePagination === 'server') {
  1445. this.initServer();
  1446. } else {
  1447. this.initBody();
  1448. }
  1449. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1450. };
  1451. BootstrapTable.prototype.onPageListChange = function (event) {
  1452. event.preventDefault();
  1453. var $this = $(event.currentTarget);
  1454. $this.parent().addClass('active').siblings().removeClass('active');
  1455. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
  1456. this.options.formatAllRows() : +$this.text();
  1457. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1458. this.updatePagination(event);
  1459. return false;
  1460. };
  1461. BootstrapTable.prototype.onPagePre = function (event) {
  1462. event.preventDefault();
  1463. if ((this.options.pageNumber - 1) === 0) {
  1464. this.options.pageNumber = this.options.totalPages;
  1465. } else {
  1466. this.options.pageNumber--;
  1467. }
  1468. this.updatePagination(event);
  1469. return false;
  1470. };
  1471. BootstrapTable.prototype.onPageNext = function (event) {
  1472. event.preventDefault();
  1473. if ((this.options.pageNumber + 1) > this.options.totalPages) {
  1474. this.options.pageNumber = 1;
  1475. } else {
  1476. this.options.pageNumber++;
  1477. }
  1478. this.updatePagination(event);
  1479. return false;
  1480. };
  1481. BootstrapTable.prototype.onPageNumber = function (event) {
  1482. event.preventDefault();
  1483. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1484. return;
  1485. }
  1486. this.options.pageNumber = +$(event.currentTarget).text();
  1487. this.updatePagination(event);
  1488. return false;
  1489. };
  1490. BootstrapTable.prototype.initRow = function(item, i, data, parentDom) {
  1491. var that=this,
  1492. key,
  1493. html = [],
  1494. style = {},
  1495. csses = [],
  1496. data_ = '',
  1497. attributes = {},
  1498. htmlAttributes = [];
  1499. if ($.inArray(item, this.hiddenRows) > -1) {
  1500. return;
  1501. }
  1502. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1503. if (style && style.css) {
  1504. for (key in style.css) {
  1505. csses.push(key + ': ' + style.css[key]);
  1506. }
  1507. }
  1508. attributes = calculateObjectValue(this.options,
  1509. this.options.rowAttributes, [item, i], attributes);
  1510. if (attributes) {
  1511. for (key in attributes) {
  1512. htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
  1513. }
  1514. }
  1515. if (item._data && !$.isEmptyObject(item._data)) {
  1516. $.each(item._data, function(k, v) {
  1517. // ignore data-index
  1518. if (k === 'index') {
  1519. return;
  1520. }
  1521. data_ += sprintf(' data-%s="%s"', k, v);
  1522. });
  1523. }
  1524. html.push('<tr',
  1525. sprintf(' %s', htmlAttributes.join(' ')),
  1526. sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
  1527. sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
  1528. sprintf(' data-index="%s"', i),
  1529. sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
  1530. sprintf('%s', data_),
  1531. '>'
  1532. );
  1533. if (this.options.cardView) {
  1534. html.push(sprintf('<td colspan="%s"><div class="card-views">', this.header.fields.length));
  1535. }
  1536. if (!this.options.cardView && this.options.detailView) {
  1537. html.push('<td>');
  1538. if (calculateObjectValue(null, this.options.detailFilter, [i, item])) {
  1539. html.push('<a class="detail-icon" href="#">',
  1540. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
  1541. '</a>');
  1542. }
  1543. html.push('</td>');
  1544. }
  1545. $.each(this.header.fields, function(j, field) {
  1546. var text = '',
  1547. value_ = getItemField(item, field, that.options.escape),
  1548. value = '',
  1549. type = '',
  1550. cellStyle = {},
  1551. id_ = '',
  1552. class_ = that.header.classes[j],
  1553. data_ = '',
  1554. rowspan_ = '',
  1555. colspan_ = '',
  1556. title_ = '',
  1557. column = that.columns[j];
  1558. if (that.fromHtml && typeof value_ === 'undefined') {
  1559. if((!column.checkbox) && (!column.radio)) {
  1560. return;
  1561. }
  1562. }
  1563. if (!column.visible) {
  1564. return;
  1565. }
  1566. if (that.options.cardView && (!column.cardVisible)) {
  1567. return;
  1568. }
  1569. if (column.escape) {
  1570. value_ = escapeHTML(value_);
  1571. }
  1572. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  1573. // handle td's id and class
  1574. if (item['_' + field + '_id']) {
  1575. id_ = sprintf(' id="%s"', item['_' + field + '_id']);
  1576. }
  1577. if (item['_' + field + '_class']) {
  1578. class_ = sprintf(' class="%s"', item['_' + field + '_class']);
  1579. }
  1580. if (item['_' + field + '_rowspan']) {
  1581. rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1582. }
  1583. if (item['_' + field + '_colspan']) {
  1584. colspan_ = sprintf(' colspan="%s"', item['_' + field + '_colspan']);
  1585. }
  1586. if (item['_' + field + '_title']) {
  1587. title_ = sprintf(' title="%s"', item['_' + field + '_title']);
  1588. }
  1589. cellStyle = calculateObjectValue(that.header,
  1590. that.header.cellStyles[j], [value_, item, i, field], cellStyle);
  1591. if (cellStyle.classes) {
  1592. class_ = sprintf(' class="%s"', cellStyle.classes);
  1593. }
  1594. if (cellStyle.css) {
  1595. var csses_ = [];
  1596. for (var key in cellStyle.css) {
  1597. csses_.push(key + ': ' + cellStyle.css[key]);
  1598. }
  1599. style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
  1600. }
  1601. value = calculateObjectValue(column,
  1602. that.header.formatters[j], [value_, item, i, field], value_);
  1603. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1604. $.each(item['_' + field + '_data'], function(k, v) {
  1605. // ignore data-index
  1606. if (k === 'index') {
  1607. return;
  1608. }
  1609. data_ += sprintf(' data-%s="%s"', k, v);
  1610. });
  1611. }
  1612. if (column.checkbox || column.radio) {
  1613. type = column.checkbox ? 'checkbox' : type;
  1614. type = column.radio ? 'radio' : type;
  1615. text = [sprintf(that.options.cardView ?
  1616. '<div class="card-view %s">' : '<td class="bs-checkbox %s">', column['class'] || ''),
  1617. '<input' +
  1618. sprintf(' data-index="%s"', i) +
  1619. sprintf(' name="%s"', that.options.selectItemName) +
  1620. sprintf(' type="%s"', type) +
  1621. sprintf(' value="%s"', item[that.options.idField]) +
  1622. sprintf(' checked="%s"', value === true ||
  1623. (value_ || value && value.checked) ? 'checked' : undefined) +
  1624. sprintf(' disabled="%s"', !column.checkboxEnabled ||
  1625. (value && value.disabled) ? 'disabled' : undefined) +
  1626. ' />',
  1627. that.header.formatters[j] && typeof value === 'string' ? value : '',
  1628. that.options.cardView ? '</div>' : '</td>'
  1629. ].join('');
  1630. item[that.header.stateField] = value === true || (!!value_ || value && value.checked);
  1631. } else {
  1632. value = typeof value === 'undefined' || value === null ?
  1633. that.options.undefinedText : value;
  1634. text = that.options.cardView ? ['<div class="card-view">',
  1635. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  1636. getPropertyFromOther(that.columns, 'field', 'title', field)) : '',
  1637. sprintf('<span class="value">%s</span>', value),
  1638. '</div>'
  1639. ].join('') : [sprintf('<td%s %s %s %s %s %s %s>',
  1640. id_, class_, style, data_, rowspan_, colspan_, title_),
  1641. value,
  1642. '</td>'
  1643. ].join('');
  1644. // Hide empty data on Card view when smartDisplay is set to true.
  1645. if (that.options.cardView && that.options.smartDisplay && value === '') {
  1646. // Should set a placeholder for event binding correct fieldIndex
  1647. text = '<div class="card-view"></div>';
  1648. }
  1649. }
  1650. html.push(text);
  1651. });
  1652. if (this.options.cardView) {
  1653. html.push('</div></td>');
  1654. }
  1655. html.push('</tr>');
  1656. return html.join(' ');
  1657. };
  1658. BootstrapTable.prototype.initBody = function (fixedScroll) {
  1659. var that = this,
  1660. html = [],
  1661. data = this.getData();
  1662. this.trigger('pre-body', data);
  1663. this.$body = this.$el.find('>tbody');
  1664. if (!this.$body.length) {
  1665. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1666. }
  1667. //Fix #389 Bootstrap-table-flatJSON is not working
  1668. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1669. this.pageFrom = 1;
  1670. this.pageTo = data.length;
  1671. }
  1672. var trFragments = $(document.createDocumentFragment());
  1673. var hasTr;
  1674. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1675. var item = data[i];
  1676. var tr = this.initRow(item, i, data, trFragments);
  1677. hasTr = hasTr || !!tr;
  1678. if (tr&&tr!==true) {
  1679. trFragments.append(tr);
  1680. }
  1681. }
  1682. // show no records
  1683. if (!hasTr) {
  1684. trFragments.append('<tr class="no-records-found">' +
  1685. sprintf('<td colspan="%s">%s</td>',
  1686. this.$header.find('th').length,
  1687. this.options.formatNoMatches()) +
  1688. '</tr>');
  1689. }
  1690. this.$body.html(trFragments);
  1691. if (!fixedScroll) {
  1692. this.scrollTo(0);
  1693. }
  1694. // click to select by column
  1695. this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (e) {
  1696. var $td = $(this),
  1697. $tr = $td.parent(),
  1698. item = that.data[$tr.data('index')],
  1699. index = $td[0].cellIndex,
  1700. fields = that.getVisibleFields(),
  1701. field = fields[that.options.detailView && !that.options.cardView ? index - 1 : index],
  1702. column = that.columns[that.fieldsColumnsIndex[field]],
  1703. value = getItemField(item, field, that.options.escape);
  1704. if ($td.find('.detail-icon').length) {
  1705. return;
  1706. }
  1707. that.trigger(e.type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
  1708. that.trigger(e.type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
  1709. // if click to select - then trigger the checkbox/radio click
  1710. if (e.type === 'click' && that.options.clickToSelect && column.clickToSelect && that.options.ignoreClickToSelectOn(e.target)) {
  1711. var $selectItem = $tr.find(sprintf('[name="%s"]', that.options.selectItemName));
  1712. if ($selectItem.length) {
  1713. $selectItem[0].click(); // #144: .trigger('click') bug
  1714. }
  1715. }
  1716. });
  1717. this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) {
  1718. e.preventDefault();
  1719. var $this = $(this),
  1720. $tr = $this.parent().parent(),
  1721. index = $tr.data('index'),
  1722. row = data[index]; // Fix #980 Detail view, when searching, returns wrong row
  1723. // remove and update
  1724. if ($tr.next().is('tr.detail-view')) {
  1725. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailOpen));
  1726. that.trigger('collapse-row', index, row, $tr.next());
  1727. $tr.next().remove();
  1728. } else {
  1729. $this.find('i').attr('class', sprintf('%s %s', that.options.iconsPrefix, that.options.icons.detailClose));
  1730. $tr.after(sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.find('td').length));
  1731. var $element = $tr.next().find('td');
  1732. var content = calculateObjectValue(that.options, that.options.detailFormatter, [index, row, $element], '');
  1733. if ($element.length === 1) {
  1734. $element.append(content);
  1735. }
  1736. that.trigger('expand-row', index, row, $element);
  1737. }
  1738. that.resetView();
  1739. return false;
  1740. });
  1741. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  1742. this.$selectItem.off('click').on('click', function (event) {
  1743. event.stopImmediatePropagation();
  1744. var $this = $(this),
  1745. checked = $this.prop('checked'),
  1746. row = that.data[$this.data('index')];
  1747. if ($(this).is(':radio') || that.options.singleSelect) {
  1748. $.each(that.options.data, function (i, row) {
  1749. row[that.header.stateField] = false;
  1750. });
  1751. }
  1752. row[that.header.stateField] = checked;
  1753. if (that.options.singleSelect) {
  1754. that.$selectItem.not(this).each(function () {
  1755. that.data[$(this).data('index')][that.header.stateField] = false;
  1756. });
  1757. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  1758. }
  1759. that.updateSelected();
  1760. that.trigger(checked ? 'check' : 'uncheck', row, $this);
  1761. });
  1762. $.each(this.header.events, function (i, events) {
  1763. if (!events) {
  1764. return;
  1765. }
  1766. // fix bug, if events is defined with namespace
  1767. if (typeof events === 'string') {
  1768. events = calculateObjectValue(null, events);
  1769. }
  1770. var field = that.header.fields[i],
  1771. fieldIndex = $.inArray(field, that.getVisibleFields());
  1772. if (fieldIndex === -1) {
  1773. return;
  1774. }
  1775. if (that.options.detailView && !that.options.cardView) {
  1776. fieldIndex += 1;
  1777. }
  1778. for (var key in events) {
  1779. that.$body.find('>tr:not(.no-records-found)').each(function () {
  1780. var $tr = $(this),
  1781. $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(fieldIndex),
  1782. index = key.indexOf(' '),
  1783. name = key.substring(0, index),
  1784. el = key.substring(index + 1),
  1785. func = events[key];
  1786. $td.find(el).off(name).on(name, function (e) {
  1787. var index = $tr.data('index'),
  1788. row = that.data[index],
  1789. value = row[field];
  1790. func.apply(this, [e, value, row, index]);
  1791. });
  1792. });
  1793. }
  1794. });
  1795. this.updateSelected();
  1796. this.resetView();
  1797. this.trigger('post-body', data);
  1798. };
  1799. BootstrapTable.prototype.initServer = function (silent, query, url) {
  1800. var that = this,
  1801. data = {},
  1802. index = $.inArray(this.options.sortName, this.header.fields),
  1803. params = {
  1804. searchText: this.searchText,
  1805. sortName: this.options.sortName,
  1806. sortOrder: this.options.sortOrder
  1807. },
  1808. request;
  1809. if (this.header.sortNames[index]) {
  1810. params.sortName = this.header.sortNames[index];
  1811. }
  1812. if (this.options.pagination && this.options.sidePagination === 'server') {
  1813. params.pageSize = this.options.pageSize === this.options.formatAllRows() ?
  1814. this.options.totalRows : this.options.pageSize;
  1815. params.pageNumber = this.options.pageNumber;
  1816. }
  1817. if (!(url || this.options.url) && !this.options.ajax) {
  1818. return;
  1819. }
  1820. if (this.options.queryParamsType === 'limit') {
  1821. params = {
  1822. search: params.searchText,
  1823. sort: params.sortName,
  1824. order: params.sortOrder
  1825. };
  1826. if (this.options.pagination && this.options.sidePagination === 'server') {
  1827. params.offset = this.options.pageSize === this.options.formatAllRows() ?
  1828. 0 : this.options.pageSize * (this.options.pageNumber - 1);
  1829. params.limit = this.options.pageSize === this.options.formatAllRows() ?
  1830. this.options.totalRows : this.options.pageSize;
  1831. if (params.limit === 0) {
  1832. delete params.limit;
  1833. }
  1834. }
  1835. }
  1836. if (!($.isEmptyObject(this.filterColumnsPartial))) {
  1837. params.filter = JSON.stringify(this.filterColumnsPartial, null);
  1838. }
  1839. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  1840. $.extend(data, query || {});
  1841. // false to stop request
  1842. if (data === false) {
  1843. return;
  1844. }
  1845. if (!silent) {
  1846. this.$tableLoading.show();
  1847. }
  1848. request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
  1849. type: this.options.method,
  1850. url: url || this.options.url,
  1851. data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
  1852. JSON.stringify(data) : data,
  1853. cache: this.options.cache,
  1854. contentType: this.options.contentType,
  1855. dataType: this.options.dataType,
  1856. success: function (res) {
  1857. //---------------- console.log('dddddddddddddddddddddde', res);
  1858. if (that.options.pagination && res.result.totalCount && !res.result.items.length) {
  1859. that.options.pageNumber = Math.ceil(res.result.totalCount / that.options.pageSize);
  1860. that.initServer();
  1861. return;
  1862. }
  1863. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  1864. that.load(res);
  1865. that.trigger('load-success', res);
  1866. if (!silent) that.$tableLoading.hide();
  1867. },
  1868. error: function (res) {
  1869. var data = [];
  1870. if (that.options.sidePagination === 'server') {
  1871. data = {};
  1872. data[that.options.totalField] = 0;
  1873. data[that.options.dataField] = [];
  1874. }
  1875. that.load(data);
  1876. that.trigger('load-error', res.status, res);
  1877. if (!silent) that.$tableLoading.hide();
  1878. }
  1879. });
  1880. if (this.options.ajax) {
  1881. calculateObjectValue(this, this.options.ajax, [request], null);
  1882. } else {
  1883. if (this._xhr && this._xhr.readyState !== 4) {
  1884. this._xhr.abort();
  1885. }
  1886. this._xhr = $.ajax(request);
  1887. }
  1888. };
  1889. BootstrapTable.prototype.initSearchText = function () {
  1890. if (this.options.search) {
  1891. this.searchText = '';
  1892. if (this.options.searchText !== '') {
  1893. var $search = this.$toolbar.find('.search input');
  1894. $search.val(this.options.searchText);
  1895. this.onSearch({currentTarget: $search, firedByInitSearchText: true});
  1896. }
  1897. }
  1898. };
  1899. BootstrapTable.prototype.getCaret = function () {
  1900. var that = this;
  1901. $.each(this.$header.find('th'), function (i, th) {
  1902. $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === that.options.sortName ? that.options.sortOrder : 'both');
  1903. });
  1904. };
  1905. BootstrapTable.prototype.updateSelected = function () {
  1906. var checkAll = this.$selectItem.filter(':enabled').length &&
  1907. this.$selectItem.filter(':enabled').length ===
  1908. this.$selectItem.filter(':enabled').filter(':checked').length;
  1909. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  1910. this.$selectItem.each(function () {
  1911. $(this).closest('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  1912. });
  1913. };
  1914. BootstrapTable.prototype.updateRows = function () {
  1915. var that = this;
  1916. this.$selectItem.each(function () {
  1917. that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
  1918. });
  1919. };
  1920. BootstrapTable.prototype.resetRows = function () {
  1921. var that = this;
  1922. $.each(this.data, function (i, row) {
  1923. that.$selectAll.prop('checked', false);
  1924. that.$selectItem.prop('checked', false);
  1925. if (that.header.stateField) {
  1926. row[that.header.stateField] = false;
  1927. }
  1928. });
  1929. this.initHiddenRows();
  1930. };
  1931. BootstrapTable.prototype.trigger = function (name) {
  1932. var args = Array.prototype.slice.call(arguments, 1);
  1933. name += '.bs.table';
  1934. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  1935. this.$el.trigger($.Event(name), args);
  1936. this.options.onAll(name, args);
  1937. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  1938. };
  1939. BootstrapTable.prototype.resetHeader = function () {
  1940. // fix #61: the hidden table reset header bug.
  1941. // fix bug: get $el.css('width') error sometime (height = 500)
  1942. clearTimeout(this.timeoutId_);
  1943. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  1944. };
  1945. BootstrapTable.prototype.fitHeader = function () {
  1946. var that = this,
  1947. fixedBody,
  1948. scrollWidth,
  1949. focused,
  1950. focusedTemp;
  1951. if (that.$el.is(':hidden')) {
  1952. that.timeoutId_ = setTimeout($.proxy(that.fitHeader, that), 100);
  1953. return;
  1954. }
  1955. fixedBody = this.$tableBody.get(0);
  1956. scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
  1957. fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ?
  1958. getScrollBarWidth() : 0;
  1959. this.$el.css('margin-top', -this.$header.outerHeight());
  1960. focused = $(':focus');
  1961. if (focused.length > 0) {
  1962. var $th = focused.parents('th');
  1963. if ($th.length > 0) {
  1964. var dataField = $th.attr('data-field');
  1965. if (dataField !== undefined) {
  1966. var $headerTh = this.$header.find("[data-field='" + dataField + "']");
  1967. if ($headerTh.length > 0) {
  1968. $headerTh.find(":input").addClass("focus-temp");
  1969. }
  1970. }
  1971. }
  1972. }
  1973. this.$header_ = this.$header.clone(true, true);
  1974. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  1975. this.$tableHeader.css({
  1976. 'margin-right': scrollWidth
  1977. }).find('table').css('width', this.$el.outerWidth())
  1978. .html('').attr('class', this.$el.attr('class'))
  1979. .append(this.$header_);
  1980. focusedTemp = $('.focus-temp:visible:eq(0)');
  1981. if (focusedTemp.length > 0) {
  1982. focusedTemp.focus();
  1983. this.$header.find('.focus-temp').removeClass('focus-temp');
  1984. }
  1985. // fix bug: $.data() is not working as expected after $.append()
  1986. this.$header.find('th[data-field]').each(function (i) {
  1987. that.$header_.find(sprintf('th[data-field="%s"]', $(this).data('field'))).data($(this).data());
  1988. });
  1989. var visibleFields = this.getVisibleFields(),
  1990. $ths = this.$header_.find('th');
  1991. this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
  1992. var $this = $(this),
  1993. index = i;
  1994. if (that.options.detailView && !that.options.cardView) {
  1995. if (i === 0) {
  1996. that.$header_.find('th.detail').find('.fht-cell').width($this.innerWidth());
  1997. }
  1998. index = i - 1;
  1999. }
  2000. if (index === -1) {
  2001. return;
  2002. }
  2003. var $th = that.$header_.find(sprintf('th[data-field="%s"]', visibleFields[index]));
  2004. if ($th.length > 1) {
  2005. $th = $($ths[$this[0].cellIndex]);
  2006. }
  2007. var zoomWidth = $th.width() - $th.find('.fht-cell').width();
  2008. $th.find('.fht-cell').width($this.innerWidth() - zoomWidth);
  2009. });
  2010. this.horizontalScroll();
  2011. this.trigger('post-header');
  2012. };
  2013. BootstrapTable.prototype.resetFooter = function () {
  2014. var that = this,
  2015. data = that.getData(),
  2016. html = [];
  2017. if (!this.options.showFooter || this.options.cardView) { //do nothing
  2018. return;
  2019. }
  2020. if (!this.options.cardView && this.options.detailView) {
  2021. html.push('<td><div class="th-inner">&nbsp;</div><div class="fht-cell"></div></td>');
  2022. }
  2023. $.each(this.columns, function (i, column) {
  2024. var key,
  2025. falign = '', // footer align style
  2026. valign = '',
  2027. csses = [],
  2028. style = {},
  2029. class_ = sprintf(' class="%s"', column['class']);
  2030. if (!column.visible) {
  2031. return;
  2032. }
  2033. if (that.options.cardView && (!column.cardVisible)) {
  2034. return;
  2035. }
  2036. falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  2037. valign = sprintf('vertical-align: %s; ', column.valign);
  2038. style = calculateObjectValue(null, that.options.footerStyle);
  2039. if (style && style.css) {
  2040. for (key in style.css) {
  2041. csses.push(key + ': ' + style.css[key]);
  2042. }
  2043. }
  2044. html.push('<td', class_, sprintf(' style="%s"', falign + valign + csses.concat().join('; ')), '>');
  2045. html.push('<div class="th-inner">');
  2046. html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  2047. html.push('</div>');
  2048. html.push('<div class="fht-cell"></div>');
  2049. html.push('</div>');
  2050. html.push('</td>');
  2051. });
  2052. this.$tableFooter.find('tr').html(html.join(''));
  2053. this.$tableFooter.show();
  2054. clearTimeout(this.timeoutFooter_);
  2055. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
  2056. this.$el.is(':hidden') ? 100 : 0);
  2057. };
  2058. BootstrapTable.prototype.fitFooter = function () {
  2059. var that = this,
  2060. $footerTd,
  2061. elWidth,
  2062. scrollWidth;
  2063. clearTimeout(this.timeoutFooter_);
  2064. if (this.$el.is(':hidden')) {
  2065. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  2066. return;
  2067. }
  2068. elWidth = this.$el.css('width');
  2069. scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
  2070. this.$tableFooter.css({
  2071. 'margin-right': scrollWidth
  2072. }).find('table').css('width', elWidth)
  2073. .attr('class', this.$el.attr('class'));
  2074. $footerTd = this.$tableFooter.find('td');
  2075. this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i) {
  2076. var $this = $(this);
  2077. $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
  2078. });
  2079. this.horizontalScroll();
  2080. };
  2081. BootstrapTable.prototype.horizontalScroll = function () {
  2082. var that = this;
  2083. // horizontal scroll event
  2084. // TODO: it's probably better improving the layout than binding to scroll event
  2085. that.trigger('scroll-body');
  2086. this.$tableBody.off('scroll').on('scroll', function () {
  2087. if (that.options.showHeader && that.options.height) {
  2088. that.$tableHeader.scrollLeft($(this).scrollLeft());
  2089. }
  2090. if (that.options.showFooter && !that.options.cardView) {
  2091. that.$tableFooter.scrollLeft($(this).scrollLeft());
  2092. }
  2093. });
  2094. };
  2095. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  2096. if (index === -1) {
  2097. return;
  2098. }
  2099. this.columns[index].visible = checked;
  2100. this.initHeader();
  2101. this.initSearch();
  2102. this.initPagination();
  2103. this.initBody();
  2104. if (this.options.showColumns) {
  2105. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  2106. if (needUpdate) {
  2107. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  2108. }
  2109. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  2110. $items.filter(':checked').prop('disabled', true);
  2111. }
  2112. }
  2113. };
  2114. BootstrapTable.prototype.getVisibleFields = function () {
  2115. var that = this,
  2116. visibleFields = [];
  2117. $.each(this.header.fields, function (j, field) {
  2118. var column = that.columns[that.fieldsColumnsIndex[field]];
  2119. if (!column.visible) {
  2120. return;
  2121. }
  2122. visibleFields.push(field);
  2123. });
  2124. return visibleFields;
  2125. };
  2126. // PUBLIC FUNCTION DEFINITION
  2127. // =======================
  2128. BootstrapTable.prototype.resetView = function (params) {
  2129. var padding = 0;
  2130. if (params && params.height) {
  2131. this.options.height = params.height;
  2132. }
  2133. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  2134. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  2135. if (this.options.height) {
  2136. var toolbarHeight = this.$toolbar.outerHeight(true),
  2137. paginationHeight = this.$pagination.outerHeight(true),
  2138. height = this.options.height - toolbarHeight - paginationHeight;
  2139. this.$tableContainer.css('height', height + 'px');
  2140. }
  2141. if (this.options.cardView) {
  2142. // remove the element css
  2143. this.$el.css('margin-top', '0');
  2144. this.$tableContainer.css('padding-bottom', '0');
  2145. this.$tableFooter.hide();
  2146. return;
  2147. }
  2148. if (this.options.showHeader && this.options.height) {
  2149. this.$tableHeader.show();
  2150. this.resetHeader();
  2151. padding += this.$header.outerHeight();
  2152. } else {
  2153. this.$tableHeader.hide();
  2154. this.trigger('post-header');
  2155. }
  2156. if (this.options.showFooter) {
  2157. this.resetFooter();
  2158. if (this.options.height) {
  2159. padding += this.$tableFooter.outerHeight() + 1;
  2160. }
  2161. }
  2162. // Assign the correct sortable arrow
  2163. this.getCaret();
  2164. this.$tableContainer.css('padding-bottom', padding + 'px');
  2165. this.trigger('reset-view');
  2166. };
  2167. BootstrapTable.prototype.getData = function (useCurrentPage) {
  2168. var data = this.options.data;
  2169. if (this.searchText || this.options.sortName || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) {
  2170. data = this.data;
  2171. }
  2172. if (useCurrentPage) {
  2173. return data.slice(this.pageFrom - 1, this.pageTo);
  2174. }
  2175. return data;
  2176. };
  2177. BootstrapTable.prototype.load = function (data) {
  2178. var fixedScroll = false;
  2179. // #431: support pagination
  2180. if (this.options.pagination && this.options.sidePagination === 'server') {
  2181. this.options.totalRows = data[this.options.totalField];
  2182. fixedScroll = data.fixedScroll;
  2183. data = data[this.options.dataField];
  2184. } else if (!$.isArray(data)) { // support fixedScroll
  2185. fixedScroll = data.fixedScroll;
  2186. data = data.data;
  2187. }
  2188. this.initData(data);
  2189. this.initSearch();
  2190. this.initPagination();
  2191. this.initBody(fixedScroll);
  2192. };
  2193. BootstrapTable.prototype.append = function (data) {
  2194. this.initData(data, 'append');
  2195. this.initSearch();
  2196. this.initPagination();
  2197. this.initSort();
  2198. this.initBody(true);
  2199. };
  2200. BootstrapTable.prototype.prepend = function (data) {
  2201. this.initData(data, 'prepend');
  2202. this.initSearch();
  2203. this.initPagination();
  2204. this.initSort();
  2205. this.initBody(true);
  2206. };
  2207. BootstrapTable.prototype.remove = function (params) {
  2208. var len = this.options.data.length,
  2209. i, row;
  2210. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  2211. return;
  2212. }
  2213. for (i = len - 1; i >= 0; i--) {
  2214. row = this.options.data[i];
  2215. if (!row.hasOwnProperty(params.field)) {
  2216. continue;
  2217. }
  2218. if ($.inArray(row[params.field], params.values) !== -1) {
  2219. this.options.data.splice(i, 1);
  2220. if (this.options.sidePagination === 'server') {
  2221. this.options.totalRows -= 1;
  2222. }
  2223. }
  2224. }
  2225. if (len === this.options.data.length) {
  2226. return;
  2227. }
  2228. this.initSearch();
  2229. this.initPagination();
  2230. this.initSort();
  2231. this.initBody(true);
  2232. };
  2233. BootstrapTable.prototype.removeAll = function () {
  2234. if (this.options.data.length > 0) {
  2235. this.options.data.splice(0, this.options.data.length);
  2236. this.initSearch();
  2237. this.initPagination();
  2238. this.initBody(true);
  2239. }
  2240. };
  2241. BootstrapTable.prototype.getRowByUniqueId = function (id) {
  2242. var uniqueId = this.options.uniqueId,
  2243. len = this.options.data.length,
  2244. dataRow = null,
  2245. i, row, rowUniqueId;
  2246. for (i = len - 1; i >= 0; i--) {
  2247. row = this.options.data[i];
  2248. if (row.hasOwnProperty(uniqueId)) { // uniqueId is a column
  2249. rowUniqueId = row[uniqueId];
  2250. } else if(row._data.hasOwnProperty(uniqueId)) { // uniqueId is a row data property
  2251. rowUniqueId = row._data[uniqueId];
  2252. } else {
  2253. continue;
  2254. }
  2255. if (typeof rowUniqueId === 'string') {
  2256. id = id.toString();
  2257. } else if (typeof rowUniqueId === 'number') {
  2258. if ((Number(rowUniqueId) === rowUniqueId) && (rowUniqueId % 1 === 0)) {
  2259. id = parseInt(id);
  2260. } else if ((rowUniqueId === Number(rowUniqueId)) && (rowUniqueId !== 0)) {
  2261. id = parseFloat(id);
  2262. }
  2263. }
  2264. if (rowUniqueId === id) {
  2265. dataRow = row;
  2266. break;
  2267. }
  2268. }
  2269. return dataRow;
  2270. };
  2271. BootstrapTable.prototype.removeByUniqueId = function (id) {
  2272. var len = this.options.data.length,
  2273. row = this.getRowByUniqueId(id);
  2274. if (row) {
  2275. this.options.data.splice(this.options.data.indexOf(row), 1);
  2276. }
  2277. if (len === this.options.data.length) {
  2278. return;
  2279. }
  2280. this.initSearch();
  2281. this.initPagination();
  2282. this.initBody(true);
  2283. };
  2284. BootstrapTable.prototype.updateByUniqueId = function (params) {
  2285. var that = this;
  2286. var allParams = $.isArray(params) ? params : [ params ];
  2287. $.each(allParams, function(i, params) {
  2288. var rowId;
  2289. if (!params.hasOwnProperty('id') || !params.hasOwnProperty('row')) {
  2290. return;
  2291. }
  2292. rowId = $.inArray(that.getRowByUniqueId(params.id), that.options.data);
  2293. if (rowId === -1) {
  2294. return;
  2295. }
  2296. $.extend(that.options.data[rowId], params.row);
  2297. });
  2298. this.initSearch();
  2299. this.initPagination();
  2300. this.initSort();
  2301. this.initBody(true);
  2302. };
  2303. BootstrapTable.prototype.refreshColumnTitle = function (params) {
  2304. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) {
  2305. return;
  2306. }
  2307. this.columns[this.fieldsColumnsIndex[params.field]].title =
  2308. this.options.escape ? escapeHTML(params.title) : params.title;
  2309. if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
  2310. var header = this.options.height !== undefined ? this.$tableHeader : this.$header;
  2311. header.find('th[data-field]').each(function (i) {
  2312. if ($(this).data('field') === params.field) {
  2313. $($(this).find(".th-inner")[0]).text(params.title);
  2314. return false;
  2315. }
  2316. });
  2317. }
  2318. };
  2319. BootstrapTable.prototype.insertRow = function (params) {
  2320. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  2321. return;
  2322. }
  2323. this.options.data.splice(params.index, 0, params.row);
  2324. this.initSearch();
  2325. this.initPagination();
  2326. this.initSort();
  2327. this.initBody(true);
  2328. };
  2329. BootstrapTable.prototype.updateRow = function (params) {
  2330. var that = this;
  2331. var allParams = $.isArray(params) ? params : [ params ];
  2332. $.each(allParams, function(i, params) {
  2333. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  2334. return;
  2335. }
  2336. $.extend(that.options.data[params.index], params.row);
  2337. });
  2338. this.initSearch();
  2339. this.initPagination();
  2340. this.initSort();
  2341. this.initBody(true);
  2342. };
  2343. BootstrapTable.prototype.initHiddenRows = function () {
  2344. this.hiddenRows = [];
  2345. };
  2346. BootstrapTable.prototype.showRow = function (params) {
  2347. this.toggleRow(params, true);
  2348. };
  2349. BootstrapTable.prototype.hideRow = function (params) {
  2350. this.toggleRow(params, false);
  2351. };
  2352. BootstrapTable.prototype.toggleRow = function (params, visible) {
  2353. var row, index;
  2354. if (params.hasOwnProperty('index')) {
  2355. row = this.getData()[params.index];
  2356. } else if (params.hasOwnProperty('uniqueId')) {
  2357. row = this.getRowByUniqueId(params.uniqueId);
  2358. }
  2359. if (!row) {
  2360. return;
  2361. }
  2362. index = $.inArray(row, this.hiddenRows);
  2363. if (!visible && index === -1) {
  2364. this.hiddenRows.push(row);
  2365. } else if (visible && index > -1) {
  2366. this.hiddenRows.splice(index, 1);
  2367. }
  2368. this.initBody(true);
  2369. };
  2370. BootstrapTable.prototype.getHiddenRows = function (show) {
  2371. var that = this,
  2372. data = this.getData(),
  2373. rows = [];
  2374. $.each(data, function (i, row) {
  2375. if ($.inArray(row, that.hiddenRows) > -1) {
  2376. rows.push(row);
  2377. }
  2378. });
  2379. this.hiddenRows = rows;
  2380. return rows;
  2381. };
  2382. BootstrapTable.prototype.mergeCells = function (options) {
  2383. var row = options.index,
  2384. col = $.inArray(options.field, this.getVisibleFields()),
  2385. rowspan = options.rowspan || 1,
  2386. colspan = options.colspan || 1,
  2387. i, j,
  2388. $tr = this.$body.find('>tr'),
  2389. $td;
  2390. if (this.options.detailView && !this.options.cardView) {
  2391. col += 1;
  2392. }
  2393. $td = $tr.eq(row).find('>td').eq(col);
  2394. if (row < 0 || col < 0 || row >= this.data.length) {
  2395. return;
  2396. }
  2397. for (i = row; i < row + rowspan; i++) {
  2398. for (j = col; j < col + colspan; j++) {
  2399. $tr.eq(i).find('>td').eq(j).hide();
  2400. }
  2401. }
  2402. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  2403. };
  2404. BootstrapTable.prototype.updateCell = function (params) {
  2405. if (!params.hasOwnProperty('index') ||
  2406. !params.hasOwnProperty('field') ||
  2407. !params.hasOwnProperty('value')) {
  2408. return;
  2409. }
  2410. this.data[params.index][params.field] = params.value;
  2411. if (params.reinit === false) {
  2412. return;
  2413. }
  2414. this.initSort();
  2415. this.initBody(true);
  2416. };
  2417. BootstrapTable.prototype.updateCellById = function (params) {
  2418. var that = this;
  2419. if (!params.hasOwnProperty('id') ||
  2420. !params.hasOwnProperty('field') ||
  2421. !params.hasOwnProperty('value')) {
  2422. return;
  2423. }
  2424. var allParams = $.isArray(params) ? params : [ params ];
  2425. $.each(allParams, function(i, params) {
  2426. var rowId;
  2427. rowId = $.inArray(that.getRowByUniqueId(params.id), that.options.data);
  2428. if (rowId === -1) {
  2429. return;
  2430. }
  2431. that.data[rowId][params.field] = params.value;
  2432. });
  2433. if (params.reinit === false) {
  2434. return;
  2435. }
  2436. this.initSort();
  2437. this.initBody(true);
  2438. };
  2439. BootstrapTable.prototype.getOptions = function () {
  2440. //Deep copy
  2441. return $.extend(true, {}, this.options);
  2442. };
  2443. BootstrapTable.prototype.getSelections = function () {
  2444. var that = this;
  2445. return $.grep(this.options.data, function (row) {
  2446. // fix #2424: from html with checkbox
  2447. return row[that.header.stateField] === true;
  2448. });
  2449. };
  2450. BootstrapTable.prototype.getAllSelections = function () {
  2451. var that = this;
  2452. return $.grep(this.options.data, function (row) {
  2453. return row[that.header.stateField];
  2454. });
  2455. };
  2456. BootstrapTable.prototype.checkAll = function () {
  2457. this.checkAll_(true);
  2458. };
  2459. BootstrapTable.prototype.uncheckAll = function () {
  2460. this.checkAll_(false);
  2461. };
  2462. BootstrapTable.prototype.checkInvert = function () {
  2463. var that = this;
  2464. var rows = that.$selectItem.filter(':enabled');
  2465. var checked = rows.filter(':checked');
  2466. rows.each(function() {
  2467. $(this).prop('checked', !$(this).prop('checked'));
  2468. });
  2469. that.updateRows();
  2470. that.updateSelected();
  2471. that.trigger('uncheck-some', checked);
  2472. checked = that.getSelections();
  2473. that.trigger('check-some', checked);
  2474. };
  2475. BootstrapTable.prototype.checkAll_ = function (checked) {
  2476. var rows;
  2477. if (!checked) {
  2478. rows = this.getSelections();
  2479. }
  2480. this.$selectAll.add(this.$selectAll_).prop('checked', checked);
  2481. this.$selectItem.filter(':enabled').prop('checked', checked);
  2482. this.updateRows();
  2483. if (checked) {
  2484. rows = this.getSelections();
  2485. }
  2486. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  2487. };
  2488. BootstrapTable.prototype.check = function (index) {
  2489. this.check_(true, index);
  2490. };
  2491. BootstrapTable.prototype.uncheck = function (index) {
  2492. this.check_(false, index);
  2493. };
  2494. BootstrapTable.prototype.check_ = function (checked, index) {
  2495. var $el = this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  2496. this.data[index][this.header.stateField] = checked;
  2497. this.updateSelected();
  2498. this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
  2499. };
  2500. BootstrapTable.prototype.checkBy = function (obj) {
  2501. this.checkBy_(true, obj);
  2502. };
  2503. BootstrapTable.prototype.uncheckBy = function (obj) {
  2504. this.checkBy_(false, obj);
  2505. };
  2506. BootstrapTable.prototype.checkBy_ = function (checked, obj) {
  2507. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  2508. return;
  2509. }
  2510. var that = this,
  2511. rows = [];
  2512. $.each(this.options.data, function (index, row) {
  2513. if (!row.hasOwnProperty(obj.field)) {
  2514. return false;
  2515. }
  2516. if ($.inArray(row[obj.field], obj.values) !== -1) {
  2517. var $el = that.$selectItem.filter(':enabled')
  2518. .filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  2519. row[that.header.stateField] = checked;
  2520. rows.push(row);
  2521. that.trigger(checked ? 'check' : 'uncheck', row, $el);
  2522. }
  2523. });
  2524. this.updateSelected();
  2525. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  2526. };
  2527. BootstrapTable.prototype.destroy = function () {
  2528. this.$el.insertBefore(this.$container);
  2529. $(this.options.toolbar).insertBefore(this.$el);
  2530. this.$container.next().remove();
  2531. this.$container.remove();
  2532. this.$el.html(this.$el_.html())
  2533. .css('margin-top', '0')
  2534. .attr('class', this.$el_.attr('class') || ''); // reset the class
  2535. };
  2536. BootstrapTable.prototype.showLoading = function () {
  2537. this.$tableLoading.show();
  2538. };
  2539. BootstrapTable.prototype.hideLoading = function () {
  2540. this.$tableLoading.hide();
  2541. };
  2542. BootstrapTable.prototype.togglePagination = function () {
  2543. this.options.pagination = !this.options.pagination;
  2544. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  2545. if (this.options.pagination) {
  2546. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
  2547. } else {
  2548. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
  2549. }
  2550. this.updatePagination();
  2551. };
  2552. BootstrapTable.prototype.toggleFullscreen = function () {
  2553. this.$el.closest('.bootstrap-table').toggleClass('fullscreen');
  2554. };
  2555. BootstrapTable.prototype.refresh = function (params) {
  2556. if (params && params.url) {
  2557. this.options.url = params.url;
  2558. }
  2559. if (params && params.pageNumber) {
  2560. this.options.pageNumber = params.pageNumber;
  2561. }
  2562. if (params && params.pageSize) {
  2563. this.options.pageSize = params.pageSize;
  2564. }
  2565. this.initServer(params && params.silent,
  2566. params && params.query, params && params.url);
  2567. this.trigger('refresh', params);
  2568. };
  2569. BootstrapTable.prototype.resetWidth = function () {
  2570. if (this.options.showHeader && this.options.height) {
  2571. this.fitHeader();
  2572. }
  2573. if (this.options.showFooter && !this.options.cardView) {
  2574. this.fitFooter();
  2575. }
  2576. };
  2577. BootstrapTable.prototype.showColumn = function (field) {
  2578. this.toggleColumn(this.fieldsColumnsIndex[field], true, true);
  2579. };
  2580. BootstrapTable.prototype.hideColumn = function (field) {
  2581. this.toggleColumn(this.fieldsColumnsIndex[field], false, true);
  2582. };
  2583. BootstrapTable.prototype.getHiddenColumns = function () {
  2584. return $.grep(this.columns, function (column) {
  2585. return !column.visible;
  2586. });
  2587. };
  2588. BootstrapTable.prototype.getVisibleColumns = function () {
  2589. return $.grep(this.columns, function (column) {
  2590. return column.visible;
  2591. });
  2592. };
  2593. BootstrapTable.prototype.toggleAllColumns = function (visible) {
  2594. var that = this;
  2595. $.each(this.columns, function (i, column) {
  2596. that.columns[i].visible = visible;
  2597. });
  2598. this.initHeader();
  2599. this.initSearch();
  2600. this.initPagination();
  2601. this.initBody();
  2602. if (this.options.showColumns) {
  2603. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  2604. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  2605. $items.filter(':checked').prop('disabled', true);
  2606. }
  2607. }
  2608. };
  2609. BootstrapTable.prototype.showAllColumns = function () {
  2610. this.toggleAllColumns(true);
  2611. };
  2612. BootstrapTable.prototype.hideAllColumns = function () {
  2613. this.toggleAllColumns(false);
  2614. };
  2615. BootstrapTable.prototype.filterBy = function (columns) {
  2616. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  2617. this.options.pageNumber = 1;
  2618. this.initSearch();
  2619. this.updatePagination();
  2620. };
  2621. BootstrapTable.prototype.scrollTo = function (value) {
  2622. if (typeof value === 'string') {
  2623. value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
  2624. }
  2625. if (typeof value === 'number') {
  2626. this.$tableBody.scrollTop(value);
  2627. }
  2628. if (typeof value === 'undefined') {
  2629. return this.$tableBody.scrollTop();
  2630. }
  2631. };
  2632. BootstrapTable.prototype.getScrollPosition = function () {
  2633. return this.scrollTo();
  2634. };
  2635. BootstrapTable.prototype.selectPage = function (page) {
  2636. if (page > 0 && page <= this.options.totalPages) {
  2637. this.options.pageNumber = page;
  2638. this.updatePagination();
  2639. }
  2640. };
  2641. BootstrapTable.prototype.prevPage = function () {
  2642. if (this.options.pageNumber > 1) {
  2643. this.options.pageNumber--;
  2644. this.updatePagination();
  2645. }
  2646. };
  2647. BootstrapTable.prototype.nextPage = function () {
  2648. if (this.options.pageNumber < this.options.totalPages) {
  2649. this.options.pageNumber++;
  2650. this.updatePagination();
  2651. }
  2652. };
  2653. BootstrapTable.prototype.toggleView = function () {
  2654. this.options.cardView = !this.options.cardView;
  2655. this.initHeader();
  2656. // Fixed remove toolbar when click cardView button.
  2657. //that.initToolbar();
  2658. var $icon = this.$toolbar.find('button[name="toggle"] i');
  2659. if (this.options.cardView) {
  2660. $icon.removeClass(this.options.icons.toggleOff);
  2661. $icon.addClass(this.options.icons.toggleOn);
  2662. } else {
  2663. $icon.removeClass(this.options.icons.toggleOn);
  2664. $icon.addClass(this.options.icons.toggleOff);
  2665. }
  2666. this.initBody();
  2667. this.trigger('toggle', this.options.cardView);
  2668. };
  2669. BootstrapTable.prototype.refreshOptions = function (options) {
  2670. //If the objects are equivalent then avoid the call of destroy / init methods
  2671. if (compareObjects(this.options, options, true)) {
  2672. return;
  2673. }
  2674. this.options = $.extend(this.options, options);
  2675. this.trigger('refresh-options', this.options);
  2676. this.destroy();
  2677. this.init();
  2678. };
  2679. BootstrapTable.prototype.resetSearch = function (text) {
  2680. var $search = this.$toolbar.find('.search input');
  2681. $search.val(text || '');
  2682. this.onSearch({currentTarget: $search});
  2683. };
  2684. BootstrapTable.prototype.expandRow_ = function (expand, index) {
  2685. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', index));
  2686. if ($tr.next().is('tr.detail-view') === (expand ? false : true)) {
  2687. $tr.find('> td > .detail-icon').click();
  2688. }
  2689. };
  2690. BootstrapTable.prototype.expandRow = function (index) {
  2691. this.expandRow_(true, index);
  2692. };
  2693. BootstrapTable.prototype.collapseRow = function (index) {
  2694. this.expandRow_(false, index);
  2695. };
  2696. BootstrapTable.prototype.expandAllRows = function (isSubTable) {
  2697. if (isSubTable) {
  2698. var $tr = this.$body.find(sprintf('> tr[data-index="%s"]', 0)),
  2699. that = this,
  2700. detailIcon = null,
  2701. executeInterval = false,
  2702. idInterval = -1;
  2703. if (!$tr.next().is('tr.detail-view')) {
  2704. $tr.find('> td > .detail-icon').click();
  2705. executeInterval = true;
  2706. } else if (!$tr.next().next().is('tr.detail-view')) {
  2707. $tr.next().find(".detail-icon").click();
  2708. executeInterval = true;
  2709. }
  2710. if (executeInterval) {
  2711. try {
  2712. idInterval = setInterval(function () {
  2713. detailIcon = that.$body.find("tr.detail-view").last().find(".detail-icon");
  2714. if (detailIcon.length > 0) {
  2715. detailIcon.click();
  2716. } else {
  2717. clearInterval(idInterval);
  2718. }
  2719. }, 1);
  2720. } catch (ex) {
  2721. clearInterval(idInterval);
  2722. }
  2723. }
  2724. } else {
  2725. var trs = this.$body.children();
  2726. for (var i = 0; i < trs.length; i++) {
  2727. this.expandRow_(true, $(trs[i]).data("index"));
  2728. }
  2729. }
  2730. };
  2731. BootstrapTable.prototype.collapseAllRows = function (isSubTable) {
  2732. if (isSubTable) {
  2733. this.expandRow_(false, 0);
  2734. } else {
  2735. var trs = this.$body.children();
  2736. for (var i = 0; i < trs.length; i++) {
  2737. this.expandRow_(false, $(trs[i]).data("index"));
  2738. }
  2739. }
  2740. };
  2741. BootstrapTable.prototype.updateFormatText = function (name, text) {
  2742. if (this.options[sprintf('format%s', name)]) {
  2743. if (typeof text === 'string') {
  2744. this.options[sprintf('format%s', name)] = function () {
  2745. return text;
  2746. };
  2747. } else if (typeof text === 'function') {
  2748. this.options[sprintf('format%s', name)] = text;
  2749. }
  2750. }
  2751. this.initToolbar();
  2752. this.initPagination();
  2753. this.initBody();
  2754. };
  2755. // BOOTSTRAP TABLE PLUGIN DEFINITION
  2756. // =======================
  2757. var allowedMethods = [
  2758. 'getOptions',
  2759. 'getSelections', 'getAllSelections', 'getData',
  2760. 'load', 'append', 'prepend', 'remove', 'removeAll',
  2761. 'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId',
  2762. 'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows',
  2763. 'mergeCells', 'refreshColumnTitle',
  2764. 'checkAll', 'uncheckAll', 'checkInvert',
  2765. 'check', 'uncheck',
  2766. 'checkBy', 'uncheckBy',
  2767. 'refresh',
  2768. 'resetView',
  2769. 'resetWidth',
  2770. 'destroy',
  2771. 'showLoading', 'hideLoading',
  2772. 'showColumn', 'hideColumn', 'getHiddenColumns', 'getVisibleColumns',
  2773. 'showAllColumns', 'hideAllColumns',
  2774. 'filterBy',
  2775. 'scrollTo',
  2776. 'getScrollPosition',
  2777. 'selectPage', 'prevPage', 'nextPage',
  2778. 'togglePagination',
  2779. 'toggleView',
  2780. 'refreshOptions',
  2781. 'resetSearch',
  2782. 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows',
  2783. 'updateFormatText', 'updateCellById'
  2784. ];
  2785. $.fn.bootstrapTable = function (option) {
  2786. var value,
  2787. args = Array.prototype.slice.call(arguments, 1);
  2788. this.each(function () {
  2789. var $this = $(this),
  2790. data = $this.data('bootstrap.table'),
  2791. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  2792. typeof option === 'object' && option);
  2793. if (typeof option === 'string') {
  2794. if ($.inArray(option, allowedMethods) < 0) {
  2795. throw new Error("Unknown method: " + option);
  2796. }
  2797. if (!data) {
  2798. return;
  2799. }
  2800. value = data[option].apply(data, args);
  2801. if (option === 'destroy') {
  2802. $this.removeData('bootstrap.table');
  2803. }
  2804. }
  2805. if (!data) {
  2806. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  2807. }
  2808. });
  2809. return typeof value === 'undefined' ? this : value;
  2810. };
  2811. $.fn.bootstrapTable.Constructor = BootstrapTable;
  2812. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  2813. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  2814. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  2815. $.fn.bootstrapTable.methods = allowedMethods;
  2816. $.fn.bootstrapTable.utils = {
  2817. bootstrapVersion: bootstrapVersion,
  2818. sprintf: sprintf,
  2819. compareObjects: compareObjects,
  2820. calculateObjectValue: calculateObjectValue,
  2821. getItemField: getItemField,
  2822. objectKeys: objectKeys,
  2823. isIEBrowser: isIEBrowser
  2824. };
  2825. // BOOTSTRAP TABLE INIT
  2826. // =======================
  2827. $(function () {
  2828. $('[data-toggle="table"]').bootstrapTable();
  2829. });
  2830. })(jQuery);