index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. let bootstrapVersion = 4
  2. try {
  3. const rawVersion = $.fn.dropdown.Constructor.VERSION
  4. // Only try to parse VERSION if is is defined.
  5. // It is undefined in older versions of Bootstrap (tested with 3.1.1).
  6. if (rawVersion !== undefined) {
  7. bootstrapVersion = parseInt(rawVersion, 10)
  8. }
  9. } catch (e) {
  10. // ignore
  11. }
  12. const CONSTANTS = {
  13. 3: {
  14. iconsPrefix: 'glyphicon',
  15. icons: {
  16. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  17. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  18. refresh: 'glyphicon-refresh icon-refresh',
  19. toggleOff: 'glyphicon-list-alt icon-list-alt',
  20. toggleOn: 'glyphicon-list-alt icon-list-alt',
  21. columns: 'glyphicon-th icon-th',
  22. detailOpen: 'glyphicon-plus icon-plus',
  23. detailClose: 'glyphicon-minus icon-minus',
  24. fullscreen: 'glyphicon-fullscreen'
  25. },
  26. classes: {
  27. buttonsPrefix: 'btn',
  28. buttons: 'default',
  29. buttonsGroup: 'btn-group',
  30. buttonsDropdown: 'btn-group',
  31. pull: 'pull',
  32. inputGroup: '',
  33. input: 'form-control',
  34. paginationDropdown: 'btn-group dropdown',
  35. dropup: 'dropup',
  36. dropdownActive: 'active',
  37. paginationActive: 'active',
  38. buttonActive: 'active'
  39. },
  40. html: {
  41. toobarDropdow: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  42. toobarDropdowItem: '<li role="menuitem"><label>%s</label></li>',
  43. pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  44. pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>',
  45. dropdownCaret: '<span class="caret"></span>',
  46. pagination: ['<ul class="pagination%s">', '</ul>'],
  47. paginationItem: '<li class="page-item%s"><a class="page-link" href="#">%s</a></li>',
  48. icon: '<i class="%s %s"></i>'
  49. }
  50. },
  51. 4: {
  52. iconsPrefix: 'fa',
  53. icons: {
  54. paginationSwitchDown: 'fa-caret-square-down',
  55. paginationSwitchUp: 'fa-caret-square-up',
  56. refresh: 'fa-sync',
  57. toggleOff: 'fa-toggle-off',
  58. toggleOn: 'fa-toggle-on',
  59. columns: 'fa-th-list',
  60. fullscreen: 'fa-arrows-alt',
  61. detailOpen: 'fa-plus',
  62. detailClose: 'fa-minus'
  63. },
  64. classes: {
  65. buttonsPrefix: 'btn',
  66. buttons: 'secondary',
  67. buttonsGroup: 'btn-group',
  68. buttonsDropdown: 'btn-group',
  69. pull: 'float',
  70. inputGroup: '',
  71. input: 'form-control',
  72. paginationDropdown: 'btn-group dropdown',
  73. dropup: 'dropup',
  74. dropdownActive: 'active',
  75. paginationActive: 'active',
  76. buttonActive: 'active'
  77. },
  78. html: {
  79. toobarDropdow: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'],
  80. toobarDropdowItem: '<label class="dropdown-item">%s</label>',
  81. pageDropdown: ['<div class="dropdown-menu">', '</div>'],
  82. pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>',
  83. dropdownCaret: '<span class="caret"></span>',
  84. pagination: ['<ul class="pagination%s">', '</ul>'],
  85. paginationItem: '<li class="page-item%s"><a class="page-link" href="#">%s</a></li>',
  86. icon: '<i class="%s %s"></i>'
  87. }
  88. }
  89. }[bootstrapVersion]
  90. const DEFAULTS = {
  91. height: undefined,
  92. classes: 'table table-bordered table-hover',
  93. theadClasses: '',
  94. rowStyle (row, index) {
  95. return {}
  96. },
  97. rowAttributes (row, index) {
  98. return {}
  99. },
  100. undefinedText: '-',
  101. locale: undefined,
  102. sortable: true,
  103. sortClass: undefined,
  104. silentSort: true,
  105. sortName: undefined,
  106. sortOrder: 'asc',
  107. sortStable: false,
  108. rememberOrder: false,
  109. customSort: undefined,
  110. columns: [
  111. []
  112. ],
  113. data: [],
  114. url: undefined,
  115. method: 'get',
  116. cache: true,
  117. contentType: 'application/json',
  118. dataType: 'json',
  119. ajax: undefined,
  120. ajaxOptions: {},
  121. queryParams (params) {
  122. return params
  123. },
  124. queryParamsType: 'limit', // 'limit', undefined
  125. responseHandler (res) {
  126. return res
  127. },
  128. totalField: 'total',
  129. totalNotFilteredField: 'totalNotFiltered',
  130. dataField: 'rows',
  131. pagination: false,
  132. onlyInfoPagination: false,
  133. showExtendedPagination: false,
  134. paginationLoop: true,
  135. sidePagination: 'client', // client or server
  136. totalRows: 0,
  137. totalNotFiltered: 0,
  138. pageNumber: 1,
  139. pageSize: 10,
  140. pageList: [10, 25, 50, 100],
  141. paginationHAlign: 'right', // right, left
  142. paginationVAlign: 'bottom', // bottom, top, both
  143. paginationDetailHAlign: 'left', // right, left
  144. paginationPreText: '&lsaquo;',
  145. paginationNextText: '&rsaquo;',
  146. paginationSuccessivelySize: 5, // Maximum successively number of pages in a row
  147. paginationPagesBySide: 1, // Number of pages on each side (right, left) of the current page.
  148. paginationUseIntermediate: false, // Calculate intermediate pages for quick access
  149. search: false,
  150. searchOnEnterKey: false,
  151. strictSearch: false,
  152. trimOnSearch: true,
  153. searchAlign: 'right',
  154. searchTimeOut: 500,
  155. searchText: '',
  156. customSearch: undefined,
  157. showHeader: true,
  158. showFooter: false,
  159. footerStyle (row, index) {
  160. return {}
  161. },
  162. showColumns: false,
  163. minimumCountColumns: 1,
  164. showPaginationSwitch: false,
  165. showRefresh: false,
  166. showToggle: false,
  167. showFullscreen: false,
  168. smartDisplay: true,
  169. escape: false,
  170. filterOptions: {
  171. 'filterAlgorithm': 'and' // and means all given filter must match, or means one of the given filter must match
  172. },
  173. idField: undefined,
  174. selectItemName: 'btSelectItem',
  175. clickToSelect: false,
  176. ignoreClickToSelectOn ({tagName}) {
  177. return ['A', 'BUTTON'].includes(tagName)
  178. },
  179. singleSelect: false,
  180. checkboxHeader: true,
  181. maintainMetaData: false,
  182. multipleSelectRow: false,
  183. uniqueId: undefined,
  184. cardView: false,
  185. detailView: false,
  186. detailViewIcon: true,
  187. detailViewByClick: false,
  188. detailFormatter (index, row) {
  189. return ''
  190. },
  191. detailFilter (index, row) {
  192. return true
  193. },
  194. toolbar: undefined,
  195. toolbarAlign: 'left',
  196. buttonsToolbar: undefined,
  197. buttonsAlign: 'right',
  198. buttonsPrefix: CONSTANTS.classes.buttonsPrefix,
  199. buttonsClass: CONSTANTS.classes.buttons,
  200. icons: CONSTANTS.icons,
  201. iconSize: undefined,
  202. iconsPrefix: CONSTANTS.iconsPrefix, // glyphicon or fa(font-awesome)
  203. onAll (name, args) {
  204. return false
  205. },
  206. onClickCell (field, value, row, $element) {
  207. return false
  208. },
  209. onDblClickCell (field, value, row, $element) {
  210. return false
  211. },
  212. onClickRow (item, $element) {
  213. return false
  214. },
  215. onDblClickRow (item, $element) {
  216. return false
  217. },
  218. onSort (name, order) {
  219. return false
  220. },
  221. onCheck (row) {
  222. return false
  223. },
  224. onUncheck (row) {
  225. return false
  226. },
  227. onCheckAll (rows) {
  228. return false
  229. },
  230. onUncheckAll (rows) {
  231. return false
  232. },
  233. onCheckSome (rows) {
  234. return false
  235. },
  236. onUncheckSome (rows) {
  237. return false
  238. },
  239. onLoadSuccess (data) {
  240. return false
  241. },
  242. onLoadError (status) {
  243. return false
  244. },
  245. onColumnSwitch (field, checked) {
  246. return false
  247. },
  248. onPageChange (number, size) {
  249. return false
  250. },
  251. onSearch (text) {
  252. return false
  253. },
  254. onToggle (cardView) {
  255. return false
  256. },
  257. onPreBody (data) {
  258. return false
  259. },
  260. onPostBody () {
  261. return false
  262. },
  263. onPostHeader () {
  264. return false
  265. },
  266. onPostFooter () {
  267. return false
  268. },
  269. onExpandRow (index, row, $detail) {
  270. return false
  271. },
  272. onCollapseRow (index, row) {
  273. return false
  274. },
  275. onRefreshOptions (options) {
  276. return false
  277. },
  278. onRefresh (params) {
  279. return false
  280. },
  281. onResetView () {
  282. return false
  283. },
  284. onScrollBody () {
  285. return false
  286. }
  287. }
  288. const EN = {
  289. formatLoadingMessage () {
  290. return 'Loading, please wait'
  291. },
  292. formatRecordsPerPage (pageNumber) {
  293. return `${pageNumber} rows per page`
  294. },
  295. formatShowingRows (pageFrom, pageTo, totalRows, totalNotFiltered) {
  296. if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered < totalRows) {
  297. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows (filtered from ${totalNotFiltered} total entries)`
  298. }
  299. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows`
  300. },
  301. formatDetailPagination (totalRows) {
  302. return `Showing ${totalRows} rows`
  303. },
  304. formatSearch () {
  305. return 'Search'
  306. },
  307. formatNoMatches () {
  308. return 'No matching records found'
  309. },
  310. formatPaginationSwitch () {
  311. return 'Hide/Show pagination'
  312. },
  313. formatRefresh () {
  314. return 'Refresh'
  315. },
  316. formatToggle () {
  317. return 'Toggle'
  318. },
  319. formatColumns () {
  320. return 'Columns'
  321. },
  322. formatFullscreen () {
  323. return 'Fullscreen'
  324. },
  325. formatAllRows () {
  326. return 'All'
  327. }
  328. }
  329. const COLUMN_DEFAULTS = {
  330. field: undefined,
  331. title: undefined,
  332. titleTooltip: undefined,
  333. 'class': undefined,
  334. width: undefined,
  335. widthUnit: 'px',
  336. rowspan: undefined,
  337. colspan: undefined,
  338. align: undefined, // left, right, center
  339. halign: undefined, // left, right, center
  340. falign: undefined, // left, right, center
  341. valign: undefined, // top, middle, bottom
  342. cellStyle: undefined,
  343. radio: false,
  344. checkbox: false,
  345. checkboxEnabled: true,
  346. clickToSelect: true,
  347. showSelectTitle: false,
  348. sortable: false,
  349. sortName: undefined,
  350. order: 'asc', // asc, desc
  351. sorter: undefined,
  352. visible: true,
  353. switchable: true,
  354. cardVisible: true,
  355. searchable: true,
  356. formatter: undefined,
  357. footerFormatter: undefined,
  358. detailFormatter: undefined,
  359. searchFormatter: true,
  360. escape: false,
  361. events: undefined
  362. }
  363. const EVENTS = {
  364. 'all.bs.table': 'onAll',
  365. 'click-cell.bs.table': 'onClickCell',
  366. 'dbl-click-cell.bs.table': 'onDblClickCell',
  367. 'click-row.bs.table': 'onClickRow',
  368. 'dbl-click-row.bs.table': 'onDblClickRow',
  369. 'sort.bs.table': 'onSort',
  370. 'check.bs.table': 'onCheck',
  371. 'uncheck.bs.table': 'onUncheck',
  372. 'check-all.bs.table': 'onCheckAll',
  373. 'uncheck-all.bs.table': 'onUncheckAll',
  374. 'check-some.bs.table': 'onCheckSome',
  375. 'uncheck-some.bs.table': 'onUncheckSome',
  376. 'load-success.bs.table': 'onLoadSuccess',
  377. 'load-error.bs.table': 'onLoadError',
  378. 'column-switch.bs.table': 'onColumnSwitch',
  379. 'page-change.bs.table': 'onPageChange',
  380. 'search.bs.table': 'onSearch',
  381. 'toggle.bs.table': 'onToggle',
  382. 'pre-body.bs.table': 'onPreBody',
  383. 'post-body.bs.table': 'onPostBody',
  384. 'post-header.bs.table': 'onPostHeader',
  385. 'post-footer.bs.table': 'onPostFooter',
  386. 'expand-row.bs.table': 'onExpandRow',
  387. 'collapse-row.bs.table': 'onCollapseRow',
  388. 'refresh-options.bs.table': 'onRefreshOptions',
  389. 'reset-view.bs.table': 'onResetView',
  390. 'refresh.bs.table': 'onRefresh',
  391. 'scroll-body.bs.table': 'onScrollBody'
  392. }
  393. Object.assign(DEFAULTS, EN)
  394. export default {
  395. THEME: `bootstrap${bootstrapVersion}`,
  396. CONSTANTS,
  397. DEFAULTS,
  398. COLUMN_DEFAULTS,
  399. EVENTS,
  400. LOCALES: {
  401. en: EN,
  402. 'en-US': EN
  403. }
  404. }