bootstrap-table.js 101 KB

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