index.js 12 KB

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