index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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. detailViewAlign: 'left',
  219. detailFormatter (index, row) {
  220. return ''
  221. },
  222. detailFilter (index, row) {
  223. return true
  224. },
  225. toolbar: undefined,
  226. toolbarAlign: 'left',
  227. buttonsToolbar: undefined,
  228. buttonsAlign: 'right',
  229. buttonsOrder: ['paginationSwitch', 'refresh', 'toggle', 'fullscreen', 'columns'],
  230. buttonsPrefix: CONSTANTS.classes.buttonsPrefix,
  231. buttonsClass: CONSTANTS.classes.buttons,
  232. icons: CONSTANTS.icons,
  233. html: CONSTANTS.html,
  234. iconSize: undefined,
  235. iconsPrefix: CONSTANTS.iconsPrefix, // glyphicon or fa(font-awesome)
  236. loadingFontSize: 'auto',
  237. loadingTemplate (loadingMessage) {
  238. return `<span class="loading-wrap">
  239. <span class="loading-text">${loadingMessage}</span>
  240. <span class="animation-wrap"><span class="animation-dot"></span></span>
  241. </span>
  242. `
  243. },
  244. onAll (name, args) {
  245. return false
  246. },
  247. onClickCell (field, value, row, $element) {
  248. return false
  249. },
  250. onDblClickCell (field, value, row, $element) {
  251. return false
  252. },
  253. onClickRow (item, $element) {
  254. return false
  255. },
  256. onDblClickRow (item, $element) {
  257. return false
  258. },
  259. onSort (name, order) {
  260. return false
  261. },
  262. onCheck (row) {
  263. return false
  264. },
  265. onUncheck (row) {
  266. return false
  267. },
  268. onCheckAll (rows) {
  269. return false
  270. },
  271. onUncheckAll (rows) {
  272. return false
  273. },
  274. onCheckSome (rows) {
  275. return false
  276. },
  277. onUncheckSome (rows) {
  278. return false
  279. },
  280. onLoadSuccess (data) {
  281. return false
  282. },
  283. onLoadError (status) {
  284. return false
  285. },
  286. onColumnSwitch (field, checked) {
  287. return false
  288. },
  289. onPageChange (number, size) {
  290. return false
  291. },
  292. onSearch (text) {
  293. return false
  294. },
  295. onToggle (cardView) {
  296. return false
  297. },
  298. onPreBody (data) {
  299. return false
  300. },
  301. onPostBody () {
  302. return false
  303. },
  304. onPostHeader () {
  305. return false
  306. },
  307. onPostFooter () {
  308. return false
  309. },
  310. onExpandRow (index, row, $detail) {
  311. return false
  312. },
  313. onCollapseRow (index, row) {
  314. return false
  315. },
  316. onRefreshOptions (options) {
  317. return false
  318. },
  319. onRefresh (params) {
  320. return false
  321. },
  322. onResetView () {
  323. return false
  324. },
  325. onScrollBody () {
  326. return false
  327. }
  328. }
  329. const EN = {
  330. formatLoadingMessage () {
  331. return 'Loading, please wait'
  332. },
  333. formatRecordsPerPage (pageNumber) {
  334. return `${pageNumber} rows per page`
  335. },
  336. formatShowingRows (pageFrom, pageTo, totalRows, totalNotFiltered) {
  337. if (totalNotFiltered !== undefined && totalNotFiltered > 0 && totalNotFiltered > totalRows) {
  338. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows (filtered from ${totalNotFiltered} total rows)`
  339. }
  340. return `Showing ${pageFrom} to ${pageTo} of ${totalRows} rows`
  341. },
  342. formatSRPaginationPreText () {
  343. return 'previous page'
  344. },
  345. formatSRPaginationPageText (page) {
  346. return `to page ${page}`
  347. },
  348. formatSRPaginationNextText () {
  349. return 'next page'
  350. },
  351. formatDetailPagination (totalRows) {
  352. return `Showing ${totalRows} rows`
  353. },
  354. formatSearch () {
  355. return 'Search'
  356. },
  357. formatClearSearch () {
  358. return 'Clear Search'
  359. },
  360. formatNoMatches () {
  361. return 'No matching records found'
  362. },
  363. formatPaginationSwitch () {
  364. return 'Hide/Show pagination'
  365. },
  366. formatPaginationSwitchDown () {
  367. return 'Show pagination'
  368. },
  369. formatPaginationSwitchUp () {
  370. return 'Hide pagination'
  371. },
  372. formatRefresh () {
  373. return 'Refresh'
  374. },
  375. formatToggle () {
  376. return 'Toggle'
  377. },
  378. formatToggleOn () {
  379. return 'Show card view'
  380. },
  381. formatToggleOff () {
  382. return 'Hide card view'
  383. },
  384. formatColumns () {
  385. return 'Columns'
  386. },
  387. formatColumnsToggleAll () {
  388. return 'Toggle all'
  389. },
  390. formatFullscreen () {
  391. return 'Fullscreen'
  392. },
  393. formatAllRows () {
  394. return 'All'
  395. }
  396. }
  397. const COLUMN_DEFAULTS = {
  398. field: undefined,
  399. title: undefined,
  400. titleTooltip: undefined,
  401. 'class': undefined,
  402. width: undefined,
  403. widthUnit: 'px',
  404. rowspan: undefined,
  405. colspan: undefined,
  406. align: undefined, // left, right, center
  407. halign: undefined, // left, right, center
  408. falign: undefined, // left, right, center
  409. valign: undefined, // top, middle, bottom
  410. cellStyle: undefined,
  411. radio: false,
  412. checkbox: false,
  413. checkboxEnabled: true,
  414. clickToSelect: true,
  415. showSelectTitle: false,
  416. sortable: false,
  417. sortName: undefined,
  418. order: 'asc', // asc, desc
  419. sorter: undefined,
  420. visible: true,
  421. switchable: true,
  422. cardVisible: true,
  423. searchable: true,
  424. formatter: undefined,
  425. footerFormatter: undefined,
  426. detailFormatter: undefined,
  427. searchFormatter: true,
  428. escape: false,
  429. events: undefined
  430. }
  431. const METHODS = [
  432. 'getOptions',
  433. 'refreshOptions',
  434. 'getData',
  435. 'getSelections', 'getAllSelections',
  436. 'load', 'append', 'prepend',
  437. 'remove', 'removeAll',
  438. 'insertRow', 'updateRow',
  439. 'getRowByUniqueId', 'updateByUniqueId', 'removeByUniqueId',
  440. 'updateCell', 'updateCellByUniqueId',
  441. 'showRow', 'hideRow', 'getHiddenRows',
  442. 'showColumn', 'hideColumn',
  443. 'getVisibleColumns', 'getHiddenColumns',
  444. 'showAllColumns', 'hideAllColumns',
  445. 'mergeCells',
  446. 'checkAll', 'uncheckAll', 'checkInvert',
  447. 'check', 'uncheck',
  448. 'checkBy', 'uncheckBy',
  449. 'refresh',
  450. 'destroy',
  451. 'resetView',
  452. 'showLoading', 'hideLoading',
  453. 'togglePagination', 'toggleFullscreen', 'toggleView',
  454. 'resetSearch',
  455. 'filterBy',
  456. 'scrollTo', 'getScrollPosition',
  457. 'selectPage', 'prevPage', 'nextPage',
  458. 'toggleDetailView',
  459. 'expandRow', 'collapseRow', 'expandRowByUniqueId', 'collapseRowByUniqueId',
  460. 'expandAllRows', 'collapseAllRows',
  461. 'updateColumnTitle', 'updateFormatText'
  462. ]
  463. const EVENTS = {
  464. 'all.bs.table': 'onAll',
  465. 'click-row.bs.table': 'onClickRow',
  466. 'dbl-click-row.bs.table': 'onDblClickRow',
  467. 'click-cell.bs.table': 'onClickCell',
  468. 'dbl-click-cell.bs.table': 'onDblClickCell',
  469. 'sort.bs.table': 'onSort',
  470. 'check.bs.table': 'onCheck',
  471. 'uncheck.bs.table': 'onUncheck',
  472. 'check-all.bs.table': 'onCheckAll',
  473. 'uncheck-all.bs.table': 'onUncheckAll',
  474. 'check-some.bs.table': 'onCheckSome',
  475. 'uncheck-some.bs.table': 'onUncheckSome',
  476. 'load-success.bs.table': 'onLoadSuccess',
  477. 'load-error.bs.table': 'onLoadError',
  478. 'column-switch.bs.table': 'onColumnSwitch',
  479. 'page-change.bs.table': 'onPageChange',
  480. 'search.bs.table': 'onSearch',
  481. 'toggle.bs.table': 'onToggle',
  482. 'pre-body.bs.table': 'onPreBody',
  483. 'post-body.bs.table': 'onPostBody',
  484. 'post-header.bs.table': 'onPostHeader',
  485. 'post-footer.bs.table': 'onPostFooter',
  486. 'expand-row.bs.table': 'onExpandRow',
  487. 'collapse-row.bs.table': 'onCollapseRow',
  488. 'refresh-options.bs.table': 'onRefreshOptions',
  489. 'reset-view.bs.table': 'onResetView',
  490. 'refresh.bs.table': 'onRefresh',
  491. 'scroll-body.bs.table': 'onScrollBody'
  492. }
  493. Object.assign(DEFAULTS, EN)
  494. export default {
  495. VERSION,
  496. THEME: `bootstrap${bootstrapVersion}`,
  497. CONSTANTS,
  498. DEFAULTS,
  499. COLUMN_DEFAULTS,
  500. METHODS,
  501. EVENTS,
  502. LOCALES: {
  503. en: EN,
  504. 'en-US': EN
  505. }
  506. }