bootstrap-table.js 100 KB

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