index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. const VERSION = '1.16.0'
  2. let bootstrapVersion = 4
  3. try {
  4. const rawVersion = $.fn.dropdown.Constructor.VERSION
  5. // Only try to parse VERSION if it is defined.
  6. // It is undefined in older versions of Bootstrap (tested with 3.1.1).
  7. if (rawVersion !== undefined) {
  8. bootstrapVersion = parseInt(rawVersion, 10)
  9. }
  10. } catch (e) {
  11. // ignore
  12. }
  13. const CONSTANTS = {
  14. 3: {
  15. iconsPrefix: 'glyphicon',
  16. icons: {
  17. paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
  18. paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
  19. refresh: 'glyphicon-refresh icon-refresh',
  20. toggleOff: 'glyphicon-list-alt icon-list-alt',
  21. toggleOn: 'glyphicon-list-alt icon-list-alt',
  22. columns: 'glyphicon-th icon-th',
  23. detailOpen: 'glyphicon-plus icon-plus',
  24. detailClose: 'glyphicon-minus icon-minus',
  25. fullscreen: 'glyphicon-fullscreen',
  26. search: 'glyphicon-search',
  27. clearSearch: 'glyphicon-trash'
  28. },
  29. classes: {
  30. buttonsPrefix: 'btn',
  31. buttons: 'default',
  32. buttonsGroup: 'btn-group',
  33. buttonsDropdown: 'btn-group',
  34. pull: 'pull',
  35. inputGroup: 'input-group',
  36. inputPrefix: 'input-',
  37. input: 'form-control',
  38. paginationDropdown: 'btn-group dropdown',
  39. dropup: 'dropup',
  40. dropdownActive: 'active',
  41. paginationActive: 'active',
  42. buttonActive: 'active'
  43. },
  44. html: {
  45. toolbarDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  46. toolbarDropdownItem: '<li class="dropdown-item-marker" role="menuitem"><label>%s</label></li>',
  47. toolbarDropdownSeparator: '<li class="divider"></li>',
  48. pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
  49. pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>',
  50. dropdownCaret: '<span class="caret"></span>',
  51. pagination: ['<ul class="pagination%s">', '</ul>'],
  52. paginationItem: '<li class="page-item%s"><a class="page-link" aria-label="%s" href="javascript:void(0)">%s</a></li>',
  53. icon: '<i class="%s %s"></i>',
  54. inputGroup: '<div class="input-group">%s<span class="input-group-btn">%s</span></div>',
  55. searchInput: '<input class="%s%s" type="text" placeholder="%s">',
  56. searchButton: '<button class="%s" type="button" name="search" title="%s">%s %s</button>',
  57. searchClearButton: '<button class="%s" type="button" name="clearSearch" title="%s">%s %s</button>'
  58. }
  59. },
  60. 4: {
  61. iconsPrefix: 'fa',
  62. icons: {
  63. paginationSwitchDown: 'fa-caret-square-down',
  64. paginationSwitchUp: 'fa-caret-square-up',
  65. refresh: 'fa-sync',
  66. toggleOff: 'fa-toggle-off',
  67. toggleOn: 'fa-toggle-on',
  68. columns: 'fa-th-list',
  69. detailOpen: 'fa-plus',
  70. detailClose: 'fa-minus',
  71. fullscreen: 'fa-arrows-alt',
  72. search: 'fa-search',
  73. clearSearch: 'fa-trash'
  74. },
  75. classes: {
  76. buttonsPrefix: 'btn',
  77. buttons: 'secondary',
  78. buttonsGroup: 'btn-group',
  79. buttonsDropdown: 'btn-group',
  80. pull: 'float',
  81. inputGroup: 'btn-group',
  82. inputPrefix: 'form-control-',
  83. input: 'form-control',
  84. paginationDropdown: 'btn-group dropdown',
  85. dropup: 'dropup',
  86. dropdownActive: 'active',
  87. paginationActive: 'active',
  88. buttonActive: 'active'
  89. },
  90. html: {
  91. toolbarDropdown: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'],
  92. toolbarDropdownItem: '<label class="dropdown-item dropdown-item-marker">%s</label>',
  93. pageDropdown: ['<div class="dropdown-menu">', '</div>'],
  94. pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>',
  95. toolbarDropdownSeparator: '<div class="dropdown-divider"></div>',
  96. dropdownCaret: '<span class="caret"></span>',
  97. pagination: ['<ul class="pagination%s">', '</ul>'],
  98. paginationItem: '<li class="page-item%s"><a class="page-link" aria-label="%s" href="javascript:void(0)">%s</a></li>',
  99. icon: '<i class="%s %s"></i>',
  100. inputGroup: '<div class="input-group">%s<div class="input-group-append">%s</div></div>',
  101. searchInput: '<input class="%s%s" type="text" placeholder="%s">',
  102. searchButton: '<button class="%s" type="button" name="search" title="%s">%s %s</button>',
  103. searchClearButton: '<button class="%s" type="button" name="clearSearch" title="%s">%s %s</button>'
  104. }
  105. }
  106. }[bootstrapVersion]
  107. const DEFAULTS = {
  108. height: undefined,
  109. classes: 'table table-bordered table-hover',
  110. theadClasses: '',
  111. headerStyle (column) {
  112. return {}
  113. },
  114. rowStyle (row, index) {
  115. return {}
  116. },
  117. rowAttributes (row, index) {
  118. return {}
  119. },
  120. undefinedText: '-',
  121. locale: undefined,
  122. virtualScroll: false,
  123. virtualScrollItemHeight: undefined,
  124. sortable: true,
  125. sortClass: undefined,
  126. silentSort: true,
  127. sortName: undefined,
  128. sortOrder: 'asc',
  129. sortStable: false,
  130. rememberOrder: false,
  131. serverSort: true,
  132. customSort: undefined,
  133. columns: [
  134. []
  135. ],
  136. data: [],
  137. url: undefined,
  138. method: 'get',
  139. cache: true,
  140. contentType: 'application/json',
  141. dataType: 'json',
  142. ajax: undefined,
  143. ajaxOptions: {},
  144. queryParams (params) {
  145. return params
  146. },
  147. queryParamsType: 'limit', // 'limit', undefined
  148. responseHandler (res) {
  149. return res
  150. },
  151. totalField: 'total',
  152. totalNotFilteredField: 'totalNotFiltered',
  153. dataField: 'rows',
  154. pagination: false,
  155. onlyInfoPagination: false,
  156. showExtendedPagination: false,
  157. paginationLoop: true,
  158. sidePagination: 'client', // client or server
  159. totalRows: 0,
  160. totalNotFiltered: 0,
  161. pageNumber: 1,
  162. pageSize: 10,
  163. pageList: [10, 25, 50, 100],
  164. paginationHAlign: 'right', // right, left
  165. paginationVAlign: 'bottom', // bottom, top, both
  166. paginationDetailHAlign: 'left', // right, left
  167. paginationPreText: '&lsaquo;',
  168. paginationNextText: '&rsaquo;',
  169. paginationSuccessivelySize: 5, // Maximum successively number of pages in a row
  170. paginationPagesBySide: 1, // Number of pages on each side (right, left) of the current page.
  171. paginationUseIntermediate: false, // Calculate intermediate pages for quick access
  172. search: false,
  173. searchOnEnterKey: false,
  174. strictSearch: false,
  175. visibleSearch: false,
  176. showButtonIcons: true,
  177. showButtonText: false,
  178. showSearchButton: false,
  179. showSearchClearButton: false,
  180. trimOnSearch: true,
  181. searchAlign: 'right',
  182. searchTimeOut: 500,
  183. searchText: '',
  184. customSearch: undefined,
  185. showHeader: true,
  186. showFooter: false,
  187. footerStyle (column) {
  188. return {}
  189. },
  190. showColumns: false,
  191. showColumnsToggleAll: false,
  192. showColumnsSearch: false,
  193. minimumCountColumns: 1,
  194. showPaginationSwitch: false,
  195. showRefresh: false,
  196. showToggle: false,
  197. showFullscreen: false,
  198. smartDisplay: true,
  199. escape: false,
  200. filterOptions: {
  201. filterAlgorithm: 'and'
  202. },
  203. idField: undefined,
  204. selectItemName: 'btSelectItem',
  205. clickToSelect: false,
  206. ignoreClickToSelectOn ({tagName}) {
  207. return ['A', 'BUTTON'].includes(tagName)
  208. },
  209. singleSelect: false,
  210. checkboxHeader: true,
  211. maintainMetaData: false,
  212. multipleSelectRow: false,
  213. uniqueId: undefined,
  214. cardView: false,
  215. detailView: false,
  216. detailViewIcon: true,
  217. detailViewByClick: false,
  218. detailFormatter (index, row) {
  219. return ''
  220. },
  221. detailFilter (index, row) {
  222. return true
  223. },
  224. toolbar: undefined,
  225. toolbarAlign: 'left',
  226. buttonsToolbar: undefined,
  227. buttonsAlign: 'right',
  228. buttonsOrder: ['paginationSwitch', 'refresh', 'toggle', 'fullscreen', 'columns'],
  229. buttonsPrefix: CONSTANTS.classes.buttonsPrefix,
  230. buttonsClass: CONSTANTS.classes.buttons,
  231. icons: CONSTANTS.icons,
  232. html: CONSTANTS.html,
  233. iconSize: undefined,
  234. iconsPrefix: CONSTANTS.iconsPrefix, // glyphicon or fa(font-awesome)
  235. loadingFontSize: 'auto',
  236. loadingTemplate (loadingMessage) {
  237. return `<span class="loading-wrap">
  238. <span class="loading-text">${loadingMessage}</span>
  239. <span class="animation-wrap"><span class="animation-dot"></span></span>
  240. </span>
  241. `
  242. },
  243. onAll (name, args) {
  244. return false
  245. },
  246. onClickCell (field, value, row, $element) {
  247. return false
  248. },
  249. onDblClickCell (field, value, row, $element) {
  250. return false
  251. },
  252. onClickRow (item, $element) {
  253. return false
  254. },
  255. onDblClickRow (item, $element) {
  256. return false
  257. },
  258. onSort (name, order) {
  259. return false
  260. },
  261. onCheck (row) {
  262. return false
  263. },
  264. onUncheck (row) {
  265. return false
  266. },
  267. onCheckAll (rows) {
  268. return false
  269. },
  270. onUncheckAll (rows) {
  271. return false
  272. },
  273. onCheckSome (rows) {
  274. return false
  275. },
  276. onUncheckSome (rows) {
  277. return false
  278. },
  279. onLoadSuccess (data) {
  280. return false
  281. },
  282. onLoadError (status) {
  283. return false
  284. },
  285. onColumnSwitch (field, checked) {
  286. return false
  287. },
  288. onPageChange (number, size) {
  289. return false
  290. },
  291. onSearch (text) {
  292. return false
  293. },
  294. onToggle (cardView) {
  295. return false
  296. },
  297. onPreBody (data) {
  298. return false
  299. },
  300. onPostBody () {
  301. return false
  302. },
  303. onPostHeader () {
  304. return false
  305. },
  306. onPostFooter () {
  307. return false
  308. },
  309. onExpandRow (index, row, $detail) {
  310. return false
  311. },
  312. onCollapseRow (index, row) {
  313. return false
  314. },
  315. onRefreshOptions (options) {
  316. return false
  317. },
  318. onRefresh (params) {
  319. return false
  320. },
  321. onResetView () {
  322. return false
  323. },
  324. onScrollBody () {
  325. return false
  326. }
  327. }
  328. const EN = {
  329. formatLoadingMessage () {
  330. return 'Loading, please wait'
  331. },
  332. formatRecordsPerPage (pageNumber) {
  333. return `${pageNumber} rows per page`
  334. },
  335. formatShowingRows (pageFrom, pageTo, totalRows, totalNotFiltered) {
  336. if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered > totalRows) {
  337. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows (filtered from ${totalNotFiltered} total rows)`
  338. }
  339. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows`
  340. },
  341. formatSRPaginationPreText () {
  342. return 'previous page'
  343. },
  344. formatSRPaginationPageText (page) {
  345. return `to page ${page}`
  346. },
  347. formatSRPaginationNextText () {
  348. return 'next page'
  349. },
  350. formatDetailPagination (totalRows) {
  351. return `Showing ${totalRows} rows`
  352. },
  353. formatSearch () {
  354. return 'Search'
  355. },
  356. formatClearSearch () {
  357. return 'Clear Search'
  358. },
  359. formatNoMatches () {
  360. return 'No matching records found'
  361. },
  362. formatPaginationSwitch () {
  363. return 'Hide/Show pagination'
  364. },
  365. formatPaginationSwitchDown () {
  366. return 'Show pagination'
  367. },
  368. formatPaginationSwitchUp () {
  369. return 'Hide pagination'
  370. },
  371. formatRefresh () {
  372. return 'Refresh'
  373. },
  374. formatToggle () {
  375. return 'Toggle'
  376. },
  377. formatToggleOn () {
  378. return 'Show card view'
  379. },
  380. formatToggleOff () {
  381. return 'Hide card view'
  382. },
  383. formatColumns () {
  384. return 'Columns'
  385. },
  386. formatColumnsToggleAll () {
  387. return 'Toggle all'
  388. },
  389. formatFullscreen () {
  390. return 'Fullscreen'
  391. },
  392. formatAllRows () {
  393. return 'All'
  394. }
  395. }
  396. const COLUMN_DEFAULTS = {
  397. field: undefined,
  398. title: undefined,
  399. titleTooltip: undefined,
  400. 'class': undefined,
  401. width: undefined,
  402. widthUnit: 'px',
  403. rowspan: undefined,
  404. colspan: undefined,
  405. align: undefined, // left, right, center
  406. halign: undefined, // left, right, center
  407. falign: undefined, // left, right, center
  408. valign: undefined, // top, middle, bottom
  409. cellStyle: undefined,
  410. radio: false,
  411. checkbox: false,
  412. checkboxEnabled: true,
  413. clickToSelect: true,
  414. showSelectTitle: false,
  415. sortable: false,
  416. sortName: undefined,
  417. order: 'asc', // asc, desc
  418. sorter: undefined,
  419. visible: true,
  420. switchable: true,
  421. cardVisible: true,
  422. searchable: true,
  423. formatter: undefined,
  424. footerFormatter: undefined,
  425. detailFormatter: undefined,
  426. searchFormatter: true,
  427. escape: false,
  428. events: undefined
  429. }
  430. const METHODS = [
  431. 'getOptions',
  432. 'refreshOptions',
  433. 'getData',
  434. 'getSelections', 'getAllSelections',
  435. 'load', 'append', 'prepend',
  436. 'remove', 'removeAll',
  437. 'insertRow', 'updateRow',
  438. 'getRowByUniqueId', 'updateByUniqueId', 'removeByUniqueId',
  439. 'updateCell', 'updateCellByUniqueId',
  440. 'showRow', 'hideRow', 'getHiddenRows',
  441. 'showColumn', 'hideColumn',
  442. 'getVisibleColumns', 'getHiddenColumns',
  443. 'showAllColumns', 'hideAllColumns',
  444. 'mergeCells',
  445. 'checkAll', 'uncheckAll', 'checkInvert',
  446. 'check', 'uncheck',
  447. 'checkBy', 'uncheckBy',
  448. 'refresh',
  449. 'destroy',
  450. 'resetView',
  451. 'showLoading', 'hideLoading',
  452. 'togglePagination', 'toggleFullscreen', 'toggleView',
  453. 'resetSearch',
  454. 'filterBy',
  455. 'scrollTo', 'getScrollPosition',
  456. 'selectPage', 'prevPage', 'nextPage',
  457. 'toggleDetailView',
  458. 'expandRow', 'collapseRow',
  459. 'expandAllRows', 'collapseAllRows',
  460. 'updateColumnTitle', 'updateFormatText'
  461. ]
  462. const EVENTS = {
  463. 'all.bs.table': 'onAll',
  464. 'click-row.bs.table': 'onClickRow',
  465. 'dbl-click-row.bs.table': 'onDblClickRow',
  466. 'click-cell.bs.table': 'onClickCell',
  467. 'dbl-click-cell.bs.table': 'onDblClickCell',
  468. 'sort.bs.table': 'onSort',
  469. 'check.bs.table': 'onCheck',
  470. 'uncheck.bs.table': 'onUncheck',
  471. 'check-all.bs.table': 'onCheckAll',
  472. 'uncheck-all.bs.table': 'onUncheckAll',
  473. 'check-some.bs.table': 'onCheckSome',
  474. 'uncheck-some.bs.table': 'onUncheckSome',
  475. 'load-success.bs.table': 'onLoadSuccess',
  476. 'load-error.bs.table': 'onLoadError',
  477. 'column-switch.bs.table': 'onColumnSwitch',
  478. 'page-change.bs.table': 'onPageChange',
  479. 'search.bs.table': 'onSearch',
  480. 'toggle.bs.table': 'onToggle',
  481. 'pre-body.bs.table': 'onPreBody',
  482. 'post-body.bs.table': 'onPostBody',
  483. 'post-header.bs.table': 'onPostHeader',
  484. 'post-footer.bs.table': 'onPostFooter',
  485. 'expand-row.bs.table': 'onExpandRow',
  486. 'collapse-row.bs.table': 'onCollapseRow',
  487. 'refresh-options.bs.table': 'onRefreshOptions',
  488. 'reset-view.bs.table': 'onResetView',
  489. 'refresh.bs.table': 'onRefresh',
  490. 'scroll-body.bs.table': 'onScrollBody'
  491. }
  492. Object.assign(DEFAULTS, EN)
  493. export default {
  494. VERSION,
  495. THEME: `bootstrap${bootstrapVersion}`,
  496. CONSTANTS,
  497. DEFAULTS,
  498. COLUMN_DEFAULTS,
  499. METHODS,
  500. EVENTS,
  501. LOCALES: {
  502. en: EN,
  503. 'en-US': EN
  504. }
  505. }