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