bootstrap-table-all.js 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862
  1. /**
  2. * @author zhixin wen <wenzhixin2010@gmail.com>
  3. * version: 1.8.0
  4. * https://github.com/wenzhixin/bootstrap-table/
  5. */
  6. !function ($) {
  7. 'use strict';
  8. // TOOLS DEFINITION
  9. // ======================
  10. var cellHeight = 37, // update css if changed
  11. cachedWidth = null,
  12. arrowAsc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ' +
  13. '0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBd' +
  14. 'qEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVo' +
  15. 'AADeemwtPcZI2wAAAABJRU5ErkJggg==',
  16. arrowBoth = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAQAAADYWf5HAAAAkElEQVQoz7X' +
  17. 'QMQ5AQBCF4dWQSJxC5wwax1Cq1e7BAdxD5SL+Tq/QCM1oNiJidwox0355mXnG/DrEtIQ6azio' +
  18. 'NZQxI0ykPhTQIwhCR+BmBYtlK7kLJYwWCcJA9M4qdrZrd8pPjZWPtOqdRQy320YSV17OatFC4eut' +
  19. 's6z39GYMKRPCTKY9UnPQ6P+GtMRfGtPnBCiqhAeJPmkqAAAAAElFTkSuQmCC',
  20. arrowDesc = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWj' +
  21. 'YBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJ' +
  22. 'zcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII= ';
  23. // it only does '%s', and return '' when arguments are undefined
  24. var sprintf = function (str) {
  25. var args = arguments,
  26. flag = true,
  27. i = 1;
  28. str = str.replace(/%s/g, function () {
  29. var arg = args[i++];
  30. if (typeof arg === 'undefined') {
  31. flag = false;
  32. return '';
  33. }
  34. return arg;
  35. });
  36. return flag ? str : '';
  37. };
  38. var getPropertyFromOther = function (list, from, to, value) {
  39. var result = '';
  40. $.each(list, function (i, item) {
  41. if (item[from] === value) {
  42. result = item[to];
  43. return false;
  44. }
  45. return true;
  46. });
  47. return result;
  48. };
  49. var getFieldIndex = function (columns, field) {
  50. var index = -1;
  51. $.each(columns, function (i, column) {
  52. if (column.field === field) {
  53. index = i;
  54. return false;
  55. }
  56. return true;
  57. });
  58. return index;
  59. };
  60. var getScrollBarWidth = function () {
  61. if (cachedWidth === null) {
  62. var inner = $('<p/>').addClass('fixed-table-scroll-inner'),
  63. outer = $('<div/>').addClass('fixed-table-scroll-outer'),
  64. w1, w2;
  65. outer.append(inner);
  66. $('body').append(outer);
  67. w1 = inner[0].offsetWidth;
  68. outer.css('overflow', 'scroll');
  69. w2 = inner[0].offsetWidth;
  70. if (w1 === w2) {
  71. w2 = outer[0].clientWidth;
  72. }
  73. outer.remove();
  74. cachedWidth = w1 - w2;
  75. }
  76. return cachedWidth;
  77. };
  78. var calculateObjectValue = function (self, name, args, defaultValue) {
  79. if (typeof name === 'string') {
  80. // support obj.func1.func2
  81. var names = name.split('.');
  82. if (names.length > 1) {
  83. name = window;
  84. $.each(names, function (i, f) {
  85. name = name[f];
  86. });
  87. } else {
  88. name = window[name];
  89. }
  90. }
  91. if (typeof name === 'object') {
  92. return name;
  93. }
  94. if (typeof name === 'function') {
  95. return name.apply(self, args);
  96. }
  97. return defaultValue;
  98. };
  99. var escapeHTML = function (text) {
  100. if (typeof text === 'string') {
  101. return text
  102. .replace(/&/g, "&amp;")
  103. .replace(/</g, "&lt;")
  104. .replace(/>/g, "&gt;")
  105. .replace(/"/g, "&quot;")
  106. .replace(/'/g, "&#039;");
  107. }
  108. return text;
  109. };
  110. var getRealHeight = function ($el) {
  111. var height = 0;
  112. $el.children().each(function () {
  113. if (height < $(this).outerHeight(true)) {
  114. height = $(this).outerHeight(true);
  115. }
  116. });
  117. return height;
  118. };
  119. var getRealDataAttr = function (dataAttr) {
  120. for (var attr in dataAttr) {
  121. var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
  122. if (auxAttr !== attr) {
  123. dataAttr[auxAttr] = dataAttr[attr];
  124. delete dataAttr[attr];
  125. }
  126. }
  127. return dataAttr;
  128. };
  129. // BOOTSTRAP TABLE CLASS DEFINITION
  130. // ======================
  131. var BootstrapTable = function (el, options) {
  132. this.options = options;
  133. this.$el = $(el);
  134. this.$el_ = this.$el.clone();
  135. this.timeoutId_ = 0;
  136. this.timeoutFooter_ = 0;
  137. this.init();
  138. };
  139. BootstrapTable.DEFAULTS = {
  140. classes: 'table table-hover',
  141. height: undefined,
  142. undefinedText: '-',
  143. sortName: undefined,
  144. sortOrder: 'asc',
  145. striped: false,
  146. columns: [],
  147. data: [],
  148. method: 'get',
  149. url: undefined,
  150. ajax: undefined,
  151. cache: true,
  152. contentType: 'application/json',
  153. dataType: 'json',
  154. ajaxOptions: {},
  155. queryParams: function (params) {
  156. return params;
  157. },
  158. queryParamsType: 'limit', // undefined
  159. responseHandler: function (res) {
  160. return res;
  161. },
  162. pagination: false,
  163. sidePagination: 'client', // client or server
  164. totalRows: 0, // server side need to set
  165. pageNumber: 1,
  166. pageSize: 10,
  167. pageList: [10, 25, 50, 100],
  168. paginationHAlign: 'right', //right, left
  169. paginationVAlign: 'bottom', //bottom, top, both
  170. paginationDetailHAlign: 'left', //right, left
  171. paginationFirstText: '&laquo;',
  172. paginationPreText: '&lsaquo;',
  173. paginationNextText: '&rsaquo;',
  174. paginationLastText: '&raquo;',
  175. search: false,
  176. searchAlign: 'right',
  177. selectItemName: 'btSelectItem',
  178. showHeader: true,
  179. showFooter: false,
  180. showColumns: false,
  181. showPaginationSwitch: false,
  182. showRefresh: false,
  183. showToggle: false,
  184. buttonsAlign: 'right',
  185. smartDisplay: true,
  186. minimumCountColumns: 1,
  187. idField: undefined,
  188. uniqueId: undefined,
  189. cardView: false,
  190. detailView: false,
  191. detailFormatter: function (index, row) {
  192. return '';
  193. },
  194. trimOnSearch: true,
  195. clickToSelect: false,
  196. singleSelect: false,
  197. toolbar: undefined,
  198. toolbarAlign: 'left',
  199. checkboxHeader: true,
  200. sortable: true,
  201. maintainSelected: false,
  202. searchTimeOut: 500,
  203. searchText: '',
  204. iconSize: undefined,
  205. iconsPrefix: 'glyphicon', // glyphicon of fa (font awesome)
  206. icons: {
  207. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  208. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  209. refresh: 'glyphicon-refresh icon-refresh',
  210. toggle: 'glyphicon-list-alt icon-list-alt',
  211. columns: 'glyphicon-th icon-th'
  212. },
  213. rowStyle: function (row, index) {
  214. return {};
  215. },
  216. rowAttributes: function (row, index) {
  217. return {};
  218. },
  219. onAll: function (name, args) {
  220. return false;
  221. },
  222. onClickCell: function (field, value, row, $element) {
  223. return false;
  224. },
  225. onDblClickCell: function (field, value, row, $element) {
  226. return false;
  227. },
  228. onClickRow: function (item, $element) {
  229. return false;
  230. },
  231. onDblClickRow: function (item, $element) {
  232. return false;
  233. },
  234. onSort: function (name, order) {
  235. return false;
  236. },
  237. onCheck: function (row) {
  238. return false;
  239. },
  240. onUncheck: function (row) {
  241. return false;
  242. },
  243. onCheckAll: function (rows) {
  244. return false;
  245. },
  246. onUncheckAll: function (rows) {
  247. return false;
  248. },
  249. onCheckSome: function(rows){
  250. return false;
  251. },
  252. onUncheckSome: function(rows){
  253. return false;
  254. },
  255. onLoadSuccess: function (data) {
  256. return false;
  257. },
  258. onLoadError: function (status) {
  259. return false;
  260. },
  261. onColumnSwitch: function (field, checked) {
  262. return false;
  263. },
  264. onPageChange: function (number, size) {
  265. return false;
  266. },
  267. onSearch: function (text) {
  268. return false;
  269. },
  270. onToggle: function (cardView) {
  271. return false;
  272. },
  273. onPreBody: function (data) {
  274. return false;
  275. },
  276. onPostBody: function () {
  277. return false;
  278. },
  279. onPostHeader: function () {
  280. return false;
  281. },
  282. onExpandRow: function (index, row, $detail) {
  283. return false;
  284. },
  285. onCollapseRow: function (index, row) {
  286. return false;
  287. }
  288. };
  289. BootstrapTable.LOCALES = [];
  290. BootstrapTable.LOCALES['en-US'] = {
  291. formatLoadingMessage: function () {
  292. return 'Loading, please wait...';
  293. },
  294. formatRecordsPerPage: function (pageNumber) {
  295. return sprintf('%s records per page', pageNumber);
  296. },
  297. formatShowingRows: function (pageFrom, pageTo, totalRows) {
  298. return sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
  299. },
  300. formatSearch: function () {
  301. return 'Search';
  302. },
  303. formatNoMatches: function () {
  304. return 'No matching records found';
  305. },
  306. formatPaginationSwitch: function () {
  307. return 'Hide/Show pagination';
  308. },
  309. formatRefresh: function () {
  310. return 'Refresh';
  311. },
  312. formatToggle: function () {
  313. return 'Toggle';
  314. },
  315. formatColumns: function () {
  316. return 'Columns';
  317. },
  318. formatAllRows: function () {
  319. return 'All';
  320. }
  321. };
  322. $.extend(BootstrapTable.DEFAULTS, BootstrapTable.LOCALES['en-US']);
  323. BootstrapTable.COLUMN_DEFAULTS = {
  324. radio: false,
  325. checkbox: false,
  326. checkboxEnabled: true,
  327. field: undefined,
  328. title: undefined,
  329. 'class': undefined,
  330. align: undefined, // left, right, center
  331. halign: undefined, // left, right, center
  332. falign: undefined, // left, right, center
  333. valign: undefined, // top, middle, bottom
  334. width: undefined,
  335. sortable: false,
  336. order: 'asc', // asc, desc
  337. visible: true,
  338. switchable: true,
  339. clickToSelect: true,
  340. formatter: undefined,
  341. footerFormatter: undefined,
  342. events: undefined,
  343. sorter: undefined,
  344. sortName: undefined,
  345. cellStyle: undefined,
  346. searchable: true,
  347. cardVisible: true
  348. };
  349. BootstrapTable.EVENTS = {
  350. 'all.bs.table': 'onAll',
  351. 'click-cell.bs.table': 'onClickCell',
  352. 'dbl-click-cell.bs.table': 'onDblClickCell',
  353. 'click-row.bs.table': 'onClickRow',
  354. 'dbl-click-row.bs.table': 'onDblClickRow',
  355. 'sort.bs.table': 'onSort',
  356. 'check.bs.table': 'onCheck',
  357. 'uncheck.bs.table': 'onUncheck',
  358. 'check-all.bs.table': 'onCheckAll',
  359. 'uncheck-all.bs.table': 'onUncheckAll',
  360. 'check-some.bs.table': 'onCheckSome',
  361. 'uncheck-some.bs.table': 'onUncheckSome',
  362. 'load-success.bs.table': 'onLoadSuccess',
  363. 'load-error.bs.table': 'onLoadError',
  364. 'column-switch.bs.table': 'onColumnSwitch',
  365. 'page-change.bs.table': 'onPageChange',
  366. 'search.bs.table': 'onSearch',
  367. 'toggle.bs.table': 'onToggle',
  368. 'pre-body.bs.table': 'onPreBody',
  369. 'post-body.bs.table': 'onPostBody',
  370. 'post-header.bs.table': 'onPostHeader',
  371. 'expand-row.bs.table': 'onExpandRow',
  372. 'collapse-row.bs.table': 'onCollapseRow'
  373. };
  374. BootstrapTable.prototype.init = function () {
  375. this.initContainer();
  376. this.initTable();
  377. this.initHeader();
  378. this.initData();
  379. this.initFooter();
  380. this.initToolbar();
  381. this.initPagination();
  382. this.initBody();
  383. this.initServer();
  384. };
  385. BootstrapTable.prototype.initContainer = function () {
  386. this.$container = $([
  387. '<div class="bootstrap-table">',
  388. '<div class="fixed-table-toolbar"></div>',
  389. this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  390. '<div class="fixed-table-pagination" style="clear: both;"></div>' :
  391. '',
  392. '<div class="fixed-table-container">',
  393. '<div class="fixed-table-header"><table></table></div>',
  394. '<div class="fixed-table-body">',
  395. '<div class="fixed-table-loading">',
  396. this.options.formatLoadingMessage(),
  397. '</div>',
  398. '</div>',
  399. '<div class="fixed-table-footer"><table><tr></tr></table></div>',
  400. this.options.paginationVAlign === 'bottom' || this.options.paginationVAlign === 'both' ?
  401. '<div class="fixed-table-pagination"></div>' :
  402. '',
  403. '</div>',
  404. '</div>'].join(''));
  405. this.$container.insertAfter(this.$el);
  406. this.$tableContainer = this.$container.find('.fixed-table-container');
  407. this.$tableHeader = this.$container.find('.fixed-table-header');
  408. this.$tableBody = this.$container.find('.fixed-table-body');
  409. this.$tableLoading = this.$container.find('.fixed-table-loading');
  410. this.$tableFooter = this.$container.find('.fixed-table-footer');
  411. this.$toolbar = this.$container.find('.fixed-table-toolbar');
  412. this.$pagination = this.$container.find('.fixed-table-pagination');
  413. this.$tableBody.append(this.$el);
  414. this.$container.after('<div class="clearfix"></div>');
  415. this.$el.addClass(this.options.classes);
  416. if (this.options.striped) {
  417. this.$el.addClass('table-striped');
  418. }
  419. if ($.inArray('table-no-bordered', this.options.classes.split(' ')) !== -1) {
  420. this.$tableContainer.addClass('table-no-bordered');
  421. }
  422. };
  423. BootstrapTable.prototype.initTable = function () {
  424. var that = this,
  425. columns = [],
  426. data = [];
  427. this.$header = this.$el.find('thead');
  428. if (!this.$header.length) {
  429. this.$header = $('<thead></thead>').appendTo(this.$el);
  430. }
  431. if (!this.$header.find('tr').length) {
  432. this.$header.append('<tr></tr>');
  433. }
  434. this.$header.find('th').each(function () {
  435. var column = $.extend({}, {
  436. title: $(this).html(),
  437. 'class': $(this).attr('class')
  438. }, $(this).data());
  439. columns.push(column);
  440. });
  441. this.options.columns = $.extend(true, [], columns, this.options.columns);
  442. $.each(this.options.columns, function (i, column) {
  443. that.options.columns[i] = $.extend({}, BootstrapTable.COLUMN_DEFAULTS,
  444. {field: i}, column); // when field is undefined, use index instead
  445. });
  446. // if options.data is setting, do not process tbody data
  447. if (this.options.data.length) {
  448. return;
  449. }
  450. this.$el.find('tbody tr').each(function () {
  451. var row = {};
  452. // save tr's id, class and data-* attributes
  453. row._id = $(this).attr('id');
  454. row._class = $(this).attr('class');
  455. row._data = getRealDataAttr($(this).data());
  456. $(this).find('td').each(function (i) {
  457. var field = that.options.columns[i].field;
  458. row[field] = $(this).html();
  459. // save td's id, class and data-* attributes
  460. row['_' + field + '_id'] = $(this).attr('id');
  461. row['_' + field + '_class'] = $(this).attr('class');
  462. row['_' + field + '_rowspan'] = $(this).attr('rowspan');
  463. row['_' + field + '_data'] = getRealDataAttr($(this).data());
  464. });
  465. data.push(row);
  466. });
  467. this.options.data = data;
  468. };
  469. BootstrapTable.prototype.initHeader = function () {
  470. var that = this,
  471. visibleColumns = [],
  472. html = [],
  473. timeoutId = 0;
  474. this.header = {
  475. fields: [],
  476. styles: [],
  477. classes: [],
  478. formatters: [],
  479. events: [],
  480. sorters: [],
  481. sortNames: [],
  482. cellStyles: [],
  483. clickToSelects: [],
  484. searchables: []
  485. };
  486. if (!this.options.cardView && this.options.detailView) {
  487. html.push('<th class="detail"><div class="fht-cell"></div></th>');
  488. visibleColumns.push({});
  489. }
  490. $.each(this.options.columns, function (i, column) {
  491. var text = '',
  492. halign = '', // header align style
  493. align = '', // body align style
  494. style = '',
  495. class_ = sprintf(' class="%s"', column['class']),
  496. order = that.options.sortOrder || column.order,
  497. unitWidth = 'px',
  498. width = column.width;
  499. if (!column.visible) {
  500. // Fix #229. Default Sort order is wrong
  501. // if data-visible="false" is set on the field referenced by data-sort-name.
  502. if (column.field === that.options.sortName) {
  503. that.header.fields.push(column.field);
  504. }
  505. return;
  506. }
  507. if (that.options.cardView && (!column.cardVisible)) {
  508. return;
  509. }
  510. if (column.width !== undefined && (!that.options.cardView)) {
  511. if (typeof column.width === 'string') {
  512. if (column.width.indexOf('%') !== -1) {
  513. unitWidth = '%';
  514. }
  515. }
  516. }
  517. if (column.width && typeof column.width === 'string') {
  518. width = column.width.replace('%', '').replace('px', '');
  519. }
  520. halign = sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
  521. align = sprintf('text-align: %s; ', column.align);
  522. style = sprintf('vertical-align: %s; ', column.valign);
  523. style += sprintf('width: %s%s; ', column.checkbox || column.radio ? 36 : width, unitWidth);
  524. visibleColumns.push(column);
  525. that.header.fields.push(column.field);
  526. that.header.styles.push(align + style);
  527. that.header.classes.push(class_);
  528. that.header.formatters.push(column.formatter);
  529. that.header.events.push(column.events);
  530. that.header.sorters.push(column.sorter);
  531. that.header.sortNames.push(column.sortName);
  532. that.header.cellStyles.push(column.cellStyle);
  533. that.header.clickToSelects.push(column.clickToSelect);
  534. that.header.searchables.push(column.searchable);
  535. html.push('<th',
  536. column.checkbox || column.radio ?
  537. sprintf(' class="bs-checkbox %s"', column['class'] || '') :
  538. class_,
  539. sprintf(' style="%s"', halign + style),
  540. '>');
  541. html.push(sprintf('<div class="th-inner %s">', that.options.sortable && column.sortable ?
  542. 'sortable' : ''));
  543. text = column.title;
  544. if (column.checkbox) {
  545. if (!that.options.singleSelect && that.options.checkboxHeader) {
  546. text = '<input name="btSelectAll" type="checkbox" />';
  547. }
  548. that.header.stateField = column.field;
  549. }
  550. if (column.radio) {
  551. text = '';
  552. that.header.stateField = column.field;
  553. that.options.singleSelect = true;
  554. }
  555. html.push(text);
  556. html.push('</div>');
  557. html.push('<div class="fht-cell"></div>');
  558. html.push('</div>');
  559. html.push('</th>');
  560. });
  561. this.$header.find('tr').html(html.join(''));
  562. this.$header.find('th').each(function (i) {
  563. $(this).data(visibleColumns[i]);
  564. });
  565. this.$container.off('click', '.th-inner').on('click', '.th-inner', function (event) {
  566. if (that.options.sortable && $(this).parent().data().sortable) {
  567. that.onSort(event);
  568. }
  569. });
  570. if (!this.options.showHeader || this.options.cardView) {
  571. this.$header.hide();
  572. this.$tableHeader.hide();
  573. this.$tableLoading.css('top', 0);
  574. } else {
  575. this.$header.show();
  576. this.$tableHeader.show();
  577. this.$tableLoading.css('top', cellHeight + 'px');
  578. // Assign the correct sortable arrow
  579. this.getCaretHtml();
  580. }
  581. this.$selectAll = this.$header.find('[name="btSelectAll"]');
  582. this.$container.off('click', '[name="btSelectAll"]')
  583. .on('click', '[name="btSelectAll"]', function () {
  584. var checked = $(this).prop('checked');
  585. that[checked ? 'checkAll' : 'uncheckAll']();
  586. });
  587. };
  588. BootstrapTable.prototype.initFooter = function () {
  589. if (!this.options.showFooter || this.options.cardView) {
  590. this.$tableFooter.hide();
  591. } else {
  592. this.$tableFooter.show();
  593. }
  594. };
  595. /**
  596. * @param data
  597. * @param type: append / prepend
  598. */
  599. BootstrapTable.prototype.initData = function (data, type) {
  600. if (type === 'append') {
  601. this.data = this.data.concat(data);
  602. } else if (type === 'prepend') {
  603. this.data = [].concat(data).concat(this.data);
  604. } else {
  605. this.data = data || this.options.data;
  606. }
  607. // Fix #839 Records deleted when adding new row on filtered table
  608. if (type === 'append') {
  609. this.options.data = this.options.data.concat(data);
  610. } else if (type === 'prepend') {
  611. this.options.data = [].concat(data).concat(this.options.data);
  612. } else {
  613. this.options.data = this.data;
  614. }
  615. if (this.options.sidePagination === 'server') {
  616. return;
  617. }
  618. this.initSort();
  619. };
  620. BootstrapTable.prototype.initSort = function () {
  621. var that = this,
  622. name = this.options.sortName,
  623. order = this.options.sortOrder === 'desc' ? -1 : 1,
  624. index = $.inArray(this.options.sortName, this.header.fields);
  625. if (index !== -1) {
  626. this.data.sort(function (a, b) {
  627. if (that.header.sortNames[index]) {
  628. name = that.header.sortNames[index];
  629. }
  630. var aa = a[name],
  631. bb = b[name],
  632. value = calculateObjectValue(that.header, that.header.sorters[index], [aa, bb]);
  633. if (value !== undefined) {
  634. return order * value;
  635. }
  636. // Fix #161: undefined or null string sort bug.
  637. if (aa === undefined || aa === null) {
  638. aa = '';
  639. }
  640. if (bb === undefined || bb === null) {
  641. bb = '';
  642. }
  643. // IF both values are numeric, do a numeric comparison
  644. if ($.isNumeric(aa) && $.isNumeric(bb)) {
  645. // Convert numerical values form string to float.
  646. aa = parseFloat(aa);
  647. bb = parseFloat(bb);
  648. if (aa < bb) {
  649. return order * -1;
  650. }
  651. return order;
  652. }
  653. if (aa === bb) {
  654. return 0;
  655. }
  656. // If value is not a string, convert to string
  657. if (typeof aa !== 'string') {
  658. aa = aa.toString();
  659. }
  660. if (aa.localeCompare(bb) === -1) {
  661. return order * -1;
  662. }
  663. return order;
  664. });
  665. }
  666. };
  667. BootstrapTable.prototype.onSort = function (event) {
  668. var $this = $(event.currentTarget).parent(),
  669. $this_ = this.$header.find('th').eq($this.index());
  670. this.$header.add(this.$header_).find('span.order').remove();
  671. if (this.options.sortName === $this.data('field')) {
  672. this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
  673. } else {
  674. this.options.sortName = $this.data('field');
  675. this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
  676. }
  677. this.trigger('sort', this.options.sortName, this.options.sortOrder);
  678. $this.add($this_).data('order', this.options.sortOrder);
  679. // Assign the correct sortable arrow
  680. this.getCaretHtml();
  681. if (this.options.sidePagination === 'server') {
  682. this.initServer();
  683. return;
  684. }
  685. this.initSort();
  686. this.initBody();
  687. };
  688. BootstrapTable.prototype.initToolbar = function () {
  689. var that = this,
  690. html = [],
  691. timeoutId = 0,
  692. $keepOpen,
  693. $search,
  694. switchableCount = 0;
  695. this.$toolbar.html('');
  696. if (typeof this.options.toolbar === 'string') {
  697. $(sprintf('<div class="bars pull-%s"></div>', this.options.toolbarAlign))
  698. .appendTo(this.$toolbar)
  699. .append($(this.options.toolbar));
  700. }
  701. // showColumns, showToggle, showRefresh
  702. html = [sprintf('<div class="columns columns-%s btn-group pull-%s">',
  703. this.options.buttonsAlign, this.options.buttonsAlign)];
  704. if (typeof this.options.icons === 'string') {
  705. this.options.icons = calculateObjectValue(null, this.options.icons);
  706. }
  707. if (this.options.showPaginationSwitch) {
  708. html.push(sprintf('<button class="btn btn-default" type="button" name="paginationSwitch" title="%s">',
  709. this.options.formatPaginationSwitch()),
  710. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown),
  711. '</button>');
  712. }
  713. if (this.options.showRefresh) {
  714. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="refresh" title="%s">',
  715. this.options.formatRefresh()),
  716. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh),
  717. '</button>');
  718. }
  719. if (this.options.showToggle) {
  720. html.push(sprintf('<button class="btn btn-default' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + '" type="button" name="toggle" title="%s">',
  721. this.options.formatToggle()),
  722. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggle),
  723. '</button>');
  724. }
  725. if (this.options.showColumns) {
  726. html.push(sprintf('<div class="keep-open btn-group" title="%s">',
  727. this.options.formatColumns()),
  728. '<button type="button" class="btn btn-default' + (this.options.iconSize == undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
  729. sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns),
  730. ' <span class="caret"></span>',
  731. '</button>',
  732. '<ul class="dropdown-menu" role="menu">');
  733. $.each(this.options.columns, function (i, column) {
  734. if (column.radio || column.checkbox) {
  735. return;
  736. }
  737. if (that.options.cardView && (!column.cardVisible)) {
  738. return;
  739. }
  740. var checked = column.visible ? ' checked="checked"' : '';
  741. if (column.switchable) {
  742. html.push(sprintf('<li>' +
  743. '<label><input type="checkbox" data-field="%s" value="%s"%s> %s</label>' +
  744. '</li>', column.field, i, checked, column.title));
  745. switchableCount++;
  746. }
  747. });
  748. html.push('</ul>',
  749. '</div>');
  750. }
  751. html.push('</div>');
  752. // Fix #188: this.showToolbar is for extentions
  753. if (this.showToolbar || html.length > 2) {
  754. this.$toolbar.append(html.join(''));
  755. }
  756. if (this.options.showPaginationSwitch) {
  757. this.$toolbar.find('button[name="paginationSwitch"]')
  758. .off('click').on('click', $.proxy(this.togglePagination, this));
  759. }
  760. if (this.options.showRefresh) {
  761. this.$toolbar.find('button[name="refresh"]')
  762. .off('click').on('click', $.proxy(this.refresh, this));
  763. }
  764. if (this.options.showToggle) {
  765. this.$toolbar.find('button[name="toggle"]')
  766. .off('click').on('click', function () {
  767. that.toggleView();
  768. });
  769. }
  770. if (this.options.showColumns) {
  771. $keepOpen = this.$toolbar.find('.keep-open');
  772. if (switchableCount <= this.options.minimumCountColumns) {
  773. $keepOpen.find('input').prop('disabled', true);
  774. }
  775. $keepOpen.find('li').off('click').on('click', function (event) {
  776. event.stopImmediatePropagation();
  777. });
  778. $keepOpen.find('input').off('click').on('click', function () {
  779. var $this = $(this);
  780. that.toggleColumn(getFieldIndex(that.options.columns, $(this).data('field')), $this.prop('checked'), false);
  781. that.trigger('column-switch', $(this).data('field'), $this.prop('checked'));
  782. });
  783. }
  784. if (this.options.search) {
  785. html = [];
  786. html.push(
  787. '<div class="pull-' + this.options.searchAlign + ' search">',
  788. sprintf('<input class="form-control' + (this.options.iconSize === undefined ? '' : ' input-' + this.options.iconSize) + '" type="text" placeholder="%s">',
  789. this.options.formatSearch()),
  790. '</div>');
  791. this.$toolbar.append(html.join(''));
  792. $search = this.$toolbar.find('.search input');
  793. $search.off('keyup drop').on('keyup drop', function (event) {
  794. clearTimeout(timeoutId); // doesn't matter if it's 0
  795. timeoutId = setTimeout(function () {
  796. that.onSearch(event);
  797. }, that.options.searchTimeOut);
  798. });
  799. if (this.options.searchText !== '') {
  800. $search.val(this.options.searchText);
  801. clearTimeout(timeoutId); // doesn't matter if it's 0
  802. timeoutId = setTimeout(function () {
  803. $search.trigger('keyup');
  804. }, that.options.searchTimeOut);
  805. }
  806. }
  807. };
  808. BootstrapTable.prototype.onSearch = function (event) {
  809. var text = $.trim($(event.currentTarget).val());
  810. // trim search input
  811. if (this.options.trimOnSearch && $(event.currentTarget).val() !== text) {
  812. $(event.currentTarget).val(text);
  813. }
  814. if (text === this.searchText) {
  815. return;
  816. }
  817. this.searchText = text;
  818. this.options.pageNumber = 1;
  819. this.initSearch();
  820. this.updatePagination();
  821. this.trigger('search', text);
  822. };
  823. BootstrapTable.prototype.initSearch = function () {
  824. var that = this;
  825. if (this.options.sidePagination !== 'server') {
  826. var s = this.searchText && this.searchText.toLowerCase();
  827. var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
  828. // Check filter
  829. this.data = f ? $.grep(this.options.data, function (item, i) {
  830. for (var key in f) {
  831. if (item[key] !== f[key]) {
  832. return false;
  833. }
  834. }
  835. return true;
  836. }) : this.options.data;
  837. this.data = s ? $.grep(this.data, function (item, i) {
  838. for (var key in item) {
  839. key = $.isNumeric(key) ? parseInt(key, 10) : key;
  840. var value = item[key];
  841. // Fix #142: search use formated data
  842. value = calculateObjectValue(that.header,
  843. that.header.formatters[$.inArray(key, that.header.fields)],
  844. [value, item, i], value);
  845. var index = $.inArray(key, that.header.fields);
  846. if (index !== -1 && that.header.searchables[index] &&
  847. (typeof value === 'string' ||
  848. typeof value === 'number') &&
  849. (value + '').toLowerCase().indexOf(s) !== -1) {
  850. return true;
  851. }
  852. }
  853. return false;
  854. }) : this.data;
  855. }
  856. };
  857. BootstrapTable.prototype.initPagination = function () {
  858. if (!this.options.pagination) {
  859. this.$pagination.hide();
  860. return;
  861. } else {
  862. this.$pagination.show();
  863. }
  864. var that = this,
  865. html = [],
  866. $allSelected = false,
  867. i, from, to,
  868. $pageList,
  869. $first, $pre,
  870. $next, $last,
  871. $number,
  872. data = this.getData();
  873. if (this.options.sidePagination !== 'server') {
  874. this.options.totalRows = data.length;
  875. }
  876. this.totalPages = 0;
  877. if (this.options.totalRows) {
  878. if (this.options.pageSize === this.options.formatAllRows()) {
  879. this.options.pageSize = this.options.totalRows;
  880. $allSelected = true;
  881. } else if (this.options.pageSize === this.options.totalRows) {
  882. // Fix #667 Table with pagination, multiple pages and a search that matches to one page throws exception
  883. var pageLst = typeof this.options.pageList === 'string' ?
  884. this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') :
  885. this.options.pageList;
  886. if (pageLst.indexOf(this.options.formatAllRows().toLowerCase()) > -1) {
  887. $allSelected = true;
  888. }
  889. }
  890. this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
  891. this.options.totalPages = this.totalPages;
  892. }
  893. if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
  894. this.options.pageNumber = this.totalPages;
  895. }
  896. this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
  897. this.pageTo = this.options.pageNumber * this.options.pageSize;
  898. if (this.pageTo > this.options.totalRows) {
  899. this.pageTo = this.options.totalRows;
  900. }
  901. html.push(
  902. '<div class="pull-' + this.options.paginationDetailHAlign + ' pagination-detail">',
  903. '<span class="pagination-info">',
  904. this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows),
  905. '</span>');
  906. html.push('<span class="page-list">');
  907. var pageNumber = [
  908. sprintf('<span class="btn-group %s">', this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ?
  909. 'dropdown' : 'dropup'),
  910. '<button type="button" class="btn btn-default ' + (this.options.iconSize === undefined ? '' : ' btn-' + this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">',
  911. '<span class="page-size">',
  912. $allSelected ? this.options.formatAllRows() : this.options.pageSize,
  913. '</span>',
  914. ' <span class="caret"></span>',
  915. '</button>',
  916. '<ul class="dropdown-menu" role="menu">'],
  917. pageList = this.options.pageList;
  918. if (typeof this.options.pageList === 'string') {
  919. var list = this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').split(',');
  920. pageList = [];
  921. $.each(list, function (i, value) {
  922. pageList.push(value.toUpperCase() === that.options.formatAllRows().toUpperCase() ?
  923. that.options.formatAllRows() : +value);
  924. });
  925. }
  926. $.each(pageList, function (i, page) {
  927. if (!that.options.smartDisplay || i === 0 || pageList[i - 1] <= that.options.totalRows) {
  928. var active;
  929. if ($allSelected) {
  930. active = page === that.options.formatAllRows() ? ' class="active"' : '';
  931. } else {
  932. active = page === that.options.pageSize ? ' class="active"' : '';
  933. }
  934. pageNumber.push(sprintf('<li%s><a href="javascript:void(0)">%s</a></li>', active, page));
  935. }
  936. });
  937. pageNumber.push('</ul></span>');
  938. html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
  939. html.push('</span>');
  940. html.push('</div>',
  941. '<div class="pull-' + this.options.paginationHAlign + ' pagination">',
  942. '<ul class="pagination' + (this.options.iconSize === undefined ? '' : ' pagination-' + this.options.iconSize) + '">',
  943. '<li class="page-first"><a href="javascript:void(0)">' + this.options.paginationFirstText + '</a></li>',
  944. '<li class="page-pre"><a href="javascript:void(0)">' + this.options.paginationPreText + '</a></li>');
  945. if (this.totalPages < 5) {
  946. from = 1;
  947. to = this.totalPages;
  948. } else {
  949. from = this.options.pageNumber - 2;
  950. to = from + 4;
  951. if (from < 1) {
  952. from = 1;
  953. to = 5;
  954. }
  955. if (to > this.totalPages) {
  956. to = this.totalPages;
  957. from = to - 4;
  958. }
  959. }
  960. for (i = from; i <= to; i++) {
  961. html.push('<li class="page-number' + (i === this.options.pageNumber ? ' active' : '') + '">',
  962. '<a href="javascript:void(0)">', i, '</a>',
  963. '</li>');
  964. }
  965. html.push(
  966. '<li class="page-next"><a href="javascript:void(0)">' + this.options.paginationNextText + '</a></li>',
  967. '<li class="page-last"><a href="javascript:void(0)">' + this.options.paginationLastText + '</a></li>',
  968. '</ul>',
  969. '</div>');
  970. this.$pagination.html(html.join(''));
  971. $pageList = this.$pagination.find('.page-list a');
  972. $first = this.$pagination.find('.page-first');
  973. $pre = this.$pagination.find('.page-pre');
  974. $next = this.$pagination.find('.page-next');
  975. $last = this.$pagination.find('.page-last');
  976. $number = this.$pagination.find('.page-number');
  977. if (this.options.pageNumber <= 1) {
  978. $first.addClass('disabled');
  979. $pre.addClass('disabled');
  980. }
  981. if (this.options.pageNumber >= this.totalPages) {
  982. $next.addClass('disabled');
  983. $last.addClass('disabled');
  984. }
  985. if (this.options.smartDisplay) {
  986. if (this.totalPages <= 1) {
  987. this.$pagination.find('div.pagination').hide();
  988. }
  989. if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
  990. this.$pagination.find('span.page-list').hide();
  991. }
  992. // when data is empty, hide the pagination
  993. this.$pagination[this.getData().length ? 'show' : 'hide']();
  994. }
  995. if ($allSelected) {
  996. this.options.pageSize = this.options.formatAllRows();
  997. }
  998. $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
  999. $first.off('click').on('click', $.proxy(this.onPageFirst, this));
  1000. $pre.off('click').on('click', $.proxy(this.onPagePre, this));
  1001. $next.off('click').on('click', $.proxy(this.onPageNext, this));
  1002. $last.off('click').on('click', $.proxy(this.onPageLast, this));
  1003. $number.off('click').on('click', $.proxy(this.onPageNumber, this));
  1004. };
  1005. BootstrapTable.prototype.updatePagination = function (event) {
  1006. // Fix #171: IE disabled button can be clicked bug.
  1007. if (event && $(event.currentTarget).hasClass('disabled')) {
  1008. return;
  1009. }
  1010. if (!this.options.maintainSelected) {
  1011. this.resetRows();
  1012. }
  1013. this.initPagination();
  1014. if (this.options.sidePagination === 'server') {
  1015. this.initServer();
  1016. } else {
  1017. this.initBody();
  1018. }
  1019. this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
  1020. };
  1021. BootstrapTable.prototype.onPageListChange = function (event) {
  1022. var $this = $(event.currentTarget);
  1023. $this.parent().addClass('active').siblings().removeClass('active');
  1024. this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ?
  1025. this.options.formatAllRows() : +$this.text();
  1026. this.$toolbar.find('.page-size').text(this.options.pageSize);
  1027. this.updatePagination(event);
  1028. };
  1029. BootstrapTable.prototype.onPageFirst = function (event) {
  1030. this.options.pageNumber = 1;
  1031. this.updatePagination(event);
  1032. };
  1033. BootstrapTable.prototype.onPagePre = function (event) {
  1034. this.options.pageNumber--;
  1035. this.updatePagination(event);
  1036. };
  1037. BootstrapTable.prototype.onPageNext = function (event) {
  1038. this.options.pageNumber++;
  1039. this.updatePagination(event);
  1040. };
  1041. BootstrapTable.prototype.onPageLast = function (event) {
  1042. this.options.pageNumber = this.totalPages;
  1043. this.updatePagination(event);
  1044. };
  1045. BootstrapTable.prototype.onPageNumber = function (event) {
  1046. if (this.options.pageNumber === +$(event.currentTarget).text()) {
  1047. return;
  1048. }
  1049. this.options.pageNumber = +$(event.currentTarget).text();
  1050. this.updatePagination(event);
  1051. };
  1052. BootstrapTable.prototype.initBody = function (fixedScroll) {
  1053. var that = this,
  1054. html = [],
  1055. data = this.getData();
  1056. this.trigger('pre-body', data);
  1057. this.$body = this.$el.find('tbody');
  1058. if (!this.$body.length) {
  1059. this.$body = $('<tbody></tbody>').appendTo(this.$el);
  1060. }
  1061. //Fix #389 Bootstrap-table-flatJSON is not working
  1062. if (!this.options.pagination || this.options.sidePagination === 'server') {
  1063. this.pageFrom = 1;
  1064. this.pageTo = data.length;
  1065. }
  1066. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  1067. var key,
  1068. item = data[i],
  1069. style = {},
  1070. csses = [],
  1071. data_ = '',
  1072. attributes = {},
  1073. htmlAttributes = [];
  1074. style = calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
  1075. if (style && style.css) {
  1076. for (key in style.css) {
  1077. csses.push(key + ': ' + style.css[key]);
  1078. }
  1079. }
  1080. attributes = calculateObjectValue(this.options,
  1081. this.options.rowAttributes, [item, i], attributes);
  1082. if (attributes) {
  1083. for (key in attributes) {
  1084. htmlAttributes.push(sprintf('%s="%s"', key, escapeHTML(attributes[key])));
  1085. }
  1086. }
  1087. if (item._data && !$.isEmptyObject(item._data)) {
  1088. $.each(item._data, function (k, v) {
  1089. // ignore data-index
  1090. if (k === 'index') {
  1091. return;
  1092. }
  1093. data_ += sprintf(' data-%s="%s"', k, v);
  1094. });
  1095. }
  1096. html.push('<tr',
  1097. sprintf(' %s', htmlAttributes.join(' ')),
  1098. sprintf(' id="%s"', $.isArray(item) ? undefined : item._id),
  1099. sprintf(' class="%s"', style.classes || ($.isArray(item) ? undefined : item._class)),
  1100. sprintf(' data-index="%s"', i),
  1101. sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]),
  1102. sprintf('%s', data_),
  1103. '>'
  1104. );
  1105. if (this.options.cardView) {
  1106. html.push(sprintf('<td colspan="%s">', this.header.fields.length));
  1107. }
  1108. if (!this.options.cardView && this.options.detailView) {
  1109. html.push('<td>',
  1110. '<a class="detail-icon" href="javascript:">',
  1111. '<i class="glyphicon glyphicon-plus icon-plus"></i>',
  1112. '</a>',
  1113. '</td>');
  1114. }
  1115. $.each(this.header.fields, function (j, field) {
  1116. var text = '',
  1117. value = item[field],
  1118. type = '',
  1119. cellStyle = {},
  1120. id_ = '',
  1121. class_ = that.header.classes[j],
  1122. data_ = '',
  1123. rowspan_ = '',
  1124. column = that.options.columns[getFieldIndex(that.options.columns, field)];
  1125. style = sprintf('style="%s"', csses.concat(that.header.styles[j]).join('; '));
  1126. value = calculateObjectValue(that.header,
  1127. that.header.formatters[j], [value, item, i], value);
  1128. // handle td's id and class
  1129. if (item['_' + field + '_id']) {
  1130. id_ = sprintf(' id="%s"', item['_' + field + '_id']);
  1131. }
  1132. if (item['_' + field + '_class']) {
  1133. class_ = sprintf(' class="%s"', item['_' + field + '_class']);
  1134. }
  1135. if (item['_' + field + '_rowspan']) {
  1136. rowspan_ = sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
  1137. }
  1138. cellStyle = calculateObjectValue(that.header,
  1139. that.header.cellStyles[j], [value, item, i], cellStyle);
  1140. if (cellStyle.classes) {
  1141. class_ = sprintf(' class="%s"', cellStyle.classes);
  1142. }
  1143. if (cellStyle.css) {
  1144. var csses_ = [];
  1145. for (var key in cellStyle.css) {
  1146. csses_.push(key + ': ' + cellStyle.css[key]);
  1147. }
  1148. style = sprintf('style="%s"', csses_.concat(that.header.styles[j]).join('; '));
  1149. }
  1150. if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
  1151. $.each(item['_' + field + '_data'], function (k, v) {
  1152. // ignore data-index
  1153. if (k === 'index') {
  1154. return;
  1155. }
  1156. data_ += sprintf(' data-%s="%s"', k, v);
  1157. });
  1158. }
  1159. if (column.checkbox || column.radio) {
  1160. type = column.checkbox ? 'checkbox' : type;
  1161. type = column.radio ? 'radio' : type;
  1162. text = [that.options.cardView ?
  1163. '<div class="card-view">' : '<td class="bs-checkbox">',
  1164. '<input' +
  1165. sprintf(' data-index="%s"', i) +
  1166. sprintf(' name="%s"', that.options.selectItemName) +
  1167. sprintf(' type="%s"', type) +
  1168. sprintf(' value="%s"', item[that.options.idField]) +
  1169. sprintf(' checked="%s"', value === true ||
  1170. (value && value.checked) ? 'checked' : undefined) +
  1171. sprintf(' disabled="%s"', !column.checkboxEnabled ||
  1172. (value && value.disabled) ? 'disabled' : undefined) +
  1173. ' />',
  1174. that.options.cardView ? '</div>' : '</td>'].join('');
  1175. item[that.header.stateField] = value === true || (value && value.checked);
  1176. } else {
  1177. value = typeof value === 'undefined' || value === null ?
  1178. that.options.undefinedText : value;
  1179. text = that.options.cardView ?
  1180. ['<div class="card-view">',
  1181. that.options.showHeader ? sprintf('<span class="title" %s>%s</span>', style,
  1182. getPropertyFromOther(that.options.columns, 'field', 'title', field)) : '',
  1183. sprintf('<span class="value">%s</span>', value),
  1184. '</div>'].join('') :
  1185. [sprintf('<td%s %s %s %s %s>', id_, class_, style, data_, rowspan_),
  1186. value,
  1187. '</td>'].join('');
  1188. // Hide empty data on Card view when smartDisplay is set to true.
  1189. if (that.options.cardView && that.options.smartDisplay && value === '') {
  1190. text = '';
  1191. }
  1192. }
  1193. html.push(text);
  1194. });
  1195. if (this.options.cardView) {
  1196. html.push('</td>');
  1197. }
  1198. html.push('</tr>');
  1199. }
  1200. // show no records
  1201. if (!html.length) {
  1202. html.push('<tr class="no-records-found">',
  1203. sprintf('<td colspan="%s">%s</td>',
  1204. this.$header.find('th').length, this.options.formatNoMatches()),
  1205. '</tr>');
  1206. }
  1207. this.$body.html(html.join(''));
  1208. if (!fixedScroll) {
  1209. this.scrollTo(0);
  1210. }
  1211. // click to select by column
  1212. this.$body.find('> tr > td').off('click').on('click', function () {
  1213. var $td = $(this),
  1214. $tr = $td.parent(),
  1215. item = that.data[$tr.data('index')],
  1216. cellIndex = $td[0].cellIndex,
  1217. $headerCell = that.$header.find('th:eq(' + cellIndex + ')'),
  1218. field = $headerCell.data('field'),
  1219. value = item[field];
  1220. that.trigger('click-cell', field, value, item, $td);
  1221. that.trigger('click-row', item, $tr);
  1222. // if click to select - then trigger the checkbox/radio click
  1223. if (that.options.clickToSelect) {
  1224. if (that.header.clickToSelects[$tr.children().index($(this))]) {
  1225. $tr.find(sprintf('[name="%s"]',
  1226. that.options.selectItemName))[0].click(); // #144: .trigger('click') bug
  1227. }
  1228. }
  1229. });
  1230. this.$body.find('> tr > td').off('dblclick').on('dblclick', function () {
  1231. var $td = $(this),
  1232. $tr = $td.parent(),
  1233. item = that.data[$tr.data('index')],
  1234. cellIndex = $td[0].cellIndex,
  1235. $headerCell = that.$header.find('th:eq(' + cellIndex + ')'),
  1236. field = $headerCell.data('field'),
  1237. value = item[field];
  1238. that.trigger('dbl-click-cell', field, value, item, $td);
  1239. that.trigger('dbl-click-row', item, $tr);
  1240. });
  1241. this.$body.find('> tr > td > .detail-icon').off('click').on('click', function () {
  1242. var $this = $(this),
  1243. $tr = $this.parent().parent(),
  1244. index = $tr.data('index'),
  1245. row = that.options.data[index];
  1246. // remove and update
  1247. if ($tr.next().is('tr.detail-view')) {
  1248. $this.find('i').attr('class', 'glyphicon glyphicon-plus icon-plus');
  1249. $tr.next().remove();
  1250. that.trigger('collapse-row', index, row);
  1251. } else {
  1252. $this.find('i').attr('class', 'glyphicon glyphicon-minus icon-minus');
  1253. $tr.after(sprintf('<tr class="detail-view"><td colspan="%s">%s</td></tr>',
  1254. $tr.find('td').length, calculateObjectValue(that.options,
  1255. that.options.detailFormatter, [index, row], '')));
  1256. that.trigger('expand-row', index, row, $tr.next().find('td'));
  1257. }
  1258. that.resetView();
  1259. });
  1260. this.$selectItem = this.$body.find(sprintf('[name="%s"]', this.options.selectItemName));
  1261. this.$selectItem.off('click').on('click', function (event) {
  1262. event.stopImmediatePropagation();
  1263. var checked = $(this).prop('checked'),
  1264. row = that.data[$(this).data('index')];
  1265. row[that.header.stateField] = checked;
  1266. if (that.options.singleSelect) {
  1267. that.$selectItem.not(this).each(function () {
  1268. that.data[$(this).data('index')][that.header.stateField] = false;
  1269. });
  1270. that.$selectItem.filter(':checked').not(this).prop('checked', false);
  1271. }
  1272. that.updateSelected();
  1273. that.trigger(checked ? 'check' : 'uncheck', row);
  1274. });
  1275. $.each(this.header.events, function (i, events) {
  1276. if (!events) {
  1277. return;
  1278. }
  1279. // fix bug, if events is defined with namespace
  1280. if (typeof events === 'string') {
  1281. events = calculateObjectValue(null, events);
  1282. }
  1283. if (!that.options.cardView && that.options.detailView) {
  1284. i += 1;
  1285. }
  1286. for (var key in events) {
  1287. that.$body.find('tr').each(function () {
  1288. var $tr = $(this),
  1289. $td = $tr.find(that.options.cardView ? '.card-view' : 'td').eq(i),
  1290. index = key.indexOf(' '),
  1291. name = key.substring(0, index),
  1292. el = key.substring(index + 1),
  1293. func = events[key];
  1294. $td.find(el).off(name).on(name, function (e) {
  1295. var index = $tr.data('index'),
  1296. row = that.data[index],
  1297. value = row[that.header.fields[i]];
  1298. func.apply(this, [e, value, row, index]);
  1299. });
  1300. });
  1301. }
  1302. });
  1303. this.updateSelected();
  1304. this.resetView();
  1305. this.trigger('post-body');
  1306. };
  1307. BootstrapTable.prototype.initServer = function (silent, query) {
  1308. var that = this,
  1309. data = {},
  1310. params = {
  1311. pageSize: this.options.pageSize === this.options.formatAllRows() ?
  1312. this.options.totalRows : this.options.pageSize,
  1313. pageNumber: this.options.pageNumber,
  1314. searchText: this.searchText,
  1315. sortName: this.options.sortName,
  1316. sortOrder: this.options.sortOrder
  1317. },
  1318. request;
  1319. if (!this.options.url && !this.options.ajax) {
  1320. return;
  1321. }
  1322. if (this.options.queryParamsType === 'limit') {
  1323. params = {
  1324. search: params.searchText,
  1325. sort: params.sortName,
  1326. order: params.sortOrder
  1327. };
  1328. if (this.options.pagination) {
  1329. params.limit = this.options.pageSize === this.options.formatAllRows() ?
  1330. this.options.totalRows : this.options.pageSize;
  1331. params.offset = this.options.pageSize === this.options.formatAllRows() ?
  1332. 0 : this.options.pageSize * (this.options.pageNumber - 1);
  1333. }
  1334. }
  1335. if (!($.isEmptyObject(this.filterColumnsPartial))) {
  1336. params['filter'] = JSON.stringify(this.filterColumnsPartial, null);
  1337. }
  1338. data = calculateObjectValue(this.options, this.options.queryParams, [params], data);
  1339. $.extend(data, query || {});
  1340. // false to stop request
  1341. if (data === false) {
  1342. return;
  1343. }
  1344. if (!silent) {
  1345. this.$tableLoading.show();
  1346. }
  1347. request = $.extend({}, calculateObjectValue(null, this.options.ajaxOptions), {
  1348. type: this.options.method,
  1349. url: this.options.url,
  1350. data: this.options.contentType === 'application/json' && this.options.method === 'post' ?
  1351. JSON.stringify(data) : data,
  1352. cache: this.options.cache,
  1353. contentType: this.options.contentType,
  1354. dataType: this.options.dataType,
  1355. success: function (res) {
  1356. res = calculateObjectValue(that.options, that.options.responseHandler, [res], res);
  1357. that.load(res);
  1358. that.trigger('load-success', res);
  1359. },
  1360. error: function (res) {
  1361. that.trigger('load-error', res.status);
  1362. },
  1363. complete: function () {
  1364. if (!silent) {
  1365. that.$tableLoading.hide();
  1366. }
  1367. }
  1368. });
  1369. if (this.options.ajax) {
  1370. calculateObjectValue(this, this.options.ajax, [request], null);
  1371. } else {
  1372. $.ajax(request);
  1373. }
  1374. };
  1375. BootstrapTable.prototype.getCaretHtml = function () {
  1376. var that = this;
  1377. $.each(this.$header.find('th'), function (i, th) {
  1378. if ($(th).data('field') === that.options.sortName) {
  1379. $(th).find('.sortable').css('background-image', 'url(' + (that.options.sortOrder === 'desc' ? arrowDesc : arrowAsc) + ')');
  1380. } else {
  1381. $(th).find('.sortable').css('background-image', 'url(' + arrowBoth +')');
  1382. }
  1383. });
  1384. };
  1385. BootstrapTable.prototype.updateSelected = function () {
  1386. var checkAll = this.$selectItem.filter(':enabled').length ===
  1387. this.$selectItem.filter(':enabled').filter(':checked').length;
  1388. this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
  1389. this.$selectItem.each(function () {
  1390. $(this).parents('tr')[$(this).prop('checked') ? 'addClass' : 'removeClass']('selected');
  1391. });
  1392. };
  1393. BootstrapTable.prototype.updateRows = function () {
  1394. var that = this;
  1395. this.$selectItem.each(function () {
  1396. that.data[$(this).data('index')][that.header.stateField] = $(this).prop('checked');
  1397. });
  1398. };
  1399. BootstrapTable.prototype.resetRows = function () {
  1400. var that = this;
  1401. $.each(this.data, function (i, row) {
  1402. that.$selectAll.prop('checked', false);
  1403. that.$selectItem.prop('checked', false);
  1404. row[that.header.stateField] = false;
  1405. });
  1406. };
  1407. BootstrapTable.prototype.trigger = function (name) {
  1408. var args = Array.prototype.slice.call(arguments, 1);
  1409. name += '.bs.table';
  1410. this.options[BootstrapTable.EVENTS[name]].apply(this.options, args);
  1411. this.$el.trigger($.Event(name), args);
  1412. this.options.onAll(name, args);
  1413. this.$el.trigger($.Event('all.bs.table'), [name, args]);
  1414. };
  1415. BootstrapTable.prototype.resetHeader = function () {
  1416. // fix #61: the hidden table reset header bug.
  1417. // fix bug: get $el.css('width') error sometime (height = 500)
  1418. clearTimeout(this.timeoutId_);
  1419. this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
  1420. };
  1421. BootstrapTable.prototype.fitHeader = function () {
  1422. var that = this,
  1423. fixedBody,
  1424. scrollWidth;
  1425. if (that.$el.is(':hidden')) {
  1426. that.timeoutFooter_ = setTimeout($.proxy(that.fitHeader, that), 100);
  1427. return;
  1428. }
  1429. fixedBody = this.$tableBody.get(0);
  1430. scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth &&
  1431. fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.height() ?
  1432. getScrollBarWidth() : 0;
  1433. this.$el.css('margin-top', -this.$header.height());
  1434. this.$header_ = this.$header.clone(true, true);
  1435. this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
  1436. this.$tableHeader.css({
  1437. 'margin-right': scrollWidth
  1438. }).find('table').css('width', this.$el.css('width'))
  1439. .html('').attr('class', this.$el.attr('class'))
  1440. .append(this.$header_);
  1441. // fix bug: $.data() is not working as expected after $.append()
  1442. this.$header.find('th').each(function (i) {
  1443. that.$header_.find('th').eq(i).data($(this).data());
  1444. });
  1445. this.$body.find('tr:first-child:not(.no-records-found) > *').each(function (i) {
  1446. that.$header_.find('div.fht-cell').eq(i).width($(this).innerWidth());
  1447. });
  1448. // horizontal scroll event
  1449. // TODO: it's probably better improving the layout than binding to scroll event
  1450. this.$tableBody.off('scroll').on('scroll', function () {
  1451. that.$tableHeader.scrollLeft($(this).scrollLeft());
  1452. });
  1453. that.trigger('post-header');
  1454. };
  1455. BootstrapTable.prototype.resetFooter = function () {
  1456. var that = this,
  1457. data = that.getData(),
  1458. html = [];
  1459. if (!this.options.showFooter || this.options.cardView) { //do nothing
  1460. return;
  1461. }
  1462. if (!this.options.cardView && this.options.detailView) {
  1463. html.push('<td></td>');
  1464. }
  1465. $.each(this.options.columns, function (i, column) {
  1466. var falign = '', // footer align style
  1467. style = '',
  1468. class_ = sprintf(' class="%s"', column['class']);
  1469. if (!column.visible) {
  1470. return;
  1471. }
  1472. if (that.options.cardView && (!column.cardVisible)) {
  1473. return;
  1474. }
  1475. falign = sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
  1476. style = sprintf('vertical-align: %s; ', column.valign);
  1477. html.push('<td', class_, sprintf(' style="%s"', falign + style), '>');
  1478. html.push(calculateObjectValue(column, column.footerFormatter, [data], '&nbsp;') || '&nbsp;');
  1479. html.push('</td>');
  1480. });
  1481. this.$tableFooter.find('tr').html(html.join(''));
  1482. clearTimeout(this.timeoutFooter_);
  1483. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this),
  1484. this.$el.is(':hidden') ? 100 : 0);
  1485. };
  1486. BootstrapTable.prototype.fitFooter = function () {
  1487. var that = this,
  1488. $footerTd,
  1489. elWidth,
  1490. scrollWidth;
  1491. clearTimeout(this.timeoutFooter_);
  1492. if (this.$el.is(':hidden')) {
  1493. this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
  1494. return;
  1495. }
  1496. elWidth = this.$el.css('width');
  1497. scrollWidth = elWidth > this.$tableBody.width() ? getScrollBarWidth() : 0;
  1498. this.$tableFooter.css({
  1499. 'margin-right': scrollWidth
  1500. }).find('table').css('width', elWidth)
  1501. .attr('class', this.$el.attr('class'));
  1502. $footerTd = this.$tableFooter.find('td');
  1503. this.$tableBody.find('tbody tr:first-child:not(.no-records-found) > td').each(function (i) {
  1504. $footerTd.eq(i).outerWidth($(this).outerWidth());
  1505. });
  1506. };
  1507. BootstrapTable.prototype.toggleColumn = function (index, checked, needUpdate) {
  1508. if (index === -1) {
  1509. return;
  1510. }
  1511. this.options.columns[index].visible = checked;
  1512. this.initHeader();
  1513. this.initSearch();
  1514. this.initPagination();
  1515. this.initBody();
  1516. if (this.options.showColumns) {
  1517. var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
  1518. if (needUpdate) {
  1519. $items.filter(sprintf('[value="%s"]', index)).prop('checked', checked);
  1520. }
  1521. if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
  1522. $items.filter(':checked').prop('disabled', true);
  1523. }
  1524. }
  1525. };
  1526. BootstrapTable.prototype.toggleRow = function (index, isIdField, visible) {
  1527. if (index === -1) {
  1528. return;
  1529. }
  1530. $(this.$body[0]).children().filter(sprintf(isIdField ? '[data-uniqueid="%s"]' : '[data-index="%s"]', index))
  1531. [visible ? 'show' : 'hide']();
  1532. };
  1533. // PUBLIC FUNCTION DEFINITION
  1534. // =======================
  1535. BootstrapTable.prototype.resetView = function (params) {
  1536. var that = this,
  1537. padding = 0;
  1538. if (params && params.height) {
  1539. this.options.height = params.height;
  1540. }
  1541. this.$selectAll.prop('checked', this.$selectItem.length > 0 &&
  1542. this.$selectItem.length === this.$selectItem.filter(':checked').length);
  1543. if (this.options.height) {
  1544. var toolbarHeight = getRealHeight(this.$toolbar),
  1545. paginationHeight = getRealHeight(this.$pagination),
  1546. height = this.options.height - toolbarHeight - paginationHeight;
  1547. this.$tableContainer.css('height', height + 'px');
  1548. }
  1549. if (this.options.cardView) {
  1550. // remove the element css
  1551. that.$el.css('margin-top', '0');
  1552. $tableContainer.css('padding-bottom', '0');
  1553. return;
  1554. }
  1555. if (this.options.showHeader && this.options.height) {
  1556. this.$tableHeader.show();
  1557. this.resetHeader();
  1558. padding += cellHeight;
  1559. } else {
  1560. this.$tableHeader.hide();
  1561. this.trigger('post-header');
  1562. }
  1563. if (this.options.showFooter) {
  1564. this.resetFooter();
  1565. if (this.options.height) {
  1566. padding += cellHeight;
  1567. }
  1568. }
  1569. // Assign the correct sortable arrow
  1570. this.getCaretHtml();
  1571. this.$tableContainer.css('padding-bottom', padding + 'px');
  1572. };
  1573. BootstrapTable.prototype.getData = function (useCurrentPage) {
  1574. return (this.searchText
  1575. || !$.isEmptyObject(this.filterColumns)
  1576. || !$.isEmptyObject(this.filterColumnsPartial)) ?
  1577. (useCurrentPage ? this.data.slice(this.pageFrom -1, this.pageTo)
  1578. : this.data) :
  1579. (useCurrentPage ? this.options.data.slice(this.pageFrom - 1, this.pageTo)
  1580. : this.options.data);
  1581. };
  1582. BootstrapTable.prototype.load = function (data) {
  1583. var fixedScroll = false;
  1584. // #431: support pagination
  1585. if (this.options.sidePagination === 'server') {
  1586. this.options.totalRows = data.total;
  1587. fixedScroll = data.fixedScroll;
  1588. data = data.rows;
  1589. } else if (!$.isArray(data)) { // support fixedScroll
  1590. fixedScroll = data.fixedScroll;
  1591. data = data.data;
  1592. }
  1593. this.initData(data);
  1594. this.initSearch();
  1595. this.initPagination();
  1596. this.initBody(fixedScroll);
  1597. };
  1598. BootstrapTable.prototype.append = function (data) {
  1599. this.initData(data, 'append');
  1600. this.initSearch();
  1601. this.initPagination();
  1602. this.initBody(true);
  1603. };
  1604. BootstrapTable.prototype.prepend = function (data) {
  1605. this.initData(data, 'prepend');
  1606. this.initSearch();
  1607. this.initPagination();
  1608. this.initBody(true);
  1609. };
  1610. BootstrapTable.prototype.remove = function (params) {
  1611. var len = this.options.data.length,
  1612. i, row;
  1613. if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
  1614. return;
  1615. }
  1616. for (i = len - 1; i >= 0; i--) {
  1617. row = this.options.data[i];
  1618. if (!row.hasOwnProperty(params.field)) {
  1619. continue;
  1620. }
  1621. if ($.inArray(row[params.field], params.values) !== -1) {
  1622. this.options.data.splice(i, 1);
  1623. }
  1624. }
  1625. if (len === this.options.data.length) {
  1626. return;
  1627. }
  1628. this.initSearch();
  1629. this.initPagination();
  1630. this.initBody(true);
  1631. };
  1632. BootstrapTable.prototype.removeAll = function () {
  1633. if (this.options.data.length > 0) {
  1634. this.options.data.splice(0, this.options.data.length);
  1635. this.initSearch();
  1636. this.initPagination();
  1637. this.initBody(true);
  1638. }
  1639. };
  1640. BootstrapTable.prototype.removeByUniqueId = function (id) {
  1641. var uniqueId = this.options.uniqueId,
  1642. len = this.options.data.length,
  1643. i, row;
  1644. for (i = len - 1; i >= 0; i--) {
  1645. row = this.options.data[i];
  1646. if (!row.hasOwnProperty(uniqueId)) {
  1647. continue;
  1648. }
  1649. if (typeof row[uniqueId] === 'string') {
  1650. id = id.toString();
  1651. } else if (typeof row[uniqueId] === 'number') {
  1652. if ((Number(row[uniqueId]) === row[uniqueId]) && (row[uniqueId] % 1 === 0)) {
  1653. id = parseInt(id);
  1654. } else if ((row[uniqueId] === Number(row[uniqueId])) && (row[uniqueId] !== 0)) {
  1655. id = parseFloat(id);
  1656. }
  1657. }
  1658. if (row[uniqueId] === id) {
  1659. this.options.data.splice(i, 1);
  1660. }
  1661. }
  1662. if (len === this.options.data.length) {
  1663. return;
  1664. }
  1665. this.initSearch();
  1666. this.initPagination();
  1667. this.initBody(true);
  1668. };
  1669. BootstrapTable.prototype.insertRow = function (params) {
  1670. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1671. return;
  1672. }
  1673. this.data.splice(params.index, 0, params.row);
  1674. this.initSearch();
  1675. this.initPagination();
  1676. this.initSort();
  1677. this.initBody(true);
  1678. };
  1679. BootstrapTable.prototype.updateRow = function (params) {
  1680. if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
  1681. return;
  1682. }
  1683. $.extend(this.data[params.index], params.row);
  1684. this.initSort();
  1685. this.initBody(true);
  1686. };
  1687. BootstrapTable.prototype.showRow = function (params) {
  1688. if (!params.hasOwnProperty('index')) {
  1689. return;
  1690. }
  1691. this.toggleRow(params.index, params.isIdField === undefined ? false : true, true);
  1692. };
  1693. BootstrapTable.prototype.hideRow = function (params) {
  1694. if (!params.hasOwnProperty('index')) {
  1695. return;
  1696. }
  1697. this.toggleRow(params.index, params.isIdField === undefined ? false : true, false);
  1698. };
  1699. BootstrapTable.prototype.getRowsHidden = function (show) {
  1700. var rows = $(this.$body[0]).children().filter(':hidden'),
  1701. i = 0;
  1702. if (show) {
  1703. for (; i < rows.length; i++) {
  1704. $(rows[i]).show();
  1705. }
  1706. }
  1707. return rows;
  1708. };
  1709. BootstrapTable.prototype.mergeCells = function (options) {
  1710. var row = options.index,
  1711. col = $.inArray(options.field, this.header.fields),
  1712. rowspan = options.rowspan || 1,
  1713. colspan = options.colspan || 1,
  1714. i, j,
  1715. $tr = this.$body.find('tr'),
  1716. $td = $tr.eq(row).find('td').eq(col);
  1717. if (!this.options.cardView && this.options.detailView) {
  1718. col += 1;
  1719. }
  1720. $td = $tr.eq(row).find('td').eq(col);
  1721. if (row < 0 || col < 0 || row >= this.data.length) {
  1722. return;
  1723. }
  1724. for (i = row; i < row + rowspan; i++) {
  1725. for (j = col; j < col + colspan; j++) {
  1726. $tr.eq(i).find('td').eq(j).hide();
  1727. }
  1728. }
  1729. $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
  1730. };
  1731. BootstrapTable.prototype.updateCell = function (params) {
  1732. if (!params.hasOwnProperty('rowIndex') || !params.hasOwnProperty('fieldName') || !params.hasOwnProperty('fieldValue')) {
  1733. return;
  1734. }
  1735. this.data[params.rowIndex][params.fieldName] = params.fieldValue;
  1736. this.initSort();
  1737. this.initBody(true);
  1738. };
  1739. BootstrapTable.prototype.getOptions = function () {
  1740. return this.options;
  1741. };
  1742. BootstrapTable.prototype.getSelections = function () {
  1743. var that = this;
  1744. return $.grep(this.data, function (row) {
  1745. return row[that.header.stateField];
  1746. });
  1747. };
  1748. BootstrapTable.prototype.getAllSelections = function () {
  1749. var that = this;
  1750. return $.grep(this.options.data, function (row) {
  1751. return row[that.header.stateField];
  1752. });
  1753. };
  1754. BootstrapTable.prototype.checkAll = function () {
  1755. this.checkAll_(true);
  1756. };
  1757. BootstrapTable.prototype.uncheckAll = function () {
  1758. this.checkAll_(false);
  1759. };
  1760. BootstrapTable.prototype.checkAll_ = function (checked) {
  1761. var rows;
  1762. if (!checked) {
  1763. rows = this.getSelections();
  1764. }
  1765. this.$selectItem.filter(':enabled').prop('checked', checked);
  1766. this.updateRows();
  1767. this.updateSelected();
  1768. if (checked) {
  1769. rows = this.getSelections();
  1770. }
  1771. this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
  1772. };
  1773. BootstrapTable.prototype.check = function (index) {
  1774. this.check_(true, index);
  1775. };
  1776. BootstrapTable.prototype.uncheck = function (index) {
  1777. this.check_(false, index);
  1778. };
  1779. BootstrapTable.prototype.check_ = function (checked, index) {
  1780. this.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1781. this.data[index][this.header.stateField] = checked;
  1782. this.updateSelected();
  1783. this.trigger(checked ? 'check' : 'uncheck', this.data[index]);
  1784. };
  1785. BootstrapTable.prototype.checkBy = function (obj) {
  1786. this.checkBy_(true, obj);
  1787. };
  1788. BootstrapTable.prototype.uncheckBy = function (obj) {
  1789. this.checkBy_(false, obj);
  1790. };
  1791. BootstrapTable.prototype.checkBy_ = function (checked, obj) {
  1792. if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
  1793. return;
  1794. }
  1795. var that = this,
  1796. rows = [];
  1797. $.each(this.options.data, function (index, row) {
  1798. if (!row.hasOwnProperty(obj.field)) {
  1799. return false;
  1800. }
  1801. if ($.inArray(row[obj.field], obj.values) !== -1) {
  1802. that.$selectItem.filter(sprintf('[data-index="%s"]', index)).prop('checked', checked);
  1803. row[that.header.stateField] = checked;
  1804. rows.push(row);
  1805. that.trigger(checked ? 'check' : 'uncheck', row);
  1806. }
  1807. });
  1808. this.updateSelected();
  1809. this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
  1810. };
  1811. BootstrapTable.prototype.destroy = function () {
  1812. this.$el.insertBefore(this.$container);
  1813. $(this.options.toolbar).insertBefore(this.$el);
  1814. this.$container.next().remove();
  1815. this.$container.remove();
  1816. this.$el.html(this.$el_.html())
  1817. .css('margin-top', '0')
  1818. .attr('class', this.$el_.attr('class') || ''); // reset the class
  1819. };
  1820. BootstrapTable.prototype.showLoading = function () {
  1821. this.$tableLoading.show();
  1822. };
  1823. BootstrapTable.prototype.hideLoading = function () {
  1824. this.$tableLoading.hide();
  1825. };
  1826. BootstrapTable.prototype.togglePagination = function () {
  1827. this.options.pagination = !this.options.pagination;
  1828. var button = this.$toolbar.find('button[name="paginationSwitch"] i');
  1829. if (this.options.pagination) {
  1830. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchDown);
  1831. } else {
  1832. button.attr("class", this.options.iconsPrefix + " " + this.options.icons.paginationSwitchUp);
  1833. }
  1834. this.updatePagination();
  1835. };
  1836. BootstrapTable.prototype.refresh = function (params) {
  1837. if (params && params.url) {
  1838. this.options.url = params.url;
  1839. this.options.pageNumber = 1;
  1840. }
  1841. this.initServer(params && params.silent, params && params.query);
  1842. };
  1843. BootstrapTable.prototype.resetWidth = function () {
  1844. if (this.options.showHeader && this.options.height) {
  1845. this.fitHeader();
  1846. }
  1847. if (this.options.showFooter) {
  1848. this.fitFooter();
  1849. }
  1850. };
  1851. BootstrapTable.prototype.showColumn = function (field) {
  1852. this.toggleColumn(getFieldIndex(this.options.columns, field), true, true);
  1853. };
  1854. BootstrapTable.prototype.hideColumn = function (field) {
  1855. this.toggleColumn(getFieldIndex(this.options.columns, field), false, true);
  1856. };
  1857. BootstrapTable.prototype.filterBy = function (columns) {
  1858. this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
  1859. this.options.pageNumber = 1;
  1860. this.initSearch();
  1861. this.updatePagination();
  1862. };
  1863. BootstrapTable.prototype.scrollTo = function (value) {
  1864. if (typeof value === 'string') {
  1865. value = value === 'bottom' ? this.$tableBody[0].scrollHeight : 0;
  1866. }
  1867. if (typeof value === 'number') {
  1868. this.$tableBody.scrollTop(value);
  1869. }
  1870. if (typeof value === 'undefined') {
  1871. return this.$tableBody.scrollTop();
  1872. }
  1873. };
  1874. BootstrapTable.prototype.getScrollPosition = function () {
  1875. return this.scrollTo();
  1876. }
  1877. BootstrapTable.prototype.selectPage = function (page) {
  1878. if (page > 0 && page <= this.options.totalPages) {
  1879. this.options.pageNumber = page;
  1880. this.updatePagination();
  1881. }
  1882. };
  1883. BootstrapTable.prototype.prevPage = function () {
  1884. if (this.options.pageNumber > 1) {
  1885. this.options.pageNumber--;
  1886. this.updatePagination();
  1887. }
  1888. };
  1889. BootstrapTable.prototype.nextPage = function () {
  1890. if (this.options.pageNumber < this.options.totalPages) {
  1891. this.options.pageNumber++;
  1892. this.updatePagination();
  1893. }
  1894. };
  1895. BootstrapTable.prototype.toggleView = function () {
  1896. this.options.cardView = !this.options.cardView;
  1897. this.initHeader();
  1898. // Fixed remove toolbar when click cardView button.
  1899. //that.initToolbar();
  1900. this.initBody();
  1901. this.trigger('toggle', this.options.cardView);
  1902. };
  1903. // BOOTSTRAP TABLE PLUGIN DEFINITION
  1904. // =======================
  1905. var allowedMethods = [
  1906. 'getOptions',
  1907. 'getSelections', 'getAllSelections', 'getData',
  1908. 'load', 'append', 'prepend', 'remove', 'removeAll',
  1909. 'insertRow', 'updateRow', 'updateCell', 'removeByUniqueId',
  1910. 'showRow', 'hideRow', 'getRowsHidden',
  1911. 'mergeCells',
  1912. 'checkAll', 'uncheckAll',
  1913. 'check', 'uncheck',
  1914. 'checkBy', 'uncheckBy',
  1915. 'refresh',
  1916. 'resetView',
  1917. 'resetWidth',
  1918. 'destroy',
  1919. 'showLoading', 'hideLoading',
  1920. 'showColumn', 'hideColumn',
  1921. 'filterBy',
  1922. 'scrollTo',
  1923. 'getScrollPosition',
  1924. 'selectPage', 'prevPage', 'nextPage',
  1925. 'togglePagination',
  1926. 'toggleView'
  1927. ];
  1928. $.fn.bootstrapTable = function (option, _relatedTarget) {
  1929. var value;
  1930. this.each(function () {
  1931. var $this = $(this),
  1932. data = $this.data('bootstrap.table'),
  1933. options = $.extend({}, BootstrapTable.DEFAULTS, $this.data(),
  1934. typeof option === 'object' && option);
  1935. if (typeof option === 'string') {
  1936. if ($.inArray(option, allowedMethods) < 0) {
  1937. throw new Error("Unknown method: " + option);
  1938. }
  1939. if (!data) {
  1940. return;
  1941. }
  1942. value = data[option](_relatedTarget);
  1943. if (option === 'destroy') {
  1944. $this.removeData('bootstrap.table');
  1945. }
  1946. }
  1947. if (!data) {
  1948. $this.data('bootstrap.table', (data = new BootstrapTable(this, options)));
  1949. }
  1950. });
  1951. return typeof value === 'undefined' ? this : value;
  1952. };
  1953. $.fn.bootstrapTable.Constructor = BootstrapTable;
  1954. $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
  1955. $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
  1956. $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
  1957. $.fn.bootstrapTable.methods = allowedMethods;
  1958. // BOOTSTRAP TABLE INIT
  1959. // =======================
  1960. $(function () {
  1961. $('[data-toggle="table"]').bootstrapTable();
  1962. });
  1963. }(jQuery);
  1964. /**
  1965. * @author: Dennis Hernández
  1966. * @webSite: http://djhvscf.github.io/Blog
  1967. * @version: v1.1.0
  1968. *
  1969. * @update zhixin wen <wenzhixin2010@gmail.com>
  1970. */
  1971. (function ($) {
  1972. 'use strict';
  1973. var idsStateSaveList = {
  1974. sortOrder: 'bs.table.sortOrder',
  1975. sortName: 'bs.table.sortName',
  1976. pageNumber: 'bs.table.pageNumber',
  1977. pageList: 'bs.table.pageList',
  1978. columns: 'bs.table.columns',
  1979. searchText: 'bs.table.searchText'
  1980. };
  1981. var cookieEnabled = function () {
  1982. return (navigator.cookieEnabled) ? true : false;
  1983. };
  1984. var setCookie = function (that, cookieName, sValue, sPath, sDomain, bSecure) {
  1985. if ((!that.options.stateSave) || (!cookieEnabled()) || (that.options.stateSaveIdTable === '')) {
  1986. return;
  1987. }
  1988. var tableName = that.options.stateSaveIdTable,
  1989. vEnd = that.options.stateSaveExpire;
  1990. cookieName = tableName + '.' + cookieName;
  1991. if (!cookieName || /^(?:expires|max\-age|path|domain|secure)$/i.test(cookieName)) {
  1992. return false;
  1993. }
  1994. document.cookie = encodeURIComponent(cookieName) + '=' + encodeURIComponent(sValue) + calculateExpiration(vEnd) + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '') + (bSecure ? '; secure' : '');
  1995. return true;
  1996. };
  1997. var getCookie = function (tableName, cookieName) {
  1998. cookieName = tableName + '.' + cookieName;
  1999. if (!cookieName) {
  2000. return null;
  2001. }
  2002. return decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null;
  2003. };
  2004. var hasCookie = function (cookieName) {
  2005. if (!cookieName) {
  2006. return false;
  2007. }
  2008. return (new RegExp('(?:^|;\\s*)' + encodeURIComponent(cookieName).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=')).test(document.cookie);
  2009. };
  2010. var deleteCookie = function (tableName, cookieName, sPath, sDomain) {
  2011. cookieName = tableName + '.' + cookieName;
  2012. if (!hasCookie(cookieName)) {
  2013. return false;
  2014. }
  2015. document.cookie = encodeURIComponent(cookieName) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT' + (sDomain ? '; domain=' + sDomain : '') + (sPath ? '; path=' + sPath : '');
  2016. return true;
  2017. };
  2018. var calculateExpiration = function(vEnd) {
  2019. var time = vEnd.replace(/[0-9]/, ''); //s,mi,h,d,m,y
  2020. vEnd = vEnd.replace(/[A-Za-z]/, ''); //number
  2021. switch (time.toLowerCase()) {
  2022. case 's':
  2023. vEnd = +vEnd;
  2024. break;
  2025. case 'mi':
  2026. vEnd = vEnd * 60;
  2027. break;
  2028. case 'h':
  2029. vEnd = vEnd * 60 * 60;
  2030. break;
  2031. case 'd':
  2032. vEnd = vEnd * 24 * 60 * 60;
  2033. break;
  2034. case 'm':
  2035. vEnd = vEnd * 30 * 24 * 60 * 60;
  2036. break;
  2037. case 'y':
  2038. vEnd = vEnd * 365 * 30 * 24 * 60 * 60;
  2039. break;
  2040. default:
  2041. vEnd = undefined;
  2042. break;
  2043. }
  2044. return vEnd === undefined ? '' : '; max-age=' + vEnd;
  2045. }
  2046. $.extend($.fn.bootstrapTable.defaults, {
  2047. stateSave: false,
  2048. stateSaveExpire: '2h',
  2049. stateSaveIdTable: ''
  2050. });
  2051. $.fn.bootstrapTable.methods.push('deleteCookie');
  2052. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2053. _initTable = BootstrapTable.prototype.initTable,
  2054. _onSort = BootstrapTable.prototype.onSort,
  2055. _onPageNumber = BootstrapTable.prototype.onPageNumber,
  2056. _onPageListChange = BootstrapTable.prototype.onPageListChange,
  2057. _onPageFirst = BootstrapTable.prototype.onPageFirst,
  2058. _onPagePre = BootstrapTable.prototype.onPagePre,
  2059. _onPageNext = BootstrapTable.prototype.onPageNext,
  2060. _onPageLast = BootstrapTable.prototype.onPageLast,
  2061. _toggleColumn = BootstrapTable.prototype.toggleColumn,
  2062. _onSearch = BootstrapTable.prototype.onSearch;
  2063. // init save data after initTable function
  2064. BootstrapTable.prototype.initTable = function () {
  2065. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  2066. this.initStateSave();
  2067. };
  2068. BootstrapTable.prototype.initStateSave = function () {
  2069. if (!this.options.stateSave) {
  2070. return;
  2071. }
  2072. if (!cookieEnabled()) {
  2073. return;
  2074. }
  2075. if (this.options.stateSaveIdTable === '') {
  2076. return;
  2077. }
  2078. var sortOrderStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.sortOrder),
  2079. sortOrderStateName = getCookie(this.options.stateSaveIdTable, idsStateSaveList.sortName),
  2080. pageNumberStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.pageNumber),
  2081. pageListStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.pageList),
  2082. columnsStateSave = JSON.parse(getCookie(this.options.stateSaveIdTable, idsStateSaveList.columns)),
  2083. searchStateSave = getCookie(this.options.stateSaveIdTable, idsStateSaveList.searchText);
  2084. if (sortOrderStateSave) {
  2085. this.options.sortOrder = sortOrderStateSave;
  2086. this.options.sortName = sortOrderStateName;
  2087. }
  2088. if (pageNumberStateSave) {
  2089. this.options.pageNumber = +pageNumberStateSave;
  2090. }
  2091. if (pageListStateSave) {
  2092. this.options.pageSize = pageListStateSave ===
  2093. this.options.formatAllRows() ? pageListStateSave : +pageListStateSave;
  2094. }
  2095. if (columnsStateSave) {
  2096. $.each(this.options.columns, function (i, column) {
  2097. column.visible = columnsStateSave.indexOf(i) !== -1;
  2098. });
  2099. }
  2100. if (searchStateSave) {
  2101. this.options.searchText = searchStateSave;
  2102. }
  2103. };
  2104. BootstrapTable.prototype.onSort = function () {
  2105. _onSort.apply(this, Array.prototype.slice.apply(arguments));
  2106. setCookie(this, idsStateSaveList.sortOrder, this.options.sortOrder);
  2107. setCookie(this, idsStateSaveList.sortName, this.options.sortName);
  2108. };
  2109. BootstrapTable.prototype.onPageNumber = function () {
  2110. _onPageNumber.apply(this, Array.prototype.slice.apply(arguments));
  2111. setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
  2112. };
  2113. BootstrapTable.prototype.onPageListChange = function () {
  2114. _onPageListChange.apply(this, Array.prototype.slice.apply(arguments));
  2115. setCookie(this, idsStateSaveList.pageList, this.options.pageSize);
  2116. };
  2117. BootstrapTable.prototype.onPageFirst = function () {
  2118. _onPageFirst.apply(this, Array.prototype.slice.apply(arguments));
  2119. setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
  2120. };
  2121. BootstrapTable.prototype.onPagePre = function () {
  2122. _onPagePre.apply(this, Array.prototype.slice.apply(arguments));
  2123. setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
  2124. };
  2125. BootstrapTable.prototype.onPageNext = function () {
  2126. _onPageNext.apply(this, Array.prototype.slice.apply(arguments));
  2127. setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
  2128. };
  2129. BootstrapTable.prototype.onPageLast = function () {
  2130. _onPageLast.apply(this, Array.prototype.slice.apply(arguments));
  2131. setCookie(this, idsStateSaveList.pageNumber, this.options.pageNumber);
  2132. };
  2133. BootstrapTable.prototype.toggleColumn = function () {
  2134. _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
  2135. var visibleColumns = [];
  2136. $.each(this.options.columns, function (i) {
  2137. if (this.visible) {
  2138. visibleColumns.push(i);
  2139. }
  2140. });
  2141. setCookie(this, idsStateSaveList.columns, JSON.stringify(visibleColumns));
  2142. };
  2143. BootstrapTable.prototype.onSearch = function () {
  2144. _onSearch.apply(this, Array.prototype.slice.apply(arguments));
  2145. setCookie(this, idsStateSaveList.searchText, this.searchText);
  2146. };
  2147. BootstrapTable.prototype.deleteCookie = function (cookieName) {
  2148. if ((cookieName === '') || (!cookieEnabled())) {
  2149. return;
  2150. }
  2151. deleteCookie(idsStateSaveList[cookieName]);
  2152. };
  2153. })(jQuery);
  2154. /**
  2155. * @author zhixin wen <wenzhixin2010@gmail.com>
  2156. * extensions: https://github.com/vitalets/x-editable
  2157. */
  2158. !function ($) {
  2159. 'use strict';
  2160. $.extend($.fn.bootstrapTable.defaults, {
  2161. editable: true,
  2162. onEditableInit: function () {
  2163. return false;
  2164. },
  2165. onEditableSave: function (field, row, oldValue, $el) {
  2166. return false;
  2167. }
  2168. });
  2169. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2170. 'editable-init.bs.table': 'onEditableInit',
  2171. 'editable-save.bs.table': 'onEditableSave'
  2172. });
  2173. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2174. _initTable = BootstrapTable.prototype.initTable,
  2175. _initBody = BootstrapTable.prototype.initBody;
  2176. BootstrapTable.prototype.initTable = function () {
  2177. var that = this;
  2178. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  2179. if (!this.options.editable) {
  2180. return;
  2181. }
  2182. $.each(this.options.columns, function (i, column) {
  2183. if (!column.editable) {
  2184. return;
  2185. }
  2186. var _formatter = column.formatter;
  2187. column.formatter = function (value, row, index) {
  2188. var result = _formatter ? _formatter(value, row, index) : value;
  2189. return ['<a href="javascript:void(0)"',
  2190. ' data-name="' + column.field + '"',
  2191. ' data-pk="' + row[that.options.idField] + '"',
  2192. ' data-value="' + result + '"',
  2193. '>' + '</a>'
  2194. ].join('');
  2195. };
  2196. });
  2197. };
  2198. BootstrapTable.prototype.initBody = function () {
  2199. var that = this;
  2200. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  2201. if (!this.options.editable) {
  2202. return;
  2203. }
  2204. $.each(this.options.columns, function (i, column) {
  2205. if (!column.editable) {
  2206. return;
  2207. }
  2208. that.$body.find('a[data-name="' + column.field + '"]').editable(column.editable)
  2209. .off('save').on('save', function (e, params) {
  2210. var data = that.getData(),
  2211. index = $(this).parents('tr[data-index]').data('index'),
  2212. row = data[index],
  2213. oldValue = row[column.field];
  2214. row[column.field] = params.submitValue;
  2215. that.trigger('editable-save', column.field, row, oldValue, $(this));
  2216. });
  2217. });
  2218. this.trigger('editable-init');
  2219. };
  2220. }(jQuery);
  2221. /**
  2222. * @author zhixin wen <wenzhixin2010@gmail.com>
  2223. * extensions: https://github.com/kayalshri/tableExport.jquery.plugin
  2224. */
  2225. (function ($) {
  2226. 'use strict';
  2227. var TYPE_NAME = {
  2228. json: 'JSON',
  2229. xml: 'XML',
  2230. png: 'PNG',
  2231. csv: 'CSV',
  2232. txt: 'TXT',
  2233. sql: 'SQL',
  2234. doc: 'MS-Word',
  2235. excel: 'Ms-Excel',
  2236. powerpoint: 'Ms-Powerpoint',
  2237. pdf: 'PDF'
  2238. };
  2239. $.extend($.fn.bootstrapTable.defaults, {
  2240. showExport: false,
  2241. // 'json', 'xml', 'png', 'csv', 'txt', 'sql', 'doc', 'excel', 'powerpoint', 'pdf'
  2242. exportTypes: ['json', 'xml', 'csv', 'txt', 'sql', 'excel'],
  2243. exportOptions: {}
  2244. });
  2245. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2246. _initToolbar = BootstrapTable.prototype.initToolbar;
  2247. BootstrapTable.prototype.initToolbar = function () {
  2248. this.showToolbar = true;
  2249. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  2250. if (this.options.showExport) {
  2251. var that = this,
  2252. $btnGroup = this.$toolbar.find('>.btn-group'),
  2253. $export = $btnGroup.find('div.export');
  2254. if (!$export.length) {
  2255. $export = $([
  2256. '<div class="export btn-group">',
  2257. '<button class="btn btn-default dropdown-toggle" ' +
  2258. 'data-toggle="dropdown" type="button">',
  2259. '<i class="glyphicon glyphicon-export icon-share"></i> ',
  2260. '<span class="caret"></span>',
  2261. '</button>',
  2262. '<ul class="dropdown-menu" role="menu">',
  2263. '</ul>',
  2264. '</div>'].join('')).appendTo($btnGroup);
  2265. var $menu = $export.find('.dropdown-menu'),
  2266. exportTypes = this.options.exportTypes;
  2267. if (typeof this.options.exportTypes === 'string') {
  2268. var types = this.options.exportTypes.slice(1, -1).replace(/ /g, '').split(',');
  2269. exportTypes = [];
  2270. $.each(types, function (i, value) {
  2271. exportTypes.push(value.slice(1, -1));
  2272. });
  2273. }
  2274. $.each(exportTypes, function (i, type) {
  2275. if (TYPE_NAME.hasOwnProperty(type)) {
  2276. $menu.append(['<li data-type="' + type + '">',
  2277. '<a href="javascript:void(0)">',
  2278. TYPE_NAME[type],
  2279. '</a>',
  2280. '</li>'].join(''));
  2281. }
  2282. });
  2283. $menu.find('li').click(function () {
  2284. that.$el.tableExport($.extend({}, that.options.exportOptions, {
  2285. type: $(this).data('type'),
  2286. escape: false
  2287. }));
  2288. });
  2289. }
  2290. }
  2291. };
  2292. })(jQuery);
  2293. /**
  2294. * @author: Dennis Hernández
  2295. * @webSite: http://djhvscf.github.io/Blog
  2296. * @version: v1.0.0
  2297. */
  2298. !function ($) {
  2299. 'use strict';
  2300. var sprintf = function (str) {
  2301. var args = arguments,
  2302. flag = true,
  2303. i = 1;
  2304. str = str.replace(/%s/g, function () {
  2305. var arg = args[i++];
  2306. if (typeof arg === 'undefined') {
  2307. flag = false;
  2308. return '';
  2309. }
  2310. return arg;
  2311. });
  2312. return flag ? str : '';
  2313. };
  2314. var getFieldIndex = function (columns, field) {
  2315. var index = -1;
  2316. $.each(columns, function (i, column) {
  2317. if (column.field === field) {
  2318. index = i;
  2319. return false;
  2320. }
  2321. return true;
  2322. });
  2323. return index;
  2324. };
  2325. var calculateObjectValue = function (self, name, args, defaultValue) {
  2326. if (typeof name === 'string') {
  2327. // support obj.func1.func2
  2328. var names = name.split('.');
  2329. if (names.length > 1) {
  2330. name = window;
  2331. $.each(names, function (i, f) {
  2332. name = name[f];
  2333. });
  2334. } else {
  2335. name = window[name];
  2336. }
  2337. }
  2338. if (typeof name === 'object') {
  2339. return name;
  2340. }
  2341. if (typeof name === 'function') {
  2342. return name.apply(self, args);
  2343. }
  2344. return defaultValue;
  2345. };
  2346. $.extend($.fn.bootstrapTable.defaults, {
  2347. filterControl: false,
  2348. onColumnSearch: function (field, text) {
  2349. return false;
  2350. }
  2351. });
  2352. $.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
  2353. filterControl: undefined
  2354. });
  2355. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2356. 'column-search.bs.table': 'onColumnSearch'
  2357. });
  2358. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2359. _initHeader = BootstrapTable.prototype.initHeader,
  2360. _initBody = BootstrapTable.prototype.initBody,
  2361. _initSearch = BootstrapTable.prototype.initSearch;
  2362. BootstrapTable.prototype.initHeader = function () {
  2363. _initHeader.apply(this, Array.prototype.slice.apply(arguments));
  2364. if (!this.options.filterControl) {
  2365. return;
  2366. }
  2367. var addedFilterControl = false,
  2368. that = this,
  2369. isVisible,
  2370. html,
  2371. timeoutId = 0;
  2372. $.each(this.options.columns, function (i, column) {
  2373. isVisible = 'hidden';
  2374. html = [];
  2375. if (!column.filterControl) {
  2376. html.push('<div style="height: 34px;"></div>');
  2377. } else {
  2378. html.push('<div style="margin: 0px 2px 2px 2px;" class="filterControl">');
  2379. if (column.filterControl && column.searchable) {
  2380. addedFilterControl = true;
  2381. isVisible = 'visible'
  2382. }
  2383. switch (column.filterControl.toLowerCase()) {
  2384. case 'input' :
  2385. html.push(sprintf('<input type="text" class="form-control" style="width: 100%; visibility: %s">', isVisible));
  2386. break;
  2387. case 'select':
  2388. html.push(sprintf('<select class="%s form-control" style="width: 100%; visibility: %s"></select>',
  2389. column.field, isVisible))
  2390. break;
  2391. }
  2392. }
  2393. that.$header.find(sprintf('.th-inner:contains("%s")', column.title)).next().append(html.join(''));
  2394. });
  2395. if (addedFilterControl) {
  2396. this.$header.off('keyup', 'input').on('keyup', 'input', function (event) {
  2397. clearTimeout(timeoutId);
  2398. timeoutId = setTimeout(function () {
  2399. that.onColumnSearch(event);
  2400. }, that.options.searchTimeOut);
  2401. });
  2402. this.$header.off('change', 'select').on('change', 'select', function (event) {
  2403. clearTimeout(timeoutId);
  2404. timeoutId = setTimeout(function () {
  2405. that.onColumnSearch(event);
  2406. }, that.options.searchTimeOut);
  2407. });
  2408. } else {
  2409. this.$header.find('.filterControl').hide();
  2410. }
  2411. };
  2412. BootstrapTable.prototype.initBody = function () {
  2413. _initBody.apply(this, Array.prototype.slice.apply(arguments));
  2414. var that = this,
  2415. data = this.getData();
  2416. for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
  2417. var key,
  2418. item = data[i];
  2419. $.each(this.header.fields, function (j, field) {
  2420. var value = item[field],
  2421. column = that.options.columns[getFieldIndex(that.options.columns, field)];
  2422. value = calculateObjectValue(that.header,
  2423. that.header.formatters[j], [value, item, i], value);
  2424. if ((!column.checkbox) || (!column.radio)) {
  2425. if (column.filterControl !== undefined && column.filterControl.toLowerCase() === 'select'
  2426. && column.searchable) {
  2427. var selectControl = $('.' + column.field),
  2428. iOpt = 0,
  2429. exitsOpt = false,
  2430. options;
  2431. if (selectControl !== undefined) {
  2432. options = selectControl.get(0).options;
  2433. if (options.length === 0) {
  2434. //Added the default option
  2435. selectControl.append($("<option></option>")
  2436. .attr("value", '')
  2437. .text(''));
  2438. selectControl.append($("<option></option>")
  2439. .attr("value", value)
  2440. .text(value));
  2441. } else {
  2442. for (; iOpt < options.length; iOpt++) {
  2443. if (options[iOpt].value === value) {
  2444. exitsOpt = true;
  2445. break;
  2446. }
  2447. }
  2448. if (!exitsOpt) {
  2449. selectControl.append($("<option></option>")
  2450. .attr("value", value)
  2451. .text(value));
  2452. }
  2453. }
  2454. }
  2455. }
  2456. }
  2457. });
  2458. }
  2459. };
  2460. BootstrapTable.prototype.initSearch = function () {
  2461. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  2462. var that = this;
  2463. var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
  2464. //Check partial column filter
  2465. this.data = fp ? $.grep(this.data, function (item, i) {
  2466. for (var key in fp) {
  2467. var fval = fp[key].toLowerCase();
  2468. var value = item[key];
  2469. value = calculateObjectValue(that.header,
  2470. that.header.formatters[$.inArray(key, that.header.fields)],
  2471. [value, item, i], value);
  2472. if (!($.inArray(key, that.header.fields) !== -1 &&
  2473. (typeof value === 'string' || typeof value === 'number') &&
  2474. (value + '').toLowerCase().indexOf(fval) !== -1)) {
  2475. return false;
  2476. }
  2477. }
  2478. return true;
  2479. }) : this.data;
  2480. };
  2481. BootstrapTable.prototype.onColumnSearch = function (event) {
  2482. var text = $.trim($(event.currentTarget).val());
  2483. var $field = $(event.currentTarget).parent().parent().parent().data('field')
  2484. if ($.isEmptyObject(this.filterColumnsPartial)) {
  2485. this.filterColumnsPartial = {};
  2486. }
  2487. if (text) {
  2488. this.filterColumnsPartial[$field] = text;
  2489. } else {
  2490. delete this.filterColumnsPartial[$field];
  2491. }
  2492. this.options.pageNumber = 1;
  2493. this.onSearch(event);
  2494. this.updatePagination();
  2495. this.trigger('column-search', $field, text);
  2496. };
  2497. }(jQuery);
  2498. /**
  2499. * @author zhixin wen <wenzhixin2010@gmail.com>
  2500. * extensions: https://github.com/lukaskral/bootstrap-table-filter
  2501. */
  2502. !function($) {
  2503. 'use strict';
  2504. $.extend($.fn.bootstrapTable.defaults, {
  2505. showFilter: false
  2506. });
  2507. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2508. _init = BootstrapTable.prototype.init,
  2509. _initSearch = BootstrapTable.prototype.initSearch;
  2510. BootstrapTable.prototype.init = function () {
  2511. _init.apply(this, Array.prototype.slice.apply(arguments));
  2512. var that = this;
  2513. this.$el.on('load-success.bs.table', function () {
  2514. if (that.options.showFilter) {
  2515. $(that.options.toolbar).bootstrapTableFilter({
  2516. connectTo: that.$el
  2517. });
  2518. }
  2519. });
  2520. };
  2521. BootstrapTable.prototype.initSearch = function () {
  2522. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  2523. if (this.options.sidePagination !== 'server') {
  2524. if (typeof this.searchCallback === 'function') {
  2525. this.data = $.grep(this.options.data, this.searchCallback);
  2526. }
  2527. }
  2528. };
  2529. BootstrapTable.prototype.getData = function () {
  2530. return (this.searchText || this.searchCallback) ? this.data : this.options.data;
  2531. };
  2532. BootstrapTable.prototype.getColumns = function () {
  2533. return this.options.columns;
  2534. };
  2535. BootstrapTable.prototype.registerSearchCallback = function (callback) {
  2536. this.searchCallback = callback;
  2537. };
  2538. BootstrapTable.prototype.updateSearch = function () {
  2539. this.options.pageNumber = 1;
  2540. this.initSearch();
  2541. this.updatePagination();
  2542. };
  2543. BootstrapTable.prototype.getServerUrl = function () {
  2544. return (this.options.sidePagination === 'server') ? this.options.url : false;
  2545. };
  2546. $.fn.bootstrapTable.methods.push('getColumns',
  2547. 'registerSearchCallback', 'updateSearch',
  2548. 'getServerUrl');
  2549. }(jQuery);
  2550. /**
  2551. * @author: Dennis Hernández
  2552. * @webSite: http://djhvscf.github.io/Blog
  2553. * @version: v1.1.0
  2554. */
  2555. (function ($) {
  2556. 'use strict';
  2557. var flatJSON = function (el, data) {
  2558. if (el.options.flat) {
  2559. el.options.data = sd.flatHelper(data);
  2560. }
  2561. if (el.options.sidePagination === 'server') {
  2562. el.data = el.options.data;
  2563. }
  2564. };
  2565. $.extend($.fn.bootstrapTable.defaults, {
  2566. flat: false
  2567. });
  2568. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2569. _initData = BootstrapTable.prototype.initData,
  2570. _init = BootstrapTable.prototype.init,
  2571. _initTable = BootstrapTable.prototype.initTable;
  2572. BootstrapTable.prototype.initData = function (data) {
  2573. _initData.apply(this, Array.prototype.slice.apply(arguments));
  2574. flatJSON(this, data === undefined ? this.options.data : data);
  2575. };
  2576. BootstrapTable.prototype.init = function () {
  2577. flatJSON(this, this.options.data);
  2578. _init.apply(this, Array.prototype.slice.apply(arguments));
  2579. };
  2580. BootstrapTable.prototype.initTable = function () {
  2581. flatJSON(this, this.options.data);
  2582. _initTable.apply(this, Array.prototype.slice.apply(arguments));
  2583. };
  2584. //Main functions
  2585. var sd = {
  2586. flat: function (element) {
  2587. var result = {};
  2588. function recurse(cur, prop) {
  2589. if (Object(cur) !== cur) {
  2590. result[prop] = cur;
  2591. } else if ($.isArray(cur)) {
  2592. for (var i = 0, l = cur.length; i < l; i++) {
  2593. recurse(cur[i], prop ? prop + "." + i : "" + i);
  2594. if (l == 0) {
  2595. result[prop] = [];
  2596. }
  2597. }
  2598. } else {
  2599. var isEmpty = true;
  2600. for (var p in cur) {
  2601. isEmpty = false;
  2602. recurse(cur[p], prop ? prop + "." + p : p);
  2603. }
  2604. if (isEmpty) {
  2605. result[prop] = {};
  2606. }
  2607. }
  2608. }
  2609. recurse(element, "");
  2610. return result;
  2611. },
  2612. flatHelper: function (data) {
  2613. var flatArray = [],
  2614. arrayHelper = [];
  2615. if (!$.isArray(data)) {
  2616. arrayHelper.push(data);
  2617. data = arrayHelper;
  2618. }
  2619. $.each(data, function (i, element) {
  2620. flatArray.push(sd.flat(element));
  2621. });
  2622. return flatArray;
  2623. }
  2624. };
  2625. })(jQuery);
  2626. /**
  2627. * @author: Dennis Hernández
  2628. * @webSite: http://djhvscf.github.io/Blog
  2629. * @version: v1.0.0
  2630. *
  2631. * @update zhixin wen <wenzhixin2010@gmail.com>
  2632. */
  2633. !function ($) {
  2634. 'use strict';
  2635. $.extend($.fn.bootstrapTable.defaults, {
  2636. keyEvents: false
  2637. });
  2638. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2639. _init = BootstrapTable.prototype.init;
  2640. BootstrapTable.prototype.init = function () {
  2641. _init.apply(this, Array.prototype.slice.apply(arguments));
  2642. this.initKeyEvents();
  2643. };
  2644. BootstrapTable.prototype.initKeyEvents = function () {
  2645. if (this.options.keyEvents) {
  2646. var that = this;
  2647. $(document).off('keydown').on('keydown', function (e) {
  2648. var $search = that.$toolbar.find('.search input'),
  2649. $refresh = that.$toolbar.find('button[name="refresh"]'),
  2650. $toggle = that.$toolbar.find('button[name="toggle"]'),
  2651. $paginationSwitch = that.$toolbar.find('button[name="paginationSwitch"]');
  2652. if (document.activeElement === $search.get(0)) {
  2653. return true;
  2654. }
  2655. switch (e.keyCode) {
  2656. case 83: //s
  2657. if (!that.options.search) {
  2658. return;
  2659. }
  2660. $search.focus();
  2661. return false;
  2662. case 82: //r
  2663. if (!that.options.showRefresh) {
  2664. return;
  2665. }
  2666. $refresh.click();
  2667. return false;
  2668. case 84: //t
  2669. if (!that.options.showToggle) {
  2670. return;
  2671. }
  2672. $toggle.click();
  2673. return false;
  2674. case 80: //p
  2675. if (!that.options.showPaginationSwitch) {
  2676. return;
  2677. }
  2678. $paginationSwitch.click();
  2679. return false;
  2680. case 37: // left
  2681. if (!that.options.pagination) {
  2682. return;
  2683. }
  2684. that.prevPage();
  2685. return false;
  2686. case 39: // right
  2687. if (!that.options.pagination) {
  2688. return;
  2689. }
  2690. that.nextPage();
  2691. return;
  2692. }
  2693. });
  2694. }
  2695. };
  2696. }(jQuery);
  2697. /**
  2698. * @author: Dennis Hernández
  2699. * @webSite: http://djhvscf.github.io/Blog
  2700. * @version: v1.1.0
  2701. */
  2702. !function ($) {
  2703. 'use strict';
  2704. var resetView = function (that) {
  2705. if (that.options.height || that.options.showFooter) {
  2706. setTimeout(that.resetView(), 1);
  2707. }
  2708. };
  2709. var changeView = function (that, width, height) {
  2710. if (that.options.minHeight) {
  2711. if (checkValuesLessEqual(width, that.options.minWidth) && checkValuesLessEqual(height, that.options.minHeight)) {
  2712. conditionCardView(that);
  2713. } else if (checkValuesGreater(width, that.options.minWidth) && checkValuesGreater(height, that.options.minHeight)) {
  2714. conditionFullView(that);
  2715. }
  2716. } else {
  2717. if (checkValuesLessEqual(width, that.options.minWidth)) {
  2718. conditionCardView(that);
  2719. } else if (checkValuesGreater(width, that.options.minWidth)) {
  2720. conditionFullView(that);
  2721. }
  2722. }
  2723. resetView(that);
  2724. };
  2725. var checkValuesLessEqual = function (currentValue, targetValue) {
  2726. return currentValue <= targetValue;
  2727. };
  2728. var checkValuesGreater = function (currentValue, targetValue) {
  2729. return currentValue > targetValue;
  2730. };
  2731. var conditionCardView = function (that) {
  2732. changeTableView(that, false);
  2733. };
  2734. var conditionFullView = function (that) {
  2735. changeTableView(that, true);
  2736. };
  2737. var changeTableView = function (that, cardViewState) {
  2738. that.options.cardView = cardViewState;
  2739. that.toggleView();
  2740. };
  2741. $.extend($.fn.bootstrapTable.defaults, {
  2742. mobileResponsive: false,
  2743. minWidth: 562,
  2744. minHeight: undefined,
  2745. checkOnInit: true,
  2746. toggled: false
  2747. });
  2748. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2749. _init = BootstrapTable.prototype.init;
  2750. BootstrapTable.prototype.init = function () {
  2751. _init.apply(this, Array.prototype.slice.apply(arguments));
  2752. if (!this.options.mobileResponsive) {
  2753. return;
  2754. }
  2755. if (!this.options.minWidth) {
  2756. return;
  2757. }
  2758. var that = this;
  2759. $(window).resize(function () {
  2760. changeView(that, $(this).width(), $(this).height())
  2761. });
  2762. if (this.options.checkOnInit) {
  2763. changeView(this, $(window).width(), $(window).height());
  2764. }
  2765. };
  2766. }(jQuery);
  2767. /**
  2768. * @author: Brian Huisman
  2769. * @webSite: http://www.greywyvern.com
  2770. * @version: v1.0.0
  2771. * JS function to allow natural sorting on bootstrap-table columns
  2772. * just add data-sorter="alphanum" to any th
  2773. *
  2774. * @update Dennis Hernández <http://djhvscf.github.io/Blog>
  2775. */
  2776. function alphanum(a, b) {
  2777. function chunkify(t) {
  2778. var tz = [],
  2779. x = 0,
  2780. y = -1,
  2781. n = 0,
  2782. i,
  2783. j;
  2784. while (i = (j = t.charAt(x++)).charCodeAt(0)) {
  2785. var m = (i === 46 || (i >= 48 && i <= 57));
  2786. if (m !== n) {
  2787. tz[++y] = "";
  2788. n = m;
  2789. }
  2790. tz[y] += j;
  2791. }
  2792. return tz;
  2793. }
  2794. var aa = chunkify(a);
  2795. var bb = chunkify(b);
  2796. for (x = 0; aa[x] && bb[x]; x++) {
  2797. if (aa[x] !== bb[x]) {
  2798. var c = Number(aa[x]),
  2799. d = Number(bb[x]);
  2800. if (c == aa[x] && d == bb[x]) {
  2801. return c - d;
  2802. } else {
  2803. return (aa[x] > bb[x]) ? 1 : -1;
  2804. }
  2805. }
  2806. }
  2807. return aa.length - bb.length;
  2808. }
  2809. /**
  2810. * @author: Dennis Hernández
  2811. * @webSite: http://djhvscf.github.io/Blog
  2812. * @version: v1.1.0
  2813. */
  2814. !function ($) {
  2815. 'use strict';
  2816. var getFieldIndex = function (columns, field) {
  2817. var index = -1;
  2818. $.each(columns, function (i, column) {
  2819. if (column.field === field) {
  2820. index = i;
  2821. return false;
  2822. }
  2823. return true;
  2824. });
  2825. return index;
  2826. };
  2827. $.extend($.fn.bootstrapTable.defaults, {
  2828. reorderableColumns: false,
  2829. maxMovingRows: 10,
  2830. onReorderColumn: function (headerFields) {
  2831. return false;
  2832. }
  2833. });
  2834. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2835. 'reorder-column.bs.table': 'onReorderColumn'
  2836. });
  2837. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2838. _initHeader = BootstrapTable.prototype.initHeader,
  2839. _toggleColumn = BootstrapTable.prototype.toggleColumn,
  2840. _toggleView = BootstrapTable.prototype.toggleView,
  2841. _resetView = BootstrapTable.prototype.resetView;
  2842. BootstrapTable.prototype.initHeader = function () {
  2843. _initHeader.apply(this, Array.prototype.slice.apply(arguments));
  2844. if (!this.options.reorderableColumns) {
  2845. return;
  2846. }
  2847. this.makeRowsReorderable();
  2848. };
  2849. BootstrapTable.prototype.toggleColumn = function () {
  2850. _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));
  2851. if (!this.options.reorderableColumns) {
  2852. return;
  2853. }
  2854. this.makeRowsReorderable();
  2855. };
  2856. BootstrapTable.prototype.toggleView = function () {
  2857. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  2858. if (!this.options.reorderableColumns) {
  2859. return;
  2860. }
  2861. if (this.options.cardView) {
  2862. return;
  2863. }
  2864. this.makeRowsReorderable();
  2865. };
  2866. BootstrapTable.prototype.resetView = function () {
  2867. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  2868. if (!this.options.reorderableColumns) {
  2869. return;
  2870. }
  2871. this.makeRowsReorderable();
  2872. };
  2873. BootstrapTable.prototype.makeRowsReorderable = function () {
  2874. var that = this;
  2875. try {
  2876. $(this.$el).dragtable('destroy');
  2877. } catch (e) {}
  2878. $(this.$el).dragtable({
  2879. maxMovingRows: that.options.maxMovingRows,
  2880. clickDelay:200,
  2881. beforeStop: function() {
  2882. var ths = [],
  2883. columns = [],
  2884. columnIndex = -1;
  2885. that.$header.find('th').each(function (i) {
  2886. ths.push($(this).data('field'));
  2887. });
  2888. for (var i = 0; i < ths.length; i++ ) {
  2889. columnIndex = getFieldIndex(that.options.columns, ths[i]);
  2890. if (columnIndex !== -1) {
  2891. columns.push(that.options.columns[columnIndex]);
  2892. that.options.columns.splice(columnIndex, 1);
  2893. }
  2894. }
  2895. that.options.columns = that.options.columns.concat(columns);
  2896. that.header.fields = ths;
  2897. that.resetView();
  2898. that.trigger('reorder-column', ths);
  2899. }
  2900. });
  2901. };
  2902. }(jQuery);
  2903. /**
  2904. * @author: Dennis Hernández
  2905. * @webSite: http://djhvscf.github.io/Blog
  2906. * @version: v1.0.0
  2907. */
  2908. !function ($) {
  2909. 'use strict';
  2910. var isSearch = false;
  2911. var rowAttr = function (row, index) {
  2912. return {
  2913. id: 'customId_' + index
  2914. };
  2915. };
  2916. $.extend($.fn.bootstrapTable.defaults, {
  2917. reorderableRows: false,
  2918. onDragStyle: null,
  2919. onDropStyle: null,
  2920. onDragClass: "reorder_rows_onDragClass",
  2921. dragHandle: null,
  2922. useRowAttrFunc: false,
  2923. onReorderRowsDrag: function (table, row) {
  2924. return false;
  2925. },
  2926. onReorderRowsDrop: function (table, row) {
  2927. return false;
  2928. },
  2929. onReorderRow: function (newData) {
  2930. return false;
  2931. }
  2932. });
  2933. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  2934. 'reorder-row.bs.table': 'onReorderRow'
  2935. });
  2936. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  2937. _init = BootstrapTable.prototype.init,
  2938. _initSearch = BootstrapTable.prototype.initSearch;
  2939. BootstrapTable.prototype.init = function () {
  2940. _init.apply(this, Array.prototype.slice.apply(arguments));
  2941. if (!this.options.reorderableRows) {
  2942. return;
  2943. }
  2944. var that = this;
  2945. if (this.options.useRowAttrFunc) {
  2946. this.options.rowAttributes = rowAttr;
  2947. }
  2948. var onPostRows = this.options.onPostRows;
  2949. this.options.onPostRows = function () {
  2950. setTimeout(function () {
  2951. that.makeRowsReorderable();
  2952. onPostRows.apply();
  2953. }, 1);
  2954. };
  2955. };
  2956. BootstrapTable.prototype.initSearch = function () {
  2957. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  2958. if (!this.options.reorderableRows) {
  2959. return;
  2960. }
  2961. //Known issue after search if you reorder the rows the data is not display properly
  2962. //isSearch = true;
  2963. };
  2964. BootstrapTable.prototype.makeRowsReorderable = function () {
  2965. if (this.options.cardView) {
  2966. return;
  2967. }
  2968. var that = this;
  2969. this.$el.tableDnD({
  2970. onDragStyle: that.options.onDragStyle,
  2971. onDropStyle: that.options.onDropStyle,
  2972. onDragClass: that.options.onDragClass,
  2973. onDrop: that.onDrop,
  2974. onDragStart: that.options.onReorderRowsDrag,
  2975. dragHandle: that.options.dragHandle
  2976. });
  2977. };
  2978. BootstrapTable.prototype.onDrop = function (table, row) {
  2979. var tableBs = $(table),
  2980. tableBsData = tableBs.data('bootstrap.table'),
  2981. tableBsOptions = tableBs.data('bootstrap.table').options,
  2982. row = null,
  2983. newData = [];
  2984. for (var i = 0; i < table.tBodies[0].rows.length; i++) {
  2985. row = $(table.tBodies[0].rows[i]);
  2986. newData.push(tableBsOptions.data[row.data('index')]);
  2987. row.data('index', i).attr('data-index', i);
  2988. }
  2989. tableBsOptions.data = newData;
  2990. //Call the user defined function
  2991. tableBsOptions.onReorderRowsDrop.apply(table, row);
  2992. //Call the event reorder-row
  2993. tableBsData.trigger('reorder-row', newData);
  2994. };
  2995. }(jQuery);
  2996. /**
  2997. * @author: Dennis Hernández
  2998. * @webSite: http://djhvscf.github.io/Blog
  2999. * @version: v1.0.0
  3000. */
  3001. (function ($) {
  3002. 'use strict';
  3003. var initResizable = function (that) {
  3004. //Deletes the plugin to re-create it
  3005. that.$el.colResizable({disable: true});
  3006. //Creates the plugin
  3007. that.$el.colResizable({
  3008. liveDrag: that.options.liveDrag,
  3009. fixed: that.options.fixed,
  3010. headerOnly: that.options.headerOnly,
  3011. minWidth: that.options.minWidth,
  3012. hoverCursor: that.options.hoverCursor,
  3013. dragCursor: that.options.dragCursor,
  3014. onResize: that.onResize,
  3015. onDrag: that.options.onResizableDrag
  3016. });
  3017. };
  3018. $.extend($.fn.bootstrapTable.defaults, {
  3019. resizable: false,
  3020. liveDrag: false,
  3021. fixed: true,
  3022. headerOnly: false,
  3023. minWidth: 15,
  3024. hoverCursor: 'e-resize',
  3025. dragCursor: 'e-resize',
  3026. onResizableResize: function (e) {
  3027. return false;
  3028. },
  3029. onResizableDrag: function (e) {
  3030. return false;
  3031. }
  3032. });
  3033. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3034. _toggleView = BootstrapTable.prototype.toggleView,
  3035. _resetView = BootstrapTable.prototype.resetView;
  3036. BootstrapTable.prototype.toggleView = function () {
  3037. _toggleView.apply(this, Array.prototype.slice.apply(arguments));
  3038. if (this.options.resizable && this.options.cardView) {
  3039. //Deletes the plugin
  3040. $(this.$el).colResizable({disable: true});
  3041. }
  3042. };
  3043. BootstrapTable.prototype.resetView = function () {
  3044. var that = this;
  3045. _resetView.apply(this, Array.prototype.slice.apply(arguments));
  3046. if (this.options.resizable) {
  3047. // because in fitHeader function, we use setTimeout(func, 100);
  3048. setTimeout(function () {
  3049. initResizable(that);
  3050. }, 100);
  3051. }
  3052. };
  3053. BootstrapTable.prototype.onResize = function (e) {
  3054. var that = $(e.currentTarget);
  3055. that.bootstrapTable('resetView');
  3056. that.data('bootstrap.table').options.onResizableResize.apply(e);
  3057. }
  3058. })(jQuery);
  3059. /**
  3060. * @author: aperez <aperez@datadec.es>
  3061. * @version: v2.0.0
  3062. *
  3063. * @update Dennis Hernández <http://djhvscf.github.io/Blog>
  3064. */
  3065. !function($) {
  3066. 'use strict';
  3067. var firstLoad = false;
  3068. var sprintf = function(str) {
  3069. var args = arguments,
  3070. flag = true,
  3071. i = 1;
  3072. str = str.replace(/%s/g, function() {
  3073. var arg = args[i++];
  3074. if (typeof arg === 'undefined') {
  3075. flag = false;
  3076. return '';
  3077. }
  3078. return arg;
  3079. });
  3080. return flag ? str : '';
  3081. };
  3082. var calculateObjectValue = function (self, name, args, defaultValue) {
  3083. if (typeof name === 'string') {
  3084. // support obj.func1.func2
  3085. var names = name.split('.');
  3086. if (names.length > 1) {
  3087. name = window;
  3088. $.each(names, function (i, f) {
  3089. name = name[f];
  3090. });
  3091. } else {
  3092. name = window[name];
  3093. }
  3094. }
  3095. if (typeof name === 'object') {
  3096. return name;
  3097. }
  3098. if (typeof name === 'function') {
  3099. return name.apply(self, args);
  3100. }
  3101. return defaultValue;
  3102. };
  3103. var showAvdSearch = function(pColumns, searchTitle, searchText, that) {
  3104. if (!$("#avdSearchModal").hasClass("modal")) {
  3105. var vModal = "<div id=\"avdSearchModal\" class=\"modal fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"mySmallModalLabel\" aria-hidden=\"true\">";
  3106. vModal += "<div class=\"modal-dialog modal-xs\">";
  3107. vModal += " <div class=\"modal-content\">";
  3108. vModal += " <div class=\"modal-header\">";
  3109. vModal += " <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\" >&times;</button>";
  3110. vModal += sprintf(" <h4 class=\"modal-title\">%s</h4>", searchTitle);
  3111. vModal += " </div>";
  3112. vModal += " <div class=\"modal-body modal-body-custom\">";
  3113. vModal += " <div class=\"container-fluid\" id=\"avdSearchModalContent\" style=\"padding-right: 0px;padding-left: 0px;\" >";
  3114. vModal += " </div>";
  3115. vModal += " </div>";
  3116. vModal += " </div>";
  3117. vModal += " </div>";
  3118. vModal += "</div>";
  3119. $("body").append($(vModal));
  3120. var vFormAvd = createFormAvd(pColumns, searchText, that),
  3121. timeoutId = 0;;
  3122. $('#avdSearchModalContent').append(vFormAvd.join(''));
  3123. $('#' + that.options.idForm).off('keyup blur', 'input').on('keyup blur', 'input', function (event) {
  3124. clearTimeout(timeoutId);
  3125. timeoutId = setTimeout(function () {
  3126. that.onColumnAdvancedSearch(event);
  3127. }, that.options.searchTimeOut);
  3128. });
  3129. $("#btnCloseAvd").click(function() {
  3130. $("#avdSearchModal").modal('hide');
  3131. });
  3132. $("#avdSearchModal").modal();
  3133. } else {
  3134. $("#avdSearchModal").modal();
  3135. }
  3136. };
  3137. var createFormAvd = function(pColumns, searchText, that) {
  3138. var htmlForm = [];
  3139. htmlForm.push(sprintf('<form class="form-horizontal" id="%s" action="%s" >', that.options.idForm, that.options.actionForm));
  3140. for (var i in pColumns) {
  3141. var vObjCol = pColumns[i];
  3142. if (!vObjCol.checkbox && vObjCol.visible && vObjCol.searchable) {
  3143. htmlForm.push('<div class="form-group">');
  3144. htmlForm.push(sprintf('<label class="col-sm-4 control-label">%s</label>', vObjCol.title));
  3145. htmlForm.push('<div class="col-sm-6">');
  3146. htmlForm.push(sprintf('<input type="text" class="form-control input-md" name="%s" placeholder="%s" id="%s">', vObjCol.field, vObjCol.title, vObjCol.field));
  3147. htmlForm.push('</div>');
  3148. htmlForm.push('</div>');
  3149. }
  3150. }
  3151. htmlForm.push('<div class="form-group">');
  3152. htmlForm.push('<div class="col-sm-offset-9 col-sm-3">');
  3153. htmlForm.push(sprintf('<button type="button" id="btnCloseAvd" class="btn btn-default" >%s</button>', searchText));
  3154. htmlForm.push('</div>');
  3155. htmlForm.push('</div>');
  3156. htmlForm.push('</form>');
  3157. return htmlForm;
  3158. };
  3159. $.extend($.fn.bootstrapTable.defaults, {
  3160. advancedSearch: false,
  3161. idForm: 'advancedSearch',
  3162. actionForm: '',
  3163. idTable: undefined,
  3164. onColumnAdvancedSearch: function (field, text) {
  3165. return false;
  3166. }
  3167. });
  3168. $.extend($.fn.bootstrapTable.defaults.icons, {
  3169. advancedSearchIcon: 'glyphicon-chevron-down'
  3170. });
  3171. $.extend($.fn.bootstrapTable.Constructor.EVENTS, {
  3172. 'column-advanced-search.bs.table': 'onColumnAdvancedSearch'
  3173. });
  3174. $.extend($.fn.bootstrapTable.locales, {
  3175. formatAdvancedSearch: function() {
  3176. return 'Advanced search';
  3177. },
  3178. formatAdvancedCloseButton: function() {
  3179. return "Close";
  3180. }
  3181. });
  3182. $.extend($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  3183. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  3184. _initToolbar = BootstrapTable.prototype.initToolbar,
  3185. _load = BootstrapTable.prototype.load,
  3186. _initSearch = BootstrapTable.prototype.initSearch;
  3187. BootstrapTable.prototype.initToolbar = function() {
  3188. _initToolbar.apply(this, Array.prototype.slice.apply(arguments));
  3189. if (!this.options.search) {
  3190. return;
  3191. }
  3192. if (!this.options.advancedSearch) {
  3193. return;
  3194. }
  3195. var that = this,
  3196. html = [];
  3197. html.push(sprintf('<div class="columns columns-%s btn-group pull-%s" role="group">', this.options.buttonsAlign, this.options.buttonsAlign));
  3198. html.push(sprintf('<button class="btn btn-default%s' + '" type="button" name="advancedSearch" title="%s">', that.options.iconSize === undefined ? '' : ' btn-' + that.options.iconSize, that.options.formatAdvancedSearch()));
  3199. html.push(sprintf('<i class="%s %s"></i>', that.options.iconsPrefix, that.options.icons.advancedSearchIcon))
  3200. html.push('</button></div>');
  3201. that.$toolbar.prepend(html.join(''));
  3202. that.$toolbar.find('button[name="advancedSearch"]')
  3203. .off('click').on('click', function() {
  3204. showAvdSearch(that.options.columns, that.options.formatAdvancedSearch(), that.options.formatAdvancedCloseButton(), that);
  3205. });
  3206. };
  3207. BootstrapTable.prototype.load = function(data) {
  3208. _load.apply(this, Array.prototype.slice.apply(arguments));
  3209. if (typeof this.options.idTable === 'undefined') {
  3210. return;
  3211. } else {
  3212. if (!firstLoad) {
  3213. var height = parseInt($(".bootstrap-table").height());
  3214. height += 10;
  3215. $("#" + this.options.idTable).bootstrapTable("resetView", {height: height});
  3216. firstLoad = true;
  3217. }
  3218. }
  3219. };
  3220. BootstrapTable.prototype.initSearch = function () {
  3221. _initSearch.apply(this, Array.prototype.slice.apply(arguments));
  3222. var that = this;
  3223. var fp = $.isEmptyObject(this.filterColumnsPartial) ? null : this.filterColumnsPartial;
  3224. this.data = fp ? $.grep(this.data, function (item, i) {
  3225. for (var key in fp) {
  3226. var fval = fp[key].toLowerCase();
  3227. var value = item[key];
  3228. value = calculateObjectValue(that.header,
  3229. that.header.formatters[$.inArray(key, that.header.fields)],
  3230. [value, item, i], value);
  3231. if (!($.inArray(key, that.header.fields) !== -1 &&
  3232. (typeof value === 'string' || typeof value === 'number') &&
  3233. (value + '').toLowerCase().indexOf(fval) !== -1)) {
  3234. return false;
  3235. }
  3236. }
  3237. return true;
  3238. }) : this.data;
  3239. };
  3240. BootstrapTable.prototype.onColumnAdvancedSearch = function (event) {
  3241. var text = $.trim($(event.currentTarget).val());
  3242. var $field = $(event.currentTarget)[0].id;
  3243. if ($.isEmptyObject(this.filterColumnsPartial)) {
  3244. this.filterColumnsPartial = {};
  3245. }
  3246. if (text) {
  3247. this.filterColumnsPartial[$field] = text;
  3248. } else {
  3249. delete this.filterColumnsPartial[$field];
  3250. }
  3251. this.options.pageNumber = 1;
  3252. this.onSearch(event);
  3253. this.updatePagination();
  3254. this.trigger('column-advanced-search', $field, text);
  3255. };
  3256. }(jQuery);