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