1 | (function (global, factory) {
|
2 | if (typeof define === "function" && define.amd) {
|
3 | define([], factory);
|
4 | } else if (typeof exports !== "undefined") {
|
5 | factory();
|
6 | } else {
|
7 | var mod = {
|
8 | exports: {}
|
9 | };
|
10 | factory();
|
11 | global.bootstrapTable = mod.exports;
|
12 | }
|
13 | })(this, function () {
|
14 | 'use strict';
|
15 |
|
16 | function _classCallCheck(instance, Constructor) {
|
17 | if (!(instance instanceof Constructor)) {
|
18 | throw new TypeError("Cannot call a class as a function");
|
19 | }
|
20 | }
|
21 |
|
22 | var _createClass = function () {
|
23 | function defineProperties(target, props) {
|
24 | for (var i = 0; i < props.length; i++) {
|
25 | var descriptor = props[i];
|
26 | descriptor.enumerable = descriptor.enumerable || false;
|
27 | descriptor.configurable = true;
|
28 | if ("value" in descriptor) descriptor.writable = true;
|
29 | Object.defineProperty(target, descriptor.key, descriptor);
|
30 | }
|
31 | }
|
32 |
|
33 | return function (Constructor, protoProps, staticProps) {
|
34 | if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
35 | if (staticProps) defineProperties(Constructor, staticProps);
|
36 | return Constructor;
|
37 | };
|
38 | }();
|
39 |
|
40 | var _slicedToArray = function () {
|
41 | function sliceIterator(arr, i) {
|
42 | var _arr = [];
|
43 | var _n = true;
|
44 | var _d = false;
|
45 | var _e = undefined;
|
46 |
|
47 | try {
|
48 | for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
49 | _arr.push(_s.value);
|
50 |
|
51 | if (i && _arr.length === i) break;
|
52 | }
|
53 | } catch (err) {
|
54 | _d = true;
|
55 | _e = err;
|
56 | } finally {
|
57 | try {
|
58 | if (!_n && _i["return"]) _i["return"]();
|
59 | } finally {
|
60 | if (_d) throw _e;
|
61 | }
|
62 | }
|
63 |
|
64 | return _arr;
|
65 | }
|
66 |
|
67 | return function (arr, i) {
|
68 | if (Array.isArray(arr)) {
|
69 | return arr;
|
70 | } else if (Symbol.iterator in Object(arr)) {
|
71 | return sliceIterator(arr, i);
|
72 | } else {
|
73 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
74 | }
|
75 | };
|
76 | }();
|
77 |
|
78 | function _toConsumableArray(arr) {
|
79 | if (Array.isArray(arr)) {
|
80 | for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
|
81 | arr2[i] = arr[i];
|
82 | }
|
83 |
|
84 | return arr2;
|
85 | } else {
|
86 | return Array.from(arr);
|
87 | }
|
88 | }
|
89 |
|
90 | var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
|
91 | return typeof obj;
|
92 | } : function (obj) {
|
93 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
94 | };
|
95 |
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | (function ($) {
|
103 |
|
104 |
|
105 |
|
106 | var bootstrapVersion = 3;
|
107 | try {
|
108 | var rawVersion = $.fn.dropdown.Constructor.VERSION;
|
109 |
|
110 |
|
111 |
|
112 | if (rawVersion !== undefined) {
|
113 | bootstrapVersion = parseInt(rawVersion, 10);
|
114 | }
|
115 | } catch (e) {
|
116 |
|
117 | }
|
118 |
|
119 | var bootstrap = {
|
120 | 3: {
|
121 | iconsPrefix: 'glyphicon',
|
122 | icons: {
|
123 | paginationSwitchDown: 'glyphicon-collapse-down icon-chevron-down',
|
124 | paginationSwitchUp: 'glyphicon-collapse-up icon-chevron-up',
|
125 | refresh: 'glyphicon-refresh icon-refresh',
|
126 | toggleOff: 'glyphicon-list-alt icon-list-alt',
|
127 | toggleOn: 'glyphicon-list-alt icon-list-alt',
|
128 | columns: 'glyphicon-th icon-th',
|
129 | detailOpen: 'glyphicon-plus icon-plus',
|
130 | detailClose: 'glyphicon-minus icon-minus',
|
131 | fullscreen: 'glyphicon-fullscreen'
|
132 | },
|
133 | classes: {
|
134 | buttons: 'default',
|
135 | pull: 'pull'
|
136 | },
|
137 | html: {
|
138 | toobarDropdow: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
|
139 | toobarDropdowItem: '<li role="menuitem"><label>%s</label></li>',
|
140 | pageDropdown: ['<ul class="dropdown-menu" role="menu">', '</ul>'],
|
141 | pageDropdownItem: '<li role="menuitem" class="%s"><a href="#">%s</a></li>'
|
142 | }
|
143 | },
|
144 | 4: {
|
145 | iconsPrefix: 'fa',
|
146 | icons: {
|
147 | paginationSwitchDown: 'fa-caret-square-down',
|
148 | paginationSwitchUp: 'fa-caret-square-up',
|
149 | refresh: 'fa-sync',
|
150 | toggleOff: 'fa-toggle-off',
|
151 | toggleOn: 'fa-toggle-on',
|
152 | columns: 'fa-th-list',
|
153 | detailOpen: 'fa-plus',
|
154 | detailClose: 'fa-minus',
|
155 | fullscreen: 'fa-arrows-alt'
|
156 | },
|
157 | classes: {
|
158 | buttons: 'secondary',
|
159 | pull: 'float'
|
160 | },
|
161 | html: {
|
162 | toobarDropdow: ['<div class="dropdown-menu dropdown-menu-right">', '</div>'],
|
163 | toobarDropdowItem: '<label class="dropdown-item">%s</label>',
|
164 | pageDropdown: ['<div class="dropdown-menu">', '</div>'],
|
165 | pageDropdownItem: '<a class="dropdown-item %s" href="#">%s</a>'
|
166 | }
|
167 | }
|
168 | }[bootstrapVersion];
|
169 |
|
170 | var Utils = {
|
171 | bootstrapVersion: bootstrapVersion,
|
172 |
|
173 | sprintf: function sprintf(_str) {
|
174 | for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
175 | args[_key - 1] = arguments[_key];
|
176 | }
|
177 |
|
178 | var flag = true;
|
179 | var i = 0;
|
180 |
|
181 | var str = _str.replace(/%s/g, function () {
|
182 | var arg = args[i++];
|
183 |
|
184 | if (typeof arg === 'undefined') {
|
185 | flag = false;
|
186 | return '';
|
187 | }
|
188 | return arg;
|
189 | });
|
190 | return flag ? str : '';
|
191 | },
|
192 | getFieldTitle: function getFieldTitle(list, value) {
|
193 | var _iteratorNormalCompletion = true;
|
194 | var _didIteratorError = false;
|
195 | var _iteratorError = undefined;
|
196 |
|
197 | try {
|
198 | for (var _iterator = list[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
199 | var item = _step.value;
|
200 |
|
201 | if (item.field === value) {
|
202 | return item.title;
|
203 | }
|
204 | }
|
205 | } catch (err) {
|
206 | _didIteratorError = true;
|
207 | _iteratorError = err;
|
208 | } finally {
|
209 | try {
|
210 | if (!_iteratorNormalCompletion && _iterator.return) {
|
211 | _iterator.return();
|
212 | }
|
213 | } finally {
|
214 | if (_didIteratorError) {
|
215 | throw _iteratorError;
|
216 | }
|
217 | }
|
218 | }
|
219 |
|
220 | return '';
|
221 | },
|
222 | setFieldIndex: function setFieldIndex(columns) {
|
223 | var totalCol = 0;
|
224 | var flag = [];
|
225 |
|
226 | var _iteratorNormalCompletion2 = true;
|
227 | var _didIteratorError2 = false;
|
228 | var _iteratorError2 = undefined;
|
229 |
|
230 | try {
|
231 | for (var _iterator2 = columns[0][Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
232 | var column = _step2.value;
|
233 |
|
234 | totalCol += column.colspan || 1;
|
235 | }
|
236 | } catch (err) {
|
237 | _didIteratorError2 = true;
|
238 | _iteratorError2 = err;
|
239 | } finally {
|
240 | try {
|
241 | if (!_iteratorNormalCompletion2 && _iterator2.return) {
|
242 | _iterator2.return();
|
243 | }
|
244 | } finally {
|
245 | if (_didIteratorError2) {
|
246 | throw _iteratorError2;
|
247 | }
|
248 | }
|
249 | }
|
250 |
|
251 | for (var i = 0; i < columns.length; i++) {
|
252 | flag[i] = [];
|
253 | for (var j = 0; j < totalCol; j++) {
|
254 | flag[i][j] = false;
|
255 | }
|
256 | }
|
257 |
|
258 | for (var _i = 0; _i < columns.length; _i++) {
|
259 | var _iteratorNormalCompletion3 = true;
|
260 | var _didIteratorError3 = false;
|
261 | var _iteratorError3 = undefined;
|
262 |
|
263 | try {
|
264 | for (var _iterator3 = columns[_i][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
265 | var r = _step3.value;
|
266 |
|
267 | var rowspan = r.rowspan || 1;
|
268 | var colspan = r.colspan || 1;
|
269 | var index = flag[_i].indexOf(false);
|
270 |
|
271 | if (colspan === 1) {
|
272 | r.fieldIndex = index;
|
273 |
|
274 | if (typeof r.field === 'undefined') {
|
275 | r.field = index;
|
276 | }
|
277 | }
|
278 |
|
279 | for (var k = 0; k < rowspan; k++) {
|
280 | flag[_i + k][index] = true;
|
281 | }
|
282 | for (var _k = 0; _k < colspan; _k++) {
|
283 | flag[_i][index + _k] = true;
|
284 | }
|
285 | }
|
286 | } catch (err) {
|
287 | _didIteratorError3 = true;
|
288 | _iteratorError3 = err;
|
289 | } finally {
|
290 | try {
|
291 | if (!_iteratorNormalCompletion3 && _iterator3.return) {
|
292 | _iterator3.return();
|
293 | }
|
294 | } finally {
|
295 | if (_didIteratorError3) {
|
296 | throw _iteratorError3;
|
297 | }
|
298 | }
|
299 | }
|
300 | }
|
301 | },
|
302 | getScrollBarWidth: function getScrollBarWidth() {
|
303 | if (this.cachedWidth === undefined) {
|
304 | var $inner = $('<div/>').addClass('fixed-table-scroll-inner');
|
305 | var $outer = $('<div/>').addClass('fixed-table-scroll-outer');
|
306 |
|
307 | $outer.append($inner);
|
308 | $('body').append($outer);
|
309 |
|
310 | var w1 = $inner[0].offsetWidth;
|
311 | $outer.css('overflow', 'scroll');
|
312 | var w2 = $inner[0].offsetWidth;
|
313 |
|
314 | if (w1 === w2) {
|
315 | w2 = $outer[0].clientWidth;
|
316 | }
|
317 |
|
318 | $outer.remove();
|
319 | this.cachedWidth = w1 - w2;
|
320 | }
|
321 | return this.cachedWidth;
|
322 | },
|
323 | calculateObjectValue: function calculateObjectValue(self, name, args, defaultValue) {
|
324 | var func = name;
|
325 |
|
326 | if (typeof name === 'string') {
|
327 |
|
328 | var names = name.split('.');
|
329 |
|
330 | if (names.length > 1) {
|
331 | func = window;
|
332 | var _iteratorNormalCompletion4 = true;
|
333 | var _didIteratorError4 = false;
|
334 | var _iteratorError4 = undefined;
|
335 |
|
336 | try {
|
337 | for (var _iterator4 = names[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
338 | var f = _step4.value;
|
339 |
|
340 | func = func[f];
|
341 | }
|
342 | } catch (err) {
|
343 | _didIteratorError4 = true;
|
344 | _iteratorError4 = err;
|
345 | } finally {
|
346 | try {
|
347 | if (!_iteratorNormalCompletion4 && _iterator4.return) {
|
348 | _iterator4.return();
|
349 | }
|
350 | } finally {
|
351 | if (_didIteratorError4) {
|
352 | throw _iteratorError4;
|
353 | }
|
354 | }
|
355 | }
|
356 | } else {
|
357 | func = window[name];
|
358 | }
|
359 | }
|
360 |
|
361 | if (func !== null && (typeof func === 'undefined' ? 'undefined' : _typeof(func)) === 'object') {
|
362 | return func;
|
363 | }
|
364 |
|
365 | if (typeof func === 'function') {
|
366 | return func.apply(self, args || []);
|
367 | }
|
368 |
|
369 | if (!func && typeof name === 'string' && this.sprintf.apply(this, [name].concat(_toConsumableArray(args)))) {
|
370 | return this.sprintf.apply(this, [name].concat(_toConsumableArray(args)));
|
371 | }
|
372 |
|
373 | return defaultValue;
|
374 | },
|
375 | compareObjects: function compareObjects(objectA, objectB, compareLength) {
|
376 | var aKeys = Object.keys(objectA);
|
377 | var bKeys = Object.keys(objectB);
|
378 |
|
379 | if (compareLength && aKeys.length !== bKeys.length) {
|
380 | return false;
|
381 | }
|
382 |
|
383 | var _iteratorNormalCompletion5 = true;
|
384 | var _didIteratorError5 = false;
|
385 | var _iteratorError5 = undefined;
|
386 |
|
387 | try {
|
388 | for (var _iterator5 = aKeys[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
389 | var key = _step5.value;
|
390 |
|
391 | if (bKeys.includes(key) && objectA[key] !== objectB[key]) {
|
392 | return false;
|
393 | }
|
394 | }
|
395 | } catch (err) {
|
396 | _didIteratorError5 = true;
|
397 | _iteratorError5 = err;
|
398 | } finally {
|
399 | try {
|
400 | if (!_iteratorNormalCompletion5 && _iterator5.return) {
|
401 | _iterator5.return();
|
402 | }
|
403 | } finally {
|
404 | if (_didIteratorError5) {
|
405 | throw _iteratorError5;
|
406 | }
|
407 | }
|
408 | }
|
409 |
|
410 | return true;
|
411 | },
|
412 | escapeHTML: function escapeHTML(text) {
|
413 | if (typeof text === 'string') {
|
414 | return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/`/g, '`');
|
415 | }
|
416 | return text;
|
417 | },
|
418 | getRealDataAttr: function getRealDataAttr(dataAttr) {
|
419 | var _iteratorNormalCompletion6 = true;
|
420 | var _didIteratorError6 = false;
|
421 | var _iteratorError6 = undefined;
|
422 |
|
423 | try {
|
424 | for (var _iterator6 = Object.entries(dataAttr)[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
425 | var _ref = _step6.value;
|
426 |
|
427 | var _ref2 = _slicedToArray(_ref, 2);
|
428 |
|
429 | var attr = _ref2[0];
|
430 | var value = _ref2[1];
|
431 |
|
432 | var auxAttr = attr.split(/(?=[A-Z])/).join('-').toLowerCase();
|
433 | if (auxAttr !== attr) {
|
434 | dataAttr[auxAttr] = value;
|
435 | delete dataAttr[attr];
|
436 | }
|
437 | }
|
438 | } catch (err) {
|
439 | _didIteratorError6 = true;
|
440 | _iteratorError6 = err;
|
441 | } finally {
|
442 | try {
|
443 | if (!_iteratorNormalCompletion6 && _iterator6.return) {
|
444 | _iterator6.return();
|
445 | }
|
446 | } finally {
|
447 | if (_didIteratorError6) {
|
448 | throw _iteratorError6;
|
449 | }
|
450 | }
|
451 | }
|
452 |
|
453 | return dataAttr;
|
454 | },
|
455 | getItemField: function getItemField(item, field, escape) {
|
456 | var value = item;
|
457 |
|
458 | if (typeof field !== 'string' || item.hasOwnProperty(field)) {
|
459 | return escape ? this.escapeHTML(item[field]) : item[field];
|
460 | }
|
461 |
|
462 | var props = field.split('.');
|
463 | var _iteratorNormalCompletion7 = true;
|
464 | var _didIteratorError7 = false;
|
465 | var _iteratorError7 = undefined;
|
466 |
|
467 | try {
|
468 | for (var _iterator7 = props[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
469 | var p = _step7.value;
|
470 |
|
471 | value = value && value[p];
|
472 | }
|
473 | } catch (err) {
|
474 | _didIteratorError7 = true;
|
475 | _iteratorError7 = err;
|
476 | } finally {
|
477 | try {
|
478 | if (!_iteratorNormalCompletion7 && _iterator7.return) {
|
479 | _iterator7.return();
|
480 | }
|
481 | } finally {
|
482 | if (_didIteratorError7) {
|
483 | throw _iteratorError7;
|
484 | }
|
485 | }
|
486 | }
|
487 |
|
488 | return escape ? this.escapeHTML(value) : value;
|
489 | },
|
490 | isIEBrowser: function isIEBrowser() {
|
491 | return navigator.userAgent.includes('MSIE ') || /Trident.*rv:11\./.test(navigator.userAgent);
|
492 | },
|
493 | findIndex: function findIndex(items, item) {
|
494 | var _iteratorNormalCompletion8 = true;
|
495 | var _didIteratorError8 = false;
|
496 | var _iteratorError8 = undefined;
|
497 |
|
498 | try {
|
499 | for (var _iterator8 = items.entries()[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
500 | var _ref3 = _step8.value;
|
501 |
|
502 | var _ref4 = _slicedToArray(_ref3, 2);
|
503 |
|
504 | var i = _ref4[0];
|
505 | var it = _ref4[1];
|
506 |
|
507 | if (JSON.stringify(it) === JSON.stringify(item)) {
|
508 | return i;
|
509 | }
|
510 | }
|
511 | } catch (err) {
|
512 | _didIteratorError8 = true;
|
513 | _iteratorError8 = err;
|
514 | } finally {
|
515 | try {
|
516 | if (!_iteratorNormalCompletion8 && _iterator8.return) {
|
517 | _iterator8.return();
|
518 | }
|
519 | } finally {
|
520 | if (_didIteratorError8) {
|
521 | throw _iteratorError8;
|
522 | }
|
523 | }
|
524 | }
|
525 |
|
526 | return -1;
|
527 | }
|
528 | };
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | var DEFAULTS = {
|
534 | height: undefined,
|
535 | classes: 'table table-bordered table-hover',
|
536 | theadClasses: '',
|
537 | rowStyle: function rowStyle(row, index) {
|
538 | return {};
|
539 | },
|
540 | rowAttributes: function rowAttributes(row, index) {
|
541 | return {};
|
542 | },
|
543 |
|
544 | undefinedText: '-',
|
545 | locale: undefined,
|
546 | sortable: true,
|
547 | sortClass: undefined,
|
548 | silentSort: true,
|
549 | sortName: undefined,
|
550 | sortOrder: 'asc',
|
551 | sortStable: false,
|
552 | rememberOrder: false,
|
553 | customSort: undefined,
|
554 | columns: [[]],
|
555 | data: [],
|
556 | url: undefined,
|
557 | method: 'get',
|
558 | cache: true,
|
559 | contentType: 'application/json',
|
560 | dataType: 'json',
|
561 | ajax: undefined,
|
562 | ajaxOptions: {},
|
563 | queryParams: function queryParams(params) {
|
564 | return params;
|
565 | },
|
566 |
|
567 | queryParamsType: 'limit', responseHandler: function responseHandler(res) {
|
568 | return res;
|
569 | },
|
570 |
|
571 | totalField: 'total',
|
572 | dataField: 'rows',
|
573 | pagination: false,
|
574 | onlyInfoPagination: false,
|
575 | paginationLoop: true,
|
576 | sidePagination: 'client',
|
577 | totalRows: 0,
|
578 | pageNumber: 1,
|
579 | pageSize: 10,
|
580 | pageList: [10, 25, 50, 100],
|
581 | paginationHAlign: 'right',
|
582 | paginationVAlign: 'bottom',
|
583 | paginationDetailHAlign: 'left',
|
584 | paginationPreText: '‹',
|
585 | paginationNextText: '›',
|
586 | paginationSuccessivelySize: 5,
|
587 | paginationPagesBySide: 1,
|
588 | paginationUseIntermediate: false,
|
589 | search: false,
|
590 | searchOnEnterKey: false,
|
591 | strictSearch: false,
|
592 | trimOnSearch: true,
|
593 | searchAlign: 'right',
|
594 | searchTimeOut: 500,
|
595 | searchText: '',
|
596 | customSearch: undefined,
|
597 | showHeader: true,
|
598 | showFooter: false,
|
599 | footerStyle: function footerStyle(row, index) {
|
600 | return {};
|
601 | },
|
602 |
|
603 | showColumns: false,
|
604 | minimumCountColumns: 1,
|
605 | showPaginationSwitch: false,
|
606 | showRefresh: false,
|
607 | showToggle: false,
|
608 | showFullscreen: false,
|
609 | smartDisplay: true,
|
610 | escape: false,
|
611 | idField: undefined,
|
612 | uniqueId: undefined,
|
613 | cardView: false,
|
614 | detailView: false,
|
615 | detailFormatter: function detailFormatter(index, row) {
|
616 | return '';
|
617 | },
|
618 | detailFilter: function detailFilter(index, row) {
|
619 | return true;
|
620 | },
|
621 |
|
622 | selectItemName: 'btSelectItem',
|
623 | clickToSelect: false,
|
624 | ignoreClickToSelectOn: function ignoreClickToSelectOn(_ref5) {
|
625 | var tagName = _ref5.tagName;
|
626 |
|
627 | return ['A', 'BUTTON'].includes(tagName);
|
628 | },
|
629 |
|
630 | singleSelect: false,
|
631 | checkboxHeader: true,
|
632 | maintainSelected: false,
|
633 | toolbar: undefined,
|
634 | toolbarAlign: 'left',
|
635 | buttonsToolbar: undefined,
|
636 | buttonsAlign: 'right',
|
637 | buttonsClass: bootstrap.classes.buttons,
|
638 | icons: bootstrap.icons,
|
639 | iconSize: undefined,
|
640 | iconsPrefix: bootstrap.iconsPrefix, onAll: function onAll(name, args) {
|
641 | return false;
|
642 | },
|
643 | onClickCell: function onClickCell(field, value, row, $element) {
|
644 | return false;
|
645 | },
|
646 | onDblClickCell: function onDblClickCell(field, value, row, $element) {
|
647 | return false;
|
648 | },
|
649 | onClickRow: function onClickRow(item, $element) {
|
650 | return false;
|
651 | },
|
652 | onDblClickRow: function onDblClickRow(item, $element) {
|
653 | return false;
|
654 | },
|
655 | onSort: function onSort(name, order) {
|
656 | return false;
|
657 | },
|
658 | onCheck: function onCheck(row) {
|
659 | return false;
|
660 | },
|
661 | onUncheck: function onUncheck(row) {
|
662 | return false;
|
663 | },
|
664 | onCheckAll: function onCheckAll(rows) {
|
665 | return false;
|
666 | },
|
667 | onUncheckAll: function onUncheckAll(rows) {
|
668 | return false;
|
669 | },
|
670 | onCheckSome: function onCheckSome(rows) {
|
671 | return false;
|
672 | },
|
673 | onUncheckSome: function onUncheckSome(rows) {
|
674 | return false;
|
675 | },
|
676 | onLoadSuccess: function onLoadSuccess(data) {
|
677 | return false;
|
678 | },
|
679 | onLoadError: function onLoadError(status) {
|
680 | return false;
|
681 | },
|
682 | onColumnSwitch: function onColumnSwitch(field, checked) {
|
683 | return false;
|
684 | },
|
685 | onPageChange: function onPageChange(number, size) {
|
686 | return false;
|
687 | },
|
688 | onSearch: function onSearch(text) {
|
689 | return false;
|
690 | },
|
691 | onToggle: function onToggle(cardView) {
|
692 | return false;
|
693 | },
|
694 | onPreBody: function onPreBody(data) {
|
695 | return false;
|
696 | },
|
697 | onPostBody: function onPostBody() {
|
698 | return false;
|
699 | },
|
700 | onPostHeader: function onPostHeader() {
|
701 | return false;
|
702 | },
|
703 | onExpandRow: function onExpandRow(index, row, $detail) {
|
704 | return false;
|
705 | },
|
706 | onCollapseRow: function onCollapseRow(index, row) {
|
707 | return false;
|
708 | },
|
709 | onRefreshOptions: function onRefreshOptions(options) {
|
710 | return false;
|
711 | },
|
712 | onRefresh: function onRefresh(params) {
|
713 | return false;
|
714 | },
|
715 | onResetView: function onResetView() {
|
716 | return false;
|
717 | },
|
718 | onScrollBody: function onScrollBody() {
|
719 | return false;
|
720 | }
|
721 | };
|
722 |
|
723 | var LOCALES = {};
|
724 | LOCALES['en-US'] = LOCALES.en = {
|
725 | formatLoadingMessage: function formatLoadingMessage() {
|
726 | return 'Loading, please wait...';
|
727 | },
|
728 | formatRecordsPerPage: function formatRecordsPerPage(pageNumber) {
|
729 | return Utils.sprintf('%s rows per page', pageNumber);
|
730 | },
|
731 | formatShowingRows: function formatShowingRows(pageFrom, pageTo, totalRows) {
|
732 | return Utils.sprintf('Showing %s to %s of %s rows', pageFrom, pageTo, totalRows);
|
733 | },
|
734 | formatDetailPagination: function formatDetailPagination(totalRows) {
|
735 | return Utils.sprintf('Showing %s rows', totalRows);
|
736 | },
|
737 | formatSearch: function formatSearch() {
|
738 | return 'Search';
|
739 | },
|
740 | formatNoMatches: function formatNoMatches() {
|
741 | return 'No matching records found';
|
742 | },
|
743 | formatPaginationSwitch: function formatPaginationSwitch() {
|
744 | return 'Hide/Show pagination';
|
745 | },
|
746 | formatRefresh: function formatRefresh() {
|
747 | return 'Refresh';
|
748 | },
|
749 | formatToggle: function formatToggle() {
|
750 | return 'Toggle';
|
751 | },
|
752 | formatFullscreen: function formatFullscreen() {
|
753 | return 'Fullscreen';
|
754 | },
|
755 | formatColumns: function formatColumns() {
|
756 | return 'Columns';
|
757 | },
|
758 | formatAllRows: function formatAllRows() {
|
759 | return 'All';
|
760 | }
|
761 | };
|
762 |
|
763 | $.extend(DEFAULTS, LOCALES['en-US']);
|
764 |
|
765 | var COLUMN_DEFAULTS = {
|
766 | radio: false,
|
767 | checkbox: false,
|
768 | checkboxEnabled: true,
|
769 | field: undefined,
|
770 | title: undefined,
|
771 | titleTooltip: undefined,
|
772 | 'class': undefined,
|
773 | align: undefined,
|
774 | halign: undefined,
|
775 | falign: undefined,
|
776 | valign: undefined,
|
777 | width: undefined,
|
778 | sortable: false,
|
779 | order: 'asc',
|
780 | visible: true,
|
781 | switchable: true,
|
782 | clickToSelect: true,
|
783 | formatter: undefined,
|
784 | footerFormatter: undefined,
|
785 | events: undefined,
|
786 | sorter: undefined,
|
787 | sortName: undefined,
|
788 | cellStyle: undefined,
|
789 | searchable: true,
|
790 | searchFormatter: true,
|
791 | cardVisible: true,
|
792 | escape: false,
|
793 | showSelectTitle: false
|
794 | };
|
795 |
|
796 | var EVENTS = {
|
797 | 'all.bs.table': 'onAll',
|
798 | 'click-cell.bs.table': 'onClickCell',
|
799 | 'dbl-click-cell.bs.table': 'onDblClickCell',
|
800 | 'click-row.bs.table': 'onClickRow',
|
801 | 'dbl-click-row.bs.table': 'onDblClickRow',
|
802 | 'sort.bs.table': 'onSort',
|
803 | 'check.bs.table': 'onCheck',
|
804 | 'uncheck.bs.table': 'onUncheck',
|
805 | 'check-all.bs.table': 'onCheckAll',
|
806 | 'uncheck-all.bs.table': 'onUncheckAll',
|
807 | 'check-some.bs.table': 'onCheckSome',
|
808 | 'uncheck-some.bs.table': 'onUncheckSome',
|
809 | 'load-success.bs.table': 'onLoadSuccess',
|
810 | 'load-error.bs.table': 'onLoadError',
|
811 | 'column-switch.bs.table': 'onColumnSwitch',
|
812 | 'page-change.bs.table': 'onPageChange',
|
813 | 'search.bs.table': 'onSearch',
|
814 | 'toggle.bs.table': 'onToggle',
|
815 | 'pre-body.bs.table': 'onPreBody',
|
816 | 'post-body.bs.table': 'onPostBody',
|
817 | 'post-header.bs.table': 'onPostHeader',
|
818 | 'expand-row.bs.table': 'onExpandRow',
|
819 | 'collapse-row.bs.table': 'onCollapseRow',
|
820 | 'refresh-options.bs.table': 'onRefreshOptions',
|
821 | 'reset-view.bs.table': 'onResetView',
|
822 | 'refresh.bs.table': 'onRefresh',
|
823 | 'scroll-body.bs.table': 'onScrollBody'
|
824 | };
|
825 |
|
826 | var BootstrapTable = function () {
|
827 | function BootstrapTable(el, options) {
|
828 | _classCallCheck(this, BootstrapTable);
|
829 |
|
830 | this.options = options;
|
831 | this.$el = $(el);
|
832 | this.$el_ = this.$el.clone();
|
833 | this.timeoutId_ = 0;
|
834 | this.timeoutFooter_ = 0;
|
835 |
|
836 | this.init();
|
837 | }
|
838 |
|
839 | _createClass(BootstrapTable, [{
|
840 | key: 'init',
|
841 | value: function init() {
|
842 | this.initLocale();
|
843 | this.initContainer();
|
844 | this.initTable();
|
845 | this.initHeader();
|
846 | this.initData();
|
847 | this.initHiddenRows();
|
848 | this.initFooter();
|
849 | this.initToolbar();
|
850 | this.initPagination();
|
851 | this.initBody();
|
852 | this.initSearchText();
|
853 | this.initServer();
|
854 | }
|
855 | }, {
|
856 | key: 'initLocale',
|
857 | value: function initLocale() {
|
858 | if (this.options.locale) {
|
859 | var locales = $.fn.bootstrapTable.locales;
|
860 | var parts = this.options.locale.split(/-|_/);
|
861 |
|
862 | parts[0] = parts[0].toLowerCase();
|
863 | if (parts[1]) {
|
864 | parts[1] = parts[1].toUpperCase();
|
865 | }
|
866 |
|
867 | if (locales[this.options.locale]) {
|
868 | $.extend(this.options, locales[this.options.locale]);
|
869 | } else if (locales[parts.join('-')]) {
|
870 | $.extend(this.options, locales[parts.join('-')]);
|
871 | } else if (locales[parts[0]]) {
|
872 | $.extend(this.options, locales[parts[0]]);
|
873 | }
|
874 | }
|
875 | }
|
876 | }, {
|
877 | key: 'initContainer',
|
878 | value: function initContainer() {
|
879 | var topPagination = ['top', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination clearfix"></div>' : '';
|
880 | var bottomPagination = ['bottom', 'both'].includes(this.options.paginationVAlign) ? '<div class="fixed-table-pagination"></div>' : '';
|
881 |
|
882 | this.$container = $('\n <div class="bootstrap-table">\n <div class="fixed-table-toolbar"></div>\n ' + topPagination + '\n <div class="fixed-table-container">\n <div class="fixed-table-header"><table></table></div>\n <div class="fixed-table-body">\n <div class="fixed-table-loading">\n ' + this.options.formatLoadingMessage() + '\n </div>\n </div>\n <div class="fixed-table-footer"><table><tr></tr></table></div>\n </div>\n ' + bottomPagination + '\n </div>\n ');
|
883 |
|
884 | this.$container.insertAfter(this.$el);
|
885 | this.$tableContainer = this.$container.find('.fixed-table-container');
|
886 | this.$tableHeader = this.$container.find('.fixed-table-header');
|
887 | this.$tableBody = this.$container.find('.fixed-table-body');
|
888 | this.$tableLoading = this.$container.find('.fixed-table-loading');
|
889 | this.$tableFooter = this.$container.find('.fixed-table-footer');
|
890 |
|
891 | if (this.options.buttonsToolbar) {
|
892 | this.$toolbar = $('body').find(this.options.buttonsToolbar);
|
893 | } else {
|
894 | this.$toolbar = this.$container.find('.fixed-table-toolbar');
|
895 | }
|
896 | this.$pagination = this.$container.find('.fixed-table-pagination');
|
897 |
|
898 | this.$tableBody.append(this.$el);
|
899 | this.$container.after('<div class="clearfix"></div>');
|
900 |
|
901 | this.$el.addClass(this.options.classes);
|
902 |
|
903 | if (this.options.height) {
|
904 | this.$tableContainer.addClass('fixed-height');
|
905 |
|
906 | if (this.options.classes.split(' ').includes('table-bordered')) {
|
907 | this.$tableBody.append('<div class="fixed-table-border"></div>');
|
908 | this.$tableBorder = this.$tableBody.find('.fixed-table-border');
|
909 | this.$tableLoading.addClass('fixed-table-border');
|
910 | }
|
911 | }
|
912 | }
|
913 | }, {
|
914 | key: 'initTable',
|
915 | value: function initTable() {
|
916 | var _this = this;
|
917 |
|
918 | var columns = [];
|
919 | var data = [];
|
920 |
|
921 | this.$header = this.$el.find('>thead');
|
922 | if (!this.$header.length) {
|
923 | this.$header = $('<thead class="' + this.options.theadClasses + '"></thead>').appendTo(this.$el);
|
924 | } else if (this.options.theadClasses) {
|
925 | this.$header.addClass(this.options.theadClasses);
|
926 | }
|
927 | this.$header.find('tr').each(function (i, el) {
|
928 | var column = [];
|
929 |
|
930 | $(el).find('th').each(function (i, el) {
|
931 |
|
932 | if (typeof $(el).data('field') !== 'undefined') {
|
933 | $(el).data('field', '' + $(el).data('field'));
|
934 | }
|
935 | column.push($.extend({}, {
|
936 | title: $(el).html(),
|
937 | 'class': $(el).attr('class'),
|
938 | titleTooltip: $(el).attr('title'),
|
939 | rowspan: $(el).attr('rowspan') ? +$(el).attr('rowspan') : undefined,
|
940 | colspan: $(el).attr('colspan') ? +$(el).attr('colspan') : undefined
|
941 | }, $(el).data()));
|
942 | });
|
943 | columns.push(column);
|
944 | });
|
945 |
|
946 | if (!Array.isArray(this.options.columns[0])) {
|
947 | this.options.columns = [this.options.columns];
|
948 | }
|
949 |
|
950 | this.options.columns = $.extend(true, [], columns, this.options.columns);
|
951 | this.columns = [];
|
952 | this.fieldsColumnsIndex = [];
|
953 |
|
954 | Utils.setFieldIndex(this.options.columns);
|
955 |
|
956 | this.options.columns.forEach(function (columns, i) {
|
957 | columns.forEach(function (_column, j) {
|
958 | var column = $.extend({}, BootstrapTable.COLUMN_DEFAULTS, _column);
|
959 |
|
960 | if (typeof column.fieldIndex !== 'undefined') {
|
961 | _this.columns[column.fieldIndex] = column;
|
962 | _this.fieldsColumnsIndex[column.field] = column.fieldIndex;
|
963 | }
|
964 |
|
965 | _this.options.columns[i][j] = column;
|
966 | });
|
967 | });
|
968 |
|
969 |
|
970 | if (this.options.data.length) {
|
971 | return;
|
972 | }
|
973 |
|
974 | var m = [];
|
975 | this.$el.find('>tbody>tr').each(function (y, el) {
|
976 | var row = {};
|
977 |
|
978 |
|
979 | row._id = $(el).attr('id');
|
980 | row._class = $(el).attr('class');
|
981 | row._data = Utils.getRealDataAttr($(el).data());
|
982 |
|
983 | $(el).find('>td').each(function (_x, el) {
|
984 | var cspan = +$(el).attr('colspan') || 1;
|
985 | var rspan = +$(el).attr('rowspan') || 1;
|
986 | var x = _x;
|
987 |
|
988 |
|
989 | for (; m[y] && m[y][x]; x++) {}
|
990 |
|
991 |
|
992 |
|
993 |
|
994 | for (var tx = x; tx < x + cspan; tx++) {
|
995 | for (var ty = y; ty < y + rspan; ty++) {
|
996 | if (!m[ty]) {
|
997 |
|
998 | m[ty] = [];
|
999 | }
|
1000 | m[ty][tx] = true;
|
1001 | }
|
1002 | }
|
1003 |
|
1004 | var field = _this.columns[x].field;
|
1005 |
|
1006 | row[field] = $(el).html();
|
1007 |
|
1008 | row['_' + field + '_id'] = $(el).attr('id');
|
1009 | row['_' + field + '_class'] = $(el).attr('class');
|
1010 | row['_' + field + '_rowspan'] = $(el).attr('rowspan');
|
1011 | row['_' + field + '_colspan'] = $(el).attr('colspan');
|
1012 | row['_' + field + '_title'] = $(el).attr('title');
|
1013 | row['_' + field + '_data'] = Utils.getRealDataAttr($(el).data());
|
1014 | });
|
1015 | data.push(row);
|
1016 | });
|
1017 | this.options.data = data;
|
1018 | if (data.length) {
|
1019 | this.fromHtml = true;
|
1020 | }
|
1021 | }
|
1022 | }, {
|
1023 | key: 'initHeader',
|
1024 | value: function initHeader() {
|
1025 | var _this2 = this;
|
1026 |
|
1027 | var visibleColumns = {};
|
1028 | var html = [];
|
1029 |
|
1030 | this.header = {
|
1031 | fields: [],
|
1032 | styles: [],
|
1033 | classes: [],
|
1034 | formatters: [],
|
1035 | events: [],
|
1036 | sorters: [],
|
1037 | sortNames: [],
|
1038 | cellStyles: [],
|
1039 | searchables: []
|
1040 | };
|
1041 |
|
1042 | this.options.columns.forEach(function (columns, i) {
|
1043 | html.push('<tr>');
|
1044 |
|
1045 | if (i === 0 && !_this2.options.cardView && _this2.options.detailView) {
|
1046 | html.push('<th class="detail" rowspan="' + _this2.options.columns.length + '">\n <div class="fht-cell"></div>\n </th>\n ');
|
1047 | }
|
1048 |
|
1049 | columns.forEach(function (column, j) {
|
1050 | var text = '';
|
1051 |
|
1052 | var halign = '';
|
1053 |
|
1054 | var align = '';
|
1055 |
|
1056 | var style = '';
|
1057 | var class_ = Utils.sprintf(' class="%s"', column['class']);
|
1058 | var unitWidth = 'px';
|
1059 | var width = column.width;
|
1060 |
|
1061 | if (column.width !== undefined && !_this2.options.cardView) {
|
1062 | if (typeof column.width === 'string') {
|
1063 | if (column.width.includes('%')) {
|
1064 | unitWidth = '%';
|
1065 | }
|
1066 | }
|
1067 | }
|
1068 | if (column.width && typeof column.width === 'string') {
|
1069 | width = column.width.replace('%', '').replace('px', '');
|
1070 | }
|
1071 |
|
1072 | halign = Utils.sprintf('text-align: %s; ', column.halign ? column.halign : column.align);
|
1073 | align = Utils.sprintf('text-align: %s; ', column.align);
|
1074 | style = Utils.sprintf('vertical-align: %s; ', column.valign);
|
1075 | style += Utils.sprintf('width: %s; ', (column.checkbox || column.radio) && !width ? !column.showSelectTitle ? '36px' : undefined : width ? width + unitWidth : undefined);
|
1076 |
|
1077 | if (typeof column.fieldIndex !== 'undefined') {
|
1078 | _this2.header.fields[column.fieldIndex] = column.field;
|
1079 | _this2.header.styles[column.fieldIndex] = align + style;
|
1080 | _this2.header.classes[column.fieldIndex] = class_;
|
1081 | _this2.header.formatters[column.fieldIndex] = column.formatter;
|
1082 | _this2.header.events[column.fieldIndex] = column.events;
|
1083 | _this2.header.sorters[column.fieldIndex] = column.sorter;
|
1084 | _this2.header.sortNames[column.fieldIndex] = column.sortName;
|
1085 | _this2.header.cellStyles[column.fieldIndex] = column.cellStyle;
|
1086 | _this2.header.searchables[column.fieldIndex] = column.searchable;
|
1087 |
|
1088 | if (!column.visible) {
|
1089 | return;
|
1090 | }
|
1091 |
|
1092 | if (_this2.options.cardView && !column.cardVisible) {
|
1093 | return;
|
1094 | }
|
1095 |
|
1096 | visibleColumns[column.field] = column;
|
1097 | }
|
1098 |
|
1099 | html.push('<th' + Utils.sprintf(' title="%s"', column.titleTooltip), column.checkbox || column.radio ? Utils.sprintf(' class="bs-checkbox %s"', column['class'] || '') : class_, Utils.sprintf(' style="%s"', halign + style), Utils.sprintf(' rowspan="%s"', column.rowspan), Utils.sprintf(' colspan="%s"', column.colspan), Utils.sprintf(' data-field="%s"', column.field),
|
1100 |
|
1101 | j === 0 && i > 0 ? ' data-not-first-th' : '', '>');
|
1102 |
|
1103 | html.push(Utils.sprintf('<div class="th-inner %s">', _this2.options.sortable && column.sortable ? 'sortable both' : ''));
|
1104 |
|
1105 | text = _this2.options.escape ? Utils.escapeHTML(column.title) : column.title;
|
1106 |
|
1107 | var title = text;
|
1108 | if (column.checkbox) {
|
1109 | text = '';
|
1110 | if (!_this2.options.singleSelect && _this2.options.checkboxHeader) {
|
1111 | text = '<input name="btSelectAll" type="checkbox" />';
|
1112 | }
|
1113 | _this2.header.stateField = column.field;
|
1114 | }
|
1115 | if (column.radio) {
|
1116 | text = '';
|
1117 | _this2.header.stateField = column.field;
|
1118 | _this2.options.singleSelect = true;
|
1119 | }
|
1120 | if (!text && column.showSelectTitle) {
|
1121 | text += title;
|
1122 | }
|
1123 |
|
1124 | html.push(text);
|
1125 | html.push('</div>');
|
1126 | html.push('<div class="fht-cell"></div>');
|
1127 | html.push('</div>');
|
1128 | html.push('</th>');
|
1129 | });
|
1130 | html.push('</tr>');
|
1131 | });
|
1132 |
|
1133 | this.$header.html(html.join(''));
|
1134 | this.$header.find('th[data-field]').each(function (i, el) {
|
1135 | $(el).data(visibleColumns[$(el).data('field')]);
|
1136 | });
|
1137 | this.$container.off('click', '.th-inner').on('click', '.th-inner', function (e) {
|
1138 | var $this = $(e.currentTarget);
|
1139 |
|
1140 | if (_this2.options.detailView && !$this.parent().hasClass('bs-checkbox')) {
|
1141 | if ($this.closest('.bootstrap-table')[0] !== _this2.$container[0]) {
|
1142 | return false;
|
1143 | }
|
1144 | }
|
1145 |
|
1146 | if (_this2.options.sortable && $this.parent().data().sortable) {
|
1147 | _this2.onSort(e);
|
1148 | }
|
1149 | });
|
1150 |
|
1151 | this.$header.children().children().off('keypress').on('keypress', function (e) {
|
1152 | if (_this2.options.sortable && $(e.currentTarget).data().sortable) {
|
1153 | var code = e.keyCode || e.which;
|
1154 | if (code === 13) {
|
1155 |
|
1156 | _this2.onSort(e);
|
1157 | }
|
1158 | }
|
1159 | });
|
1160 |
|
1161 | $(window).off('resize.bootstrap-table');
|
1162 | if (!this.options.showHeader || this.options.cardView) {
|
1163 | this.$header.hide();
|
1164 | this.$tableHeader.hide();
|
1165 | this.$tableLoading.css('top', 0);
|
1166 | } else {
|
1167 | this.$header.show();
|
1168 | this.$tableHeader.show();
|
1169 | this.$tableLoading.css('top', this.$header.outerHeight() + 1);
|
1170 |
|
1171 | this.getCaret();
|
1172 | $(window).on('resize.bootstrap-table', $.proxy(this.resetWidth, this));
|
1173 | }
|
1174 |
|
1175 | this.$selectAll = this.$header.find('[name="btSelectAll"]');
|
1176 | this.$selectAll.off('click').on('click', function (_ref6) {
|
1177 | var currentTarget = _ref6.currentTarget;
|
1178 |
|
1179 | var checked = $(currentTarget).prop('checked');
|
1180 | _this2[checked ? 'checkAll' : 'uncheckAll']();
|
1181 | _this2.updateSelected();
|
1182 | });
|
1183 | }
|
1184 | }, {
|
1185 | key: 'initFooter',
|
1186 | value: function initFooter() {
|
1187 | if (!this.options.showFooter || this.options.cardView) {
|
1188 | this.$tableFooter.hide();
|
1189 | } else {
|
1190 | this.$tableFooter.show();
|
1191 | }
|
1192 | }
|
1193 | }, {
|
1194 | key: 'initData',
|
1195 | value: function initData(data, type) {
|
1196 | if (type === 'append') {
|
1197 | this.options.data = this.options.data.concat(data);
|
1198 | } else if (type === 'prepend') {
|
1199 | this.options.data = [].concat(data).concat(this.options.data);
|
1200 | } else {
|
1201 | this.options.data = data || this.options.data;
|
1202 | }
|
1203 |
|
1204 | this.data = this.options.data;
|
1205 |
|
1206 | if (this.options.sidePagination === 'server') {
|
1207 | return;
|
1208 | }
|
1209 | this.initSort();
|
1210 | }
|
1211 | }, {
|
1212 | key: 'initSort',
|
1213 | value: function initSort() {
|
1214 | var _this3 = this;
|
1215 |
|
1216 | var name = this.options.sortName;
|
1217 | var order = this.options.sortOrder === 'desc' ? -1 : 1;
|
1218 | var index = this.header.fields.indexOf(this.options.sortName);
|
1219 | var timeoutId = 0;
|
1220 |
|
1221 | if (index !== -1) {
|
1222 | if (this.options.sortStable) {
|
1223 | this.data.forEach(function (row, i) {
|
1224 | if (!row.hasOwnProperty('_position')) {
|
1225 | row._position = i;
|
1226 | }
|
1227 | });
|
1228 | }
|
1229 |
|
1230 | if (this.options.customSort) {
|
1231 | Utils.calculateObjectValue(this.options, this.options.customSort, [this.options.sortName, this.options.sortOrder, this.data]);
|
1232 | } else {
|
1233 | this.data.sort(function (a, b) {
|
1234 | if (_this3.header.sortNames[index]) {
|
1235 | name = _this3.header.sortNames[index];
|
1236 | }
|
1237 | var aa = Utils.getItemField(a, name, _this3.options.escape);
|
1238 | var bb = Utils.getItemField(b, name, _this3.options.escape);
|
1239 | var value = Utils.calculateObjectValue(_this3.header, _this3.header.sorters[index], [aa, bb, a, b]);
|
1240 |
|
1241 | if (value !== undefined) {
|
1242 | if (_this3.options.sortStable && value === 0) {
|
1243 | return order * (a._position - b._position);
|
1244 | }
|
1245 | return order * value;
|
1246 | }
|
1247 |
|
1248 |
|
1249 | if (aa === undefined || aa === null) {
|
1250 | aa = '';
|
1251 | }
|
1252 | if (bb === undefined || bb === null) {
|
1253 | bb = '';
|
1254 | }
|
1255 |
|
1256 | if (_this3.options.sortStable && aa === bb) {
|
1257 | aa = a._position;
|
1258 | bb = b._position;
|
1259 | }
|
1260 |
|
1261 |
|
1262 | if ($.isNumeric(aa) && $.isNumeric(bb)) {
|
1263 |
|
1264 | aa = parseFloat(aa);
|
1265 | bb = parseFloat(bb);
|
1266 | if (aa < bb) {
|
1267 | return order * -1;
|
1268 | }
|
1269 | if (aa > bb) {
|
1270 | return order;
|
1271 | }
|
1272 | return 0;
|
1273 | }
|
1274 |
|
1275 | if (aa === bb) {
|
1276 | return 0;
|
1277 | }
|
1278 |
|
1279 |
|
1280 | if (typeof aa !== 'string') {
|
1281 | aa = aa.toString();
|
1282 | }
|
1283 |
|
1284 | if (aa.localeCompare(bb) === -1) {
|
1285 | return order * -1;
|
1286 | }
|
1287 |
|
1288 | return order;
|
1289 | });
|
1290 | }
|
1291 |
|
1292 | if (this.options.sortClass !== undefined) {
|
1293 | clearTimeout(timeoutId);
|
1294 | timeoutId = setTimeout(function () {
|
1295 | _this3.$el.removeClass(_this3.options.sortClass);
|
1296 | var index = _this3.$header.find('[data-field="' + _this3.options.sortName + '"]').index();
|
1297 | _this3.$el.find('tr td:nth-child(' + (index + 1) + ')').addClass(_this3.options.sortClass);
|
1298 | }, 250);
|
1299 | }
|
1300 | }
|
1301 | }
|
1302 | }, {
|
1303 | key: 'onSort',
|
1304 | value: function onSort(_ref7) {
|
1305 | var type = _ref7.type,
|
1306 | currentTarget = _ref7.currentTarget;
|
1307 |
|
1308 | var $this = type === 'keypress' ? $(currentTarget) : $(currentTarget).parent();
|
1309 | var $this_ = this.$header.find('th').eq($this.index());
|
1310 |
|
1311 | this.$header.add(this.$header_).find('span.order').remove();
|
1312 |
|
1313 | if (this.options.sortName === $this.data('field')) {
|
1314 | this.options.sortOrder = this.options.sortOrder === 'asc' ? 'desc' : 'asc';
|
1315 | } else {
|
1316 | this.options.sortName = $this.data('field');
|
1317 | if (this.options.rememberOrder) {
|
1318 | this.options.sortOrder = $this.data('order') === 'asc' ? 'desc' : 'asc';
|
1319 | } else {
|
1320 | this.options.sortOrder = this.columns[this.fieldsColumnsIndex[$this.data('field')]].order;
|
1321 | }
|
1322 | }
|
1323 | this.trigger('sort', this.options.sortName, this.options.sortOrder);
|
1324 |
|
1325 | $this.add($this_).data('order', this.options.sortOrder);
|
1326 |
|
1327 |
|
1328 | this.getCaret();
|
1329 |
|
1330 | if (this.options.sidePagination === 'server') {
|
1331 | this.initServer(this.options.silentSort);
|
1332 | return;
|
1333 | }
|
1334 |
|
1335 | this.initSort();
|
1336 | this.initBody();
|
1337 | }
|
1338 | }, {
|
1339 | key: 'initToolbar',
|
1340 | value: function initToolbar() {
|
1341 | var _this4 = this;
|
1342 |
|
1343 | var html = [];
|
1344 | var timeoutId = 0;
|
1345 | var $keepOpen = void 0;
|
1346 | var $search = void 0;
|
1347 | var switchableCount = 0;
|
1348 |
|
1349 | if (this.$toolbar.find('.bs-bars').children().length) {
|
1350 | $('body').append($(this.options.toolbar));
|
1351 | }
|
1352 | this.$toolbar.html('');
|
1353 |
|
1354 | if (typeof this.options.toolbar === 'string' || _typeof(this.options.toolbar) === 'object') {
|
1355 | $(Utils.sprintf('<div class="bs-bars %s-%s"></div>', bootstrap.classes.pull, this.options.toolbarAlign)).appendTo(this.$toolbar).append($(this.options.toolbar));
|
1356 | }
|
1357 |
|
1358 |
|
1359 | html = [Utils.sprintf('<div class="columns columns-%s btn-group %s-%s">', this.options.buttonsAlign, bootstrap.classes.pull, this.options.buttonsAlign)];
|
1360 |
|
1361 | if (typeof this.options.icons === 'string') {
|
1362 | this.options.icons = Utils.calculateObjectValue(null, this.options.icons);
|
1363 | }
|
1364 |
|
1365 | if (this.options.showPaginationSwitch) {
|
1366 | html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="paginationSwitch" aria-label="pagination Switch" title="%s">', this.options.formatPaginationSwitch()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.paginationSwitchDown), '</button>');
|
1367 | }
|
1368 |
|
1369 | if (this.options.showFullscreen) {
|
1370 | this.$toolbar.find('button[name="fullscreen"]').off('click').on('click', $.proxy(this.toggleFullscreen, this));
|
1371 | }
|
1372 |
|
1373 | if (this.options.showRefresh) {
|
1374 | html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="refresh" aria-label="refresh" title="%s">', this.options.formatRefresh()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.refresh), '</button>');
|
1375 | }
|
1376 |
|
1377 | if (this.options.showToggle) {
|
1378 | html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="toggle" aria-label="toggle" title="%s">', this.options.formatToggle()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.toggleOff), '</button>');
|
1379 | }
|
1380 |
|
1381 | if (this.options.showFullscreen) {
|
1382 | html.push(Utils.sprintf('<button class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + '" type="button" name="fullscreen" aria-label="fullscreen" title="%s">', this.options.formatFullscreen()), Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.fullscreen), '</button>');
|
1383 | }
|
1384 |
|
1385 | if (this.options.showColumns) {
|
1386 | html.push(Utils.sprintf('<div class="keep-open btn-group" title="%s">', this.options.formatColumns()), '<button type="button" aria-label="columns" class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">', Utils.sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.columns), ' <span class="caret"></span>', '</button>', bootstrap.html.toobarDropdow[0]);
|
1387 |
|
1388 | this.columns.forEach(function (column, i) {
|
1389 | if (column.radio || column.checkbox) {
|
1390 | return;
|
1391 | }
|
1392 |
|
1393 | if (_this4.options.cardView && !column.cardVisible) {
|
1394 | return;
|
1395 | }
|
1396 |
|
1397 | var checked = column.visible ? ' checked="checked"' : '';
|
1398 |
|
1399 | if (column.switchable) {
|
1400 | html.push(Utils.sprintf(bootstrap.html.toobarDropdowItem, Utils.sprintf('<input type="checkbox" data-field="%s" value="%s"%s> %s', column.field, i, checked, column.title)));
|
1401 | switchableCount++;
|
1402 | }
|
1403 | });
|
1404 | html.push(bootstrap.html.toobarDropdow[1], '</div>');
|
1405 | }
|
1406 |
|
1407 | html.push('</div>');
|
1408 |
|
1409 |
|
1410 | if (this.showToolbar || html.length > 2) {
|
1411 | this.$toolbar.append(html.join(''));
|
1412 | }
|
1413 |
|
1414 | if (this.options.showPaginationSwitch) {
|
1415 | this.$toolbar.find('button[name="paginationSwitch"]').off('click').on('click', $.proxy(this.togglePagination, this));
|
1416 | }
|
1417 |
|
1418 | if (this.options.showRefresh) {
|
1419 | this.$toolbar.find('button[name="refresh"]').off('click').on('click', $.proxy(this.refresh, this));
|
1420 | }
|
1421 |
|
1422 | if (this.options.showToggle) {
|
1423 | this.$toolbar.find('button[name="toggle"]').off('click').on('click', function () {
|
1424 | _this4.toggleView();
|
1425 | });
|
1426 | }
|
1427 |
|
1428 | if (this.options.showColumns) {
|
1429 | $keepOpen = this.$toolbar.find('.keep-open');
|
1430 |
|
1431 | if (switchableCount <= this.options.minimumCountColumns) {
|
1432 | $keepOpen.find('input').prop('disabled', true);
|
1433 | }
|
1434 |
|
1435 | $keepOpen.find('li').off('click').on('click', function (e) {
|
1436 | e.stopImmediatePropagation();
|
1437 | });
|
1438 | $keepOpen.find('input').off('click').on('click', function (_ref8) {
|
1439 | var currentTarget = _ref8.currentTarget;
|
1440 |
|
1441 | var $this = $(currentTarget);
|
1442 |
|
1443 | _this4.toggleColumn($this.val(), $this.prop('checked'), false);
|
1444 | _this4.trigger('column-switch', $this.data('field'), $this.prop('checked'));
|
1445 | });
|
1446 | }
|
1447 |
|
1448 | if (this.options.search) {
|
1449 | html = [];
|
1450 | html.push(Utils.sprintf('<div class="%s-%s search">', bootstrap.classes.pull, this.options.searchAlign), Utils.sprintf('<input class="form-control' + Utils.sprintf(' input-%s', this.options.iconSize) + '" type="text" placeholder="%s">', this.options.formatSearch()), '</div>');
|
1451 |
|
1452 | this.$toolbar.append(html.join(''));
|
1453 | $search = this.$toolbar.find('.search input');
|
1454 | $search.off('keyup drop blur').on('keyup drop blur', function (event) {
|
1455 | if (_this4.options.searchOnEnterKey && event.keyCode !== 13) {
|
1456 | return;
|
1457 | }
|
1458 |
|
1459 | if ([37, 38, 39, 40].includes(event.keyCode)) {
|
1460 | return;
|
1461 | }
|
1462 |
|
1463 | clearTimeout(timeoutId);
|
1464 | timeoutId = setTimeout(function () {
|
1465 | _this4.onSearch(event);
|
1466 | }, _this4.options.searchTimeOut);
|
1467 | });
|
1468 |
|
1469 | if (Utils.isIEBrowser()) {
|
1470 | $search.off('mouseup').on('mouseup', function (event) {
|
1471 | clearTimeout(timeoutId);
|
1472 | timeoutId = setTimeout(function () {
|
1473 | _this4.onSearch(event);
|
1474 | }, _this4.options.searchTimeOut);
|
1475 | });
|
1476 | }
|
1477 | }
|
1478 | }
|
1479 | }, {
|
1480 | key: 'onSearch',
|
1481 | value: function onSearch(_ref9) {
|
1482 | var currentTarget = _ref9.currentTarget,
|
1483 | firedByInitSearchText = _ref9.firedByInitSearchText;
|
1484 |
|
1485 | var text = $.trim($(currentTarget).val());
|
1486 |
|
1487 |
|
1488 | if (this.options.trimOnSearch && $(currentTarget).val() !== text) {
|
1489 | $(currentTarget).val(text);
|
1490 | }
|
1491 |
|
1492 | if (text === this.searchText) {
|
1493 | return;
|
1494 | }
|
1495 | this.searchText = text;
|
1496 | this.options.searchText = text;
|
1497 |
|
1498 | if (!firedByInitSearchText) {
|
1499 | this.options.pageNumber = 1;
|
1500 | }
|
1501 | this.initSearch();
|
1502 | if (firedByInitSearchText) {
|
1503 | if (this.options.sidePagination === 'client') {
|
1504 | this.updatePagination();
|
1505 | }
|
1506 | } else {
|
1507 | this.updatePagination();
|
1508 | }
|
1509 | this.trigger('search', text);
|
1510 | }
|
1511 | }, {
|
1512 | key: 'initSearch',
|
1513 | value: function initSearch() {
|
1514 | var _this5 = this;
|
1515 |
|
1516 | if (this.options.sidePagination !== 'server') {
|
1517 | if (this.options.customSearch) {
|
1518 | Utils.calculateObjectValue(this.options, this.options.customSearch, [this.searchText]);
|
1519 | return;
|
1520 | }
|
1521 |
|
1522 | var s = this.searchText && (this.options.escape ? Utils.escapeHTML(this.searchText) : this.searchText).toLowerCase();
|
1523 | var f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns;
|
1524 |
|
1525 |
|
1526 | this.data = f ? this.options.data.filter(function (item, i) {
|
1527 | for (var key in f) {
|
1528 | if (Array.isArray(f[key]) && !f[key].includes(item[key]) || !Array.isArray(f[key]) && item[key] !== f[key]) {
|
1529 | return false;
|
1530 | }
|
1531 | }
|
1532 | return true;
|
1533 | }) : this.options.data;
|
1534 |
|
1535 | this.data = s ? this.data.filter(function (item, i) {
|
1536 | for (var j = 0; j < _this5.header.fields.length; j++) {
|
1537 | if (!_this5.header.searchables[j]) {
|
1538 | continue;
|
1539 | }
|
1540 |
|
1541 | var key = $.isNumeric(_this5.header.fields[j]) ? parseInt(_this5.header.fields[j], 10) : _this5.header.fields[j];
|
1542 | var column = _this5.columns[_this5.fieldsColumnsIndex[key]];
|
1543 | var value = void 0;
|
1544 |
|
1545 | if (typeof key === 'string') {
|
1546 | value = item;
|
1547 | var props = key.split('.');
|
1548 | for (var _i2 = 0; _i2 < props.length; _i2++) {
|
1549 | if (value[props[_i2]] !== null) {
|
1550 | value = value[props[_i2]];
|
1551 | }
|
1552 | }
|
1553 | } else {
|
1554 | value = item[key];
|
1555 | }
|
1556 |
|
1557 |
|
1558 | if (column && column.searchFormatter) {
|
1559 | value = Utils.calculateObjectValue(column, _this5.header.formatters[j], [value, item, i], value);
|
1560 | }
|
1561 |
|
1562 | if (typeof value === 'string' || typeof value === 'number') {
|
1563 | if (_this5.options.strictSearch) {
|
1564 | if (('' + value).toLowerCase() === s) {
|
1565 | return true;
|
1566 | }
|
1567 | } else {
|
1568 | if (('' + value).toLowerCase().includes(s)) {
|
1569 | return true;
|
1570 | }
|
1571 | }
|
1572 | }
|
1573 | }
|
1574 | return false;
|
1575 | }) : this.data;
|
1576 | }
|
1577 | }
|
1578 | }, {
|
1579 | key: 'initPagination',
|
1580 | value: function initPagination() {
|
1581 | var _this6 = this;
|
1582 |
|
1583 | if (!this.options.pagination) {
|
1584 | this.$pagination.hide();
|
1585 | return;
|
1586 | }
|
1587 | this.$pagination.show();
|
1588 |
|
1589 | var html = [];
|
1590 | var $allSelected = false;
|
1591 | var i = void 0;
|
1592 | var from = void 0;
|
1593 | var to = void 0;
|
1594 | var $pageList = void 0;
|
1595 | var $pre = void 0;
|
1596 | var $next = void 0;
|
1597 | var $number = void 0;
|
1598 | var data = this.getData();
|
1599 | var pageList = this.options.pageList;
|
1600 |
|
1601 | if (this.options.sidePagination !== 'server') {
|
1602 | this.options.totalRows = data.length;
|
1603 | }
|
1604 |
|
1605 | this.totalPages = 0;
|
1606 | if (this.options.totalRows) {
|
1607 | if (this.options.pageSize === this.options.formatAllRows()) {
|
1608 | this.options.pageSize = this.options.totalRows;
|
1609 | $allSelected = true;
|
1610 | } else if (this.options.pageSize === this.options.totalRows) {
|
1611 |
|
1612 |
|
1613 | var pageLst = typeof this.options.pageList === 'string' ? this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').toLowerCase().split(',') : this.options.pageList;
|
1614 | if (pageLst.includes(this.options.formatAllRows().toLowerCase())) {
|
1615 | $allSelected = true;
|
1616 | }
|
1617 | }
|
1618 |
|
1619 | this.totalPages = ~~((this.options.totalRows - 1) / this.options.pageSize) + 1;
|
1620 |
|
1621 | this.options.totalPages = this.totalPages;
|
1622 | }
|
1623 | if (this.totalPages > 0 && this.options.pageNumber > this.totalPages) {
|
1624 | this.options.pageNumber = this.totalPages;
|
1625 | }
|
1626 |
|
1627 | this.pageFrom = (this.options.pageNumber - 1) * this.options.pageSize + 1;
|
1628 | this.pageTo = this.options.pageNumber * this.options.pageSize;
|
1629 | if (this.pageTo > this.options.totalRows) {
|
1630 | this.pageTo = this.options.totalRows;
|
1631 | }
|
1632 |
|
1633 | html.push(Utils.sprintf('<div class="%s-%s pagination-detail">', bootstrap.classes.pull, this.options.paginationDetailHAlign), '<span class="pagination-info">', this.options.onlyInfoPagination ? this.options.formatDetailPagination(this.options.totalRows) : this.options.formatShowingRows(this.pageFrom, this.pageTo, this.options.totalRows), '</span>');
|
1634 |
|
1635 | if (!this.options.onlyInfoPagination) {
|
1636 | html.push('<span class="page-list">');
|
1637 |
|
1638 | var pageNumber = [Utils.sprintf('<span class="btn-group %s">', this.options.paginationVAlign === 'top' || this.options.paginationVAlign === 'both' ? 'dropdown' : 'dropup'), '<button type="button" class="btn' + Utils.sprintf(' btn-%s', this.options.buttonsClass) + Utils.sprintf(' btn-%s', this.options.iconSize) + ' dropdown-toggle" data-toggle="dropdown">', '<span class="page-size">', $allSelected ? this.options.formatAllRows() : this.options.pageSize, '</span>', ' <span class="caret"></span>', '</button>', bootstrap.html.pageDropdown[0]];
|
1639 |
|
1640 | if (typeof this.options.pageList === 'string') {
|
1641 | var list = this.options.pageList.replace('[', '').replace(']', '').replace(/ /g, '').split(',');
|
1642 |
|
1643 | pageList = [];
|
1644 | var _iteratorNormalCompletion9 = true;
|
1645 | var _didIteratorError9 = false;
|
1646 | var _iteratorError9 = undefined;
|
1647 |
|
1648 | try {
|
1649 | for (var _iterator9 = list[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
|
1650 | var value = _step9.value;
|
1651 |
|
1652 | pageList.push(value.toUpperCase() === this.options.formatAllRows().toUpperCase() || value.toUpperCase() === 'UNLIMITED' ? this.options.formatAllRows() : +value);
|
1653 | }
|
1654 | } catch (err) {
|
1655 | _didIteratorError9 = true;
|
1656 | _iteratorError9 = err;
|
1657 | } finally {
|
1658 | try {
|
1659 | if (!_iteratorNormalCompletion9 && _iterator9.return) {
|
1660 | _iterator9.return();
|
1661 | }
|
1662 | } finally {
|
1663 | if (_didIteratorError9) {
|
1664 | throw _iteratorError9;
|
1665 | }
|
1666 | }
|
1667 | }
|
1668 | }
|
1669 |
|
1670 | pageList.forEach(function (page, i) {
|
1671 | if (!_this6.options.smartDisplay || i === 0 || pageList[i - 1] < _this6.options.totalRows) {
|
1672 | var active = void 0;
|
1673 | if ($allSelected) {
|
1674 | active = page === _this6.options.formatAllRows() ? 'active' : '';
|
1675 | } else {
|
1676 | active = page === _this6.options.pageSize ? 'active' : '';
|
1677 | }
|
1678 | pageNumber.push(Utils.sprintf(bootstrap.html.pageDropdownItem, active, page));
|
1679 | }
|
1680 | });
|
1681 | pageNumber.push(bootstrap.html.pageDropdown[1] + '</span>');
|
1682 |
|
1683 | html.push(this.options.formatRecordsPerPage(pageNumber.join('')));
|
1684 | html.push('</span>');
|
1685 |
|
1686 | html.push('</div>', Utils.sprintf('<div class="%s-%s pagination">', bootstrap.classes.pull, this.options.paginationHAlign), '<ul class="pagination' + Utils.sprintf(' pagination-%s', this.options.iconSize) + '">', Utils.sprintf('<li class="page-item page-pre"><a class="page-link" href="#">%s</a></li>', this.options.paginationPreText));
|
1687 |
|
1688 | if (this.totalPages < this.options.paginationSuccessivelySize) {
|
1689 | from = 1;
|
1690 | to = this.totalPages;
|
1691 | } else {
|
1692 | from = this.options.pageNumber - this.options.paginationPagesBySide;
|
1693 | to = from + this.options.paginationPagesBySide * 2;
|
1694 | }
|
1695 |
|
1696 | if (this.options.pageNumber < this.options.paginationSuccessivelySize - 1) {
|
1697 | to = this.options.paginationSuccessivelySize;
|
1698 | }
|
1699 |
|
1700 | if (to > this.totalPages) {
|
1701 | to = this.totalPages;
|
1702 | }
|
1703 |
|
1704 | if (this.options.paginationSuccessivelySize > this.totalPages - from) {
|
1705 | from = from - (this.options.paginationSuccessivelySize - (this.totalPages - from)) + 1;
|
1706 | }
|
1707 |
|
1708 | if (from < 1) {
|
1709 | from = 1;
|
1710 | }
|
1711 |
|
1712 | if (to > this.totalPages) {
|
1713 | to = this.totalPages;
|
1714 | }
|
1715 |
|
1716 | var middleSize = Math.round(this.options.paginationPagesBySide / 2);
|
1717 | var pageItem = function pageItem(i) {
|
1718 | var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
1719 | return '\n <li class="page-item' + classes + (i === _this6.options.pageNumber ? ' active' : '') + '">\n <a class="page-link" href="#">' + i + '</a>\n </li>\n ';
|
1720 | };
|
1721 |
|
1722 | if (from > 1) {
|
1723 | var max = this.options.paginationPagesBySide;
|
1724 | if (max >= from) max = from - 1;
|
1725 | for (i = 1; i <= max; i++) {
|
1726 | html.push(pageItem(i));
|
1727 | }
|
1728 | if (from - 1 === max + 1) {
|
1729 | i = from - 1;
|
1730 | html.push(pageItem(i));
|
1731 | } else {
|
1732 | if (from - 1 > max) {
|
1733 | if (from - this.options.paginationPagesBySide * 2 > this.options.paginationPagesBySide && this.options.paginationUseIntermediate) {
|
1734 | i = Math.round((from - middleSize) / 2 + middleSize);
|
1735 | html.push(pageItem(i, ' page-intermediate'));
|
1736 | } else {
|
1737 | html.push('\n <li class="page-item page-first-separator disabled">\n <a class="page-link" href="#">...</a>\n </li>');
|
1738 | }
|
1739 | }
|
1740 | }
|
1741 | }
|
1742 |
|
1743 | for (i = from; i <= to; i++) {
|
1744 | html.push(pageItem(i));
|
1745 | }
|
1746 |
|
1747 | if (this.totalPages > to) {
|
1748 | var min = this.totalPages - (this.options.paginationPagesBySide - 1);
|
1749 | if (to >= min) min = to + 1;
|
1750 | if (to + 1 === min - 1) {
|
1751 | i = to + 1;
|
1752 | html.push(pageItem(i));
|
1753 | } else {
|
1754 | if (min > to + 1) {
|
1755 | if (this.totalPages - to > this.options.paginationPagesBySide * 2 && this.options.paginationUseIntermediate) {
|
1756 | i = Math.round((this.totalPages - middleSize - to) / 2 + to);
|
1757 | html.push(pageItem(i, ' page-intermediate'));
|
1758 | } else {
|
1759 | html.push('\n <li class="page-item page-last-separator disabled">\n <a class="page-link" href="#">...</a>\n </li>');
|
1760 | }
|
1761 | }
|
1762 | }
|
1763 |
|
1764 | for (i = min; i <= this.totalPages; i++) {
|
1765 | html.push(pageItem(i));
|
1766 | }
|
1767 | }
|
1768 |
|
1769 | html.push('\n <li class="page-item page-next">\n <a class="page-link" href="#">' + this.options.paginationNextText + '</a>\n </li>\n </ul>\n </div>\n ');
|
1770 | }
|
1771 | this.$pagination.html(html.join(''));
|
1772 |
|
1773 | if (!this.options.onlyInfoPagination) {
|
1774 | $pageList = this.$pagination.find('.page-list a');
|
1775 | $pre = this.$pagination.find('.page-pre');
|
1776 | $next = this.$pagination.find('.page-next');
|
1777 | $number = this.$pagination.find('.page-item').not('.page-next, .page-pre');
|
1778 |
|
1779 | if (this.options.smartDisplay) {
|
1780 | if (this.totalPages <= 1) {
|
1781 | this.$pagination.find('div.pagination').hide();
|
1782 | }
|
1783 | if (pageList.length < 2 || this.options.totalRows <= pageList[0]) {
|
1784 | this.$pagination.find('span.page-list').hide();
|
1785 | }
|
1786 |
|
1787 |
|
1788 | this.$pagination[this.getData().length ? 'show' : 'hide']();
|
1789 | }
|
1790 |
|
1791 | if (!this.options.paginationLoop) {
|
1792 | if (this.options.pageNumber === 1) {
|
1793 | $pre.addClass('disabled');
|
1794 | }
|
1795 | if (this.options.pageNumber === this.totalPages) {
|
1796 | $next.addClass('disabled');
|
1797 | }
|
1798 | }
|
1799 |
|
1800 | if ($allSelected) {
|
1801 | this.options.pageSize = this.options.formatAllRows();
|
1802 | }
|
1803 |
|
1804 | $pageList.off('click').on('click', $.proxy(this.onPageListChange, this));
|
1805 | $pre.off('click').on('click', $.proxy(this.onPagePre, this));
|
1806 | $next.off('click').on('click', $.proxy(this.onPageNext, this));
|
1807 | $number.off('click').on('click', $.proxy(this.onPageNumber, this));
|
1808 | }
|
1809 | }
|
1810 | }, {
|
1811 | key: 'updatePagination',
|
1812 | value: function updatePagination(event) {
|
1813 |
|
1814 | if (event && $(event.currentTarget).hasClass('disabled')) {
|
1815 | return;
|
1816 | }
|
1817 |
|
1818 | if (!this.options.maintainSelected) {
|
1819 | this.resetRows();
|
1820 | }
|
1821 |
|
1822 | this.initPagination();
|
1823 | if (this.options.sidePagination === 'server') {
|
1824 | this.initServer();
|
1825 | } else {
|
1826 | this.initBody();
|
1827 | }
|
1828 |
|
1829 | this.trigger('page-change', this.options.pageNumber, this.options.pageSize);
|
1830 | }
|
1831 | }, {
|
1832 | key: 'onPageListChange',
|
1833 | value: function onPageListChange(event) {
|
1834 | event.preventDefault();
|
1835 | var $this = $(event.currentTarget);
|
1836 |
|
1837 | $this.parent().addClass('active').siblings().removeClass('active');
|
1838 | this.options.pageSize = $this.text().toUpperCase() === this.options.formatAllRows().toUpperCase() ? this.options.formatAllRows() : +$this.text();
|
1839 | this.$toolbar.find('.page-size').text(this.options.pageSize);
|
1840 |
|
1841 | this.updatePagination(event);
|
1842 | return false;
|
1843 | }
|
1844 | }, {
|
1845 | key: 'onPagePre',
|
1846 | value: function onPagePre(event) {
|
1847 | event.preventDefault();
|
1848 | if (this.options.pageNumber - 1 === 0) {
|
1849 | this.options.pageNumber = this.options.totalPages;
|
1850 | } else {
|
1851 | this.options.pageNumber--;
|
1852 | }
|
1853 | this.updatePagination(event);
|
1854 | return false;
|
1855 | }
|
1856 | }, {
|
1857 | key: 'onPageNext',
|
1858 | value: function onPageNext(event) {
|
1859 | event.preventDefault();
|
1860 | if (this.options.pageNumber + 1 > this.options.totalPages) {
|
1861 | this.options.pageNumber = 1;
|
1862 | } else {
|
1863 | this.options.pageNumber++;
|
1864 | }
|
1865 | this.updatePagination(event);
|
1866 | return false;
|
1867 | }
|
1868 | }, {
|
1869 | key: 'onPageNumber',
|
1870 | value: function onPageNumber(event) {
|
1871 | event.preventDefault();
|
1872 | if (this.options.pageNumber === +$(event.currentTarget).text()) {
|
1873 | return;
|
1874 | }
|
1875 | this.options.pageNumber = +$(event.currentTarget).text();
|
1876 | this.updatePagination(event);
|
1877 | return false;
|
1878 | }
|
1879 | }, {
|
1880 | key: 'initRow',
|
1881 | value: function initRow(item, i, data, parentDom) {
|
1882 | var _this7 = this;
|
1883 |
|
1884 | var html = [];
|
1885 | var style = {};
|
1886 | var csses = [];
|
1887 | var data_ = '';
|
1888 | var attributes = {};
|
1889 | var htmlAttributes = [];
|
1890 |
|
1891 | if (Utils.findIndex(this.hiddenRows, item) > -1) {
|
1892 | return;
|
1893 | }
|
1894 |
|
1895 | style = Utils.calculateObjectValue(this.options, this.options.rowStyle, [item, i], style);
|
1896 |
|
1897 | if (style && style.css) {
|
1898 | var _iteratorNormalCompletion10 = true;
|
1899 | var _didIteratorError10 = false;
|
1900 | var _iteratorError10 = undefined;
|
1901 |
|
1902 | try {
|
1903 | for (var _iterator10 = Object.entries(style.css)[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
|
1904 | var _ref10 = _step10.value;
|
1905 |
|
1906 | var _ref11 = _slicedToArray(_ref10, 2);
|
1907 |
|
1908 | var key = _ref11[0];
|
1909 | var value = _ref11[1];
|
1910 |
|
1911 | csses.push(key + ': ' + value);
|
1912 | }
|
1913 | } catch (err) {
|
1914 | _didIteratorError10 = true;
|
1915 | _iteratorError10 = err;
|
1916 | } finally {
|
1917 | try {
|
1918 | if (!_iteratorNormalCompletion10 && _iterator10.return) {
|
1919 | _iterator10.return();
|
1920 | }
|
1921 | } finally {
|
1922 | if (_didIteratorError10) {
|
1923 | throw _iteratorError10;
|
1924 | }
|
1925 | }
|
1926 | }
|
1927 | }
|
1928 |
|
1929 | attributes = Utils.calculateObjectValue(this.options, this.options.rowAttributes, [item, i], attributes);
|
1930 |
|
1931 | if (attributes) {
|
1932 | var _iteratorNormalCompletion11 = true;
|
1933 | var _didIteratorError11 = false;
|
1934 | var _iteratorError11 = undefined;
|
1935 |
|
1936 | try {
|
1937 | for (var _iterator11 = Object.entries(attributes)[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
|
1938 | var _ref12 = _step11.value;
|
1939 |
|
1940 | var _ref13 = _slicedToArray(_ref12, 2);
|
1941 |
|
1942 | var _key2 = _ref13[0];
|
1943 | var _value2 = _ref13[1];
|
1944 |
|
1945 | htmlAttributes.push(_key2 + '="' + Utils.escapeHTML(_value2) + '"');
|
1946 | }
|
1947 | } catch (err) {
|
1948 | _didIteratorError11 = true;
|
1949 | _iteratorError11 = err;
|
1950 | } finally {
|
1951 | try {
|
1952 | if (!_iteratorNormalCompletion11 && _iterator11.return) {
|
1953 | _iterator11.return();
|
1954 | }
|
1955 | } finally {
|
1956 | if (_didIteratorError11) {
|
1957 | throw _iteratorError11;
|
1958 | }
|
1959 | }
|
1960 | }
|
1961 | }
|
1962 |
|
1963 | if (item._data && !$.isEmptyObject(item._data)) {
|
1964 | var _iteratorNormalCompletion12 = true;
|
1965 | var _didIteratorError12 = false;
|
1966 | var _iteratorError12 = undefined;
|
1967 |
|
1968 | try {
|
1969 | for (var _iterator12 = Object.entries(item._data)[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
|
1970 | var _ref14 = _step12.value;
|
1971 |
|
1972 | var _ref15 = _slicedToArray(_ref14, 2);
|
1973 |
|
1974 | var k = _ref15[0];
|
1975 | var v = _ref15[1];
|
1976 |
|
1977 |
|
1978 | if (k === 'index') {
|
1979 | return;
|
1980 | }
|
1981 | data_ += ' data-' + k + '="' + v + '"';
|
1982 | }
|
1983 | } catch (err) {
|
1984 | _didIteratorError12 = true;
|
1985 | _iteratorError12 = err;
|
1986 | } finally {
|
1987 | try {
|
1988 | if (!_iteratorNormalCompletion12 && _iterator12.return) {
|
1989 | _iterator12.return();
|
1990 | }
|
1991 | } finally {
|
1992 | if (_didIteratorError12) {
|
1993 | throw _iteratorError12;
|
1994 | }
|
1995 | }
|
1996 | }
|
1997 | }
|
1998 |
|
1999 | html.push('<tr', Utils.sprintf(' %s', htmlAttributes.length ? htmlAttributes.join(' ') : undefined), Utils.sprintf(' id="%s"', Array.isArray(item) ? undefined : item._id), Utils.sprintf(' class="%s"', style.classes || (Array.isArray(item) ? undefined : item._class)), ' data-index="' + i + '"', Utils.sprintf(' data-uniqueid="%s"', item[this.options.uniqueId]), Utils.sprintf('%s', data_), '>');
|
2000 |
|
2001 | if (this.options.cardView) {
|
2002 | html.push('<td colspan="' + this.header.fields.length + '"><div class="card-views">');
|
2003 | }
|
2004 |
|
2005 | if (!this.options.cardView && this.options.detailView) {
|
2006 | html.push('<td>');
|
2007 |
|
2008 | if (Utils.calculateObjectValue(null, this.options.detailFilter, [i, item])) {
|
2009 | html.push('\n <a class="detail-icon" href="#">\n <i class="' + this.options.iconsPrefix + ' ' + this.options.icons.detailOpen + '"></i>\n </a>\n ');
|
2010 | }
|
2011 |
|
2012 | html.push('</td>');
|
2013 | }
|
2014 |
|
2015 | this.header.fields.forEach(function (field, j) {
|
2016 | var text = '';
|
2017 | var value_ = Utils.getItemField(item, field, _this7.options.escape);
|
2018 | var value = '';
|
2019 | var type = '';
|
2020 | var cellStyle = {};
|
2021 | var id_ = '';
|
2022 | var class_ = _this7.header.classes[j];
|
2023 | var style_ = '';
|
2024 | var data_ = '';
|
2025 | var rowspan_ = '';
|
2026 | var colspan_ = '';
|
2027 | var title_ = '';
|
2028 | var column = _this7.columns[j];
|
2029 |
|
2030 | if (_this7.fromHtml && typeof value_ === 'undefined') {
|
2031 | if (!column.checkbox && !column.radio) {
|
2032 | return;
|
2033 | }
|
2034 | }
|
2035 |
|
2036 | if (!column.visible) {
|
2037 | return;
|
2038 | }
|
2039 |
|
2040 | if (_this7.options.cardView && !column.cardVisible) {
|
2041 | return;
|
2042 | }
|
2043 |
|
2044 | if (column.escape) {
|
2045 | value_ = Utils.escapeHTML(value_);
|
2046 | }
|
2047 |
|
2048 | if (csses.concat([_this7.header.styles[j]]).length) {
|
2049 | style_ = ' style="' + csses.concat([_this7.header.styles[j]]).join('; ') + '"';
|
2050 | }
|
2051 |
|
2052 | if (item['_' + field + '_id']) {
|
2053 | id_ = Utils.sprintf(' id="%s"', item['_' + field + '_id']);
|
2054 | }
|
2055 | if (item['_' + field + '_class']) {
|
2056 | class_ = Utils.sprintf(' class="%s"', item['_' + field + '_class']);
|
2057 | }
|
2058 | if (item['_' + field + '_rowspan']) {
|
2059 | rowspan_ = Utils.sprintf(' rowspan="%s"', item['_' + field + '_rowspan']);
|
2060 | }
|
2061 | if (item['_' + field + '_colspan']) {
|
2062 | colspan_ = Utils.sprintf(' colspan="%s"', item['_' + field + '_colspan']);
|
2063 | }
|
2064 | if (item['_' + field + '_title']) {
|
2065 | title_ = Utils.sprintf(' title="%s"', item['_' + field + '_title']);
|
2066 | }
|
2067 | cellStyle = Utils.calculateObjectValue(_this7.header, _this7.header.cellStyles[j], [value_, item, i, field], cellStyle);
|
2068 | if (cellStyle.classes) {
|
2069 | class_ = ' class="' + cellStyle.classes + '"';
|
2070 | }
|
2071 | if (cellStyle.css) {
|
2072 | var csses_ = [];
|
2073 | var _iteratorNormalCompletion13 = true;
|
2074 | var _didIteratorError13 = false;
|
2075 | var _iteratorError13 = undefined;
|
2076 |
|
2077 | try {
|
2078 | for (var _iterator13 = Object.entries(cellStyle.css)[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
|
2079 | var _ref16 = _step13.value;
|
2080 |
|
2081 | var _ref17 = _slicedToArray(_ref16, 2);
|
2082 |
|
2083 | var _key3 = _ref17[0];
|
2084 | var _value3 = _ref17[1];
|
2085 |
|
2086 | csses_.push(_key3 + ': ' + _value3);
|
2087 | }
|
2088 | } catch (err) {
|
2089 | _didIteratorError13 = true;
|
2090 | _iteratorError13 = err;
|
2091 | } finally {
|
2092 | try {
|
2093 | if (!_iteratorNormalCompletion13 && _iterator13.return) {
|
2094 | _iterator13.return();
|
2095 | }
|
2096 | } finally {
|
2097 | if (_didIteratorError13) {
|
2098 | throw _iteratorError13;
|
2099 | }
|
2100 | }
|
2101 | }
|
2102 |
|
2103 | style_ = ' style="' + csses_.concat(_this7.header.styles[j]).join('; ') + '"';
|
2104 | }
|
2105 |
|
2106 | value = Utils.calculateObjectValue(column, _this7.header.formatters[j], [value_, item, i, field], value_);
|
2107 |
|
2108 | if (item['_' + field + '_data'] && !$.isEmptyObject(item['_' + field + '_data'])) {
|
2109 | var _iteratorNormalCompletion14 = true;
|
2110 | var _didIteratorError14 = false;
|
2111 | var _iteratorError14 = undefined;
|
2112 |
|
2113 | try {
|
2114 | for (var _iterator14 = Object.entries(item['_' + field + '_data'])[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
|
2115 | var _ref18 = _step14.value;
|
2116 |
|
2117 | var _ref19 = _slicedToArray(_ref18, 2);
|
2118 |
|
2119 | var _k2 = _ref19[0];
|
2120 | var _v = _ref19[1];
|
2121 |
|
2122 |
|
2123 | if (_k2 === 'index') {
|
2124 | return;
|
2125 | }
|
2126 | data_ += ' data-' + _k2 + '="' + _v + '"';
|
2127 | }
|
2128 | } catch (err) {
|
2129 | _didIteratorError14 = true;
|
2130 | _iteratorError14 = err;
|
2131 | } finally {
|
2132 | try {
|
2133 | if (!_iteratorNormalCompletion14 && _iterator14.return) {
|
2134 | _iterator14.return();
|
2135 | }
|
2136 | } finally {
|
2137 | if (_didIteratorError14) {
|
2138 | throw _iteratorError14;
|
2139 | }
|
2140 | }
|
2141 | }
|
2142 | }
|
2143 |
|
2144 | if (column.checkbox || column.radio) {
|
2145 | type = column.checkbox ? 'checkbox' : type;
|
2146 | type = column.radio ? 'radio' : type;
|
2147 |
|
2148 | var c = column['class'] || '';
|
2149 | var isChecked = value === true || value_ || value && value.checked;
|
2150 | var isDisabled = !column.checkboxEnabled || value && value.disabled;
|
2151 |
|
2152 | text = [_this7.options.cardView ? '<div class="card-view ' + c + '">' : '<td class="bs-checkbox ' + c + '">', '<input\n data-index="' + i + '"\n name="' + _this7.options.selectItemName + '"\n type="' + type + '"\n ' + Utils.sprintf('value="%s"', item[_this7.options.idField]) + '\n ' + Utils.sprintf('checked="%s"', isChecked ? 'checked' : undefined) + '\n ' + Utils.sprintf('disabled="%s"', isDisabled ? 'disabled' : undefined) + ' />', _this7.header.formatters[j] && typeof value === 'string' ? value : '', _this7.options.cardView ? '</div>' : '</td>'].join('');
|
2153 |
|
2154 | item[_this7.header.stateField] = value === true || !!value_ || value && value.checked;
|
2155 | } else {
|
2156 | value = typeof value === 'undefined' || value === null ? _this7.options.undefinedText : value;
|
2157 |
|
2158 | if (_this7.options.cardView) {
|
2159 | var cardTitle = _this7.options.showHeader ? '<span class="title"' + style + '>' + Utils.getFieldTitle(_this7.columns, field) + '</span>' : '';
|
2160 |
|
2161 | text = '<div class="card-view">' + cardTitle + '<span class="value">' + value + '</span></div>';
|
2162 |
|
2163 | if (_this7.options.smartDisplay && value === '') {
|
2164 | text = '<div class="card-view"></div>';
|
2165 | }
|
2166 | } else {
|
2167 | text = '<td' + id_ + class_ + style_ + data_ + rowspan_ + colspan_ + title_ + '>' + value + '</td>';
|
2168 | }
|
2169 | }
|
2170 |
|
2171 | html.push(text);
|
2172 | });
|
2173 |
|
2174 | if (this.options.cardView) {
|
2175 | html.push('</div></td>');
|
2176 | }
|
2177 | html.push('</tr>');
|
2178 |
|
2179 | return html.join('');
|
2180 | }
|
2181 | }, {
|
2182 | key: 'initBody',
|
2183 | value: function initBody(fixedScroll) {
|
2184 | var _this8 = this;
|
2185 |
|
2186 | var data = this.getData();
|
2187 |
|
2188 | this.trigger('pre-body', data);
|
2189 |
|
2190 | this.$body = this.$el.find('>tbody');
|
2191 | if (!this.$body.length) {
|
2192 | this.$body = $('<tbody></tbody>').appendTo(this.$el);
|
2193 | }
|
2194 |
|
2195 |
|
2196 | if (!this.options.pagination || this.options.sidePagination === 'server') {
|
2197 | this.pageFrom = 1;
|
2198 | this.pageTo = data.length;
|
2199 | }
|
2200 |
|
2201 | var trFragments = $(document.createDocumentFragment());
|
2202 | var hasTr = false;
|
2203 |
|
2204 | for (var i = this.pageFrom - 1; i < this.pageTo; i++) {
|
2205 | var item = data[i];
|
2206 | var tr = this.initRow(item, i, data, trFragments);
|
2207 | hasTr = hasTr || !!tr;
|
2208 | if (tr && typeof tr === 'string') {
|
2209 | trFragments.append(tr);
|
2210 | }
|
2211 | }
|
2212 |
|
2213 |
|
2214 | if (!hasTr) {
|
2215 | this.$body.html('<tr class="no-records-found">' + Utils.sprintf('<td colspan="%s">%s</td>', this.$header.find('th').length, this.options.formatNoMatches()) + '</tr>');
|
2216 | } else {
|
2217 | this.$body.html(trFragments);
|
2218 | }
|
2219 |
|
2220 | if (!fixedScroll) {
|
2221 | this.scrollTo(0);
|
2222 | }
|
2223 |
|
2224 |
|
2225 | this.$body.find('> tr[data-index] > td').off('click dblclick').on('click dblclick', function (_ref20) {
|
2226 | var currentTarget = _ref20.currentTarget,
|
2227 | type = _ref20.type,
|
2228 | target = _ref20.target;
|
2229 |
|
2230 | var $td = $(currentTarget);
|
2231 | var $tr = $td.parent();
|
2232 | var item = _this8.data[$tr.data('index')];
|
2233 | var index = $td[0].cellIndex;
|
2234 | var fields = _this8.getVisibleFields();
|
2235 | var field = fields[_this8.options.detailView && !_this8.options.cardView ? index - 1 : index];
|
2236 | var column = _this8.columns[_this8.fieldsColumnsIndex[field]];
|
2237 | var value = Utils.getItemField(item, field, _this8.options.escape);
|
2238 |
|
2239 | if ($td.find('.detail-icon').length) {
|
2240 | return;
|
2241 | }
|
2242 |
|
2243 | _this8.trigger(type === 'click' ? 'click-cell' : 'dbl-click-cell', field, value, item, $td);
|
2244 | _this8.trigger(type === 'click' ? 'click-row' : 'dbl-click-row', item, $tr, field);
|
2245 |
|
2246 |
|
2247 | if (type === 'click' && _this8.options.clickToSelect && column.clickToSelect && !_this8.options.ignoreClickToSelectOn(target)) {
|
2248 | var $selectItem = $tr.find(Utils.sprintf('[name="%s"]', _this8.options.selectItemName));
|
2249 | if ($selectItem.length) {
|
2250 | $selectItem[0].click();
|
2251 | }
|
2252 | }
|
2253 | });
|
2254 |
|
2255 | this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) {
|
2256 | e.preventDefault();
|
2257 |
|
2258 | var $this = $(e.currentTarget);
|
2259 | var $tr = $this.parent().parent();
|
2260 | var index = $tr.data('index');
|
2261 | var row = data[index];
|
2262 |
|
2263 |
|
2264 | if ($tr.next().is('tr.detail-view')) {
|
2265 | $this.find('i').attr('class', Utils.sprintf('%s %s', _this8.options.iconsPrefix, _this8.options.icons.detailOpen));
|
2266 | _this8.trigger('collapse-row', index, row, $tr.next());
|
2267 | $tr.next().remove();
|
2268 | } else {
|
2269 | $this.find('i').attr('class', Utils.sprintf('%s %s', _this8.options.iconsPrefix, _this8.options.icons.detailClose));
|
2270 | $tr.after(Utils.sprintf('<tr class="detail-view"><td colspan="%s"></td></tr>', $tr.find('td').length));
|
2271 | var $element = $tr.next().find('td');
|
2272 | var content = Utils.calculateObjectValue(_this8.options, _this8.options.detailFormatter, [index, row, $element], '');
|
2273 | if ($element.length === 1) {
|
2274 | $element.append(content);
|
2275 | }
|
2276 | _this8.trigger('expand-row', index, row, $element);
|
2277 | }
|
2278 | _this8.resetView();
|
2279 | return false;
|
2280 | });
|
2281 |
|
2282 | this.$selectItem = this.$body.find(Utils.sprintf('[name="%s"]', this.options.selectItemName));
|
2283 | this.$selectItem.off('click').on('click', function (e) {
|
2284 | e.stopImmediatePropagation();
|
2285 |
|
2286 | var $this = $(e.currentTarget);
|
2287 | _this8.check_($this.prop('checked'), $this.data('index'));
|
2288 | });
|
2289 |
|
2290 | this.header.events.forEach(function (_events, i) {
|
2291 | var events = _events;
|
2292 | if (!events) {
|
2293 | return;
|
2294 | }
|
2295 |
|
2296 | if (typeof events === 'string') {
|
2297 | events = Utils.calculateObjectValue(null, events);
|
2298 | }
|
2299 |
|
2300 | var field = _this8.header.fields[i];
|
2301 | var fieldIndex = _this8.getVisibleFields().indexOf(field);
|
2302 |
|
2303 | if (fieldIndex === -1) {
|
2304 | return;
|
2305 | }
|
2306 |
|
2307 | if (_this8.options.detailView && !_this8.options.cardView) {
|
2308 | fieldIndex += 1;
|
2309 | }
|
2310 |
|
2311 | var _loop = function _loop(key, event) {
|
2312 | _this8.$body.find('>tr:not(.no-records-found)').each(function (i, tr) {
|
2313 | var $tr = $(tr);
|
2314 | var $td = $tr.find(_this8.options.cardView ? '.card-view' : 'td').eq(fieldIndex);
|
2315 | var index = key.indexOf(' ');
|
2316 | var name = key.substring(0, index);
|
2317 | var el = key.substring(index + 1);
|
2318 |
|
2319 | $td.find(el).off(name).on(name, function (e) {
|
2320 | var index = $tr.data('index');
|
2321 | var row = _this8.data[index];
|
2322 | var value = row[field];
|
2323 |
|
2324 | event.apply(_this8, [e, value, row, index]);
|
2325 | });
|
2326 | });
|
2327 | };
|
2328 |
|
2329 | var _iteratorNormalCompletion15 = true;
|
2330 | var _didIteratorError15 = false;
|
2331 | var _iteratorError15 = undefined;
|
2332 |
|
2333 | try {
|
2334 | for (var _iterator15 = Object.entries(events)[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
|
2335 | var _ref21 = _step15.value;
|
2336 |
|
2337 | var _ref22 = _slicedToArray(_ref21, 2);
|
2338 |
|
2339 | var key = _ref22[0];
|
2340 | var event = _ref22[1];
|
2341 |
|
2342 | _loop(key, event);
|
2343 | }
|
2344 | } catch (err) {
|
2345 | _didIteratorError15 = true;
|
2346 | _iteratorError15 = err;
|
2347 | } finally {
|
2348 | try {
|
2349 | if (!_iteratorNormalCompletion15 && _iterator15.return) {
|
2350 | _iterator15.return();
|
2351 | }
|
2352 | } finally {
|
2353 | if (_didIteratorError15) {
|
2354 | throw _iteratorError15;
|
2355 | }
|
2356 | }
|
2357 | }
|
2358 | });
|
2359 |
|
2360 | this.updateSelected();
|
2361 | this.resetView();
|
2362 |
|
2363 | this.trigger('post-body', data);
|
2364 | }
|
2365 | }, {
|
2366 | key: 'initServer',
|
2367 | value: function initServer(silent, query, url) {
|
2368 | var _this9 = this;
|
2369 |
|
2370 | var data = {};
|
2371 | var index = this.header.fields.indexOf(this.options.sortName);
|
2372 |
|
2373 | var params = {
|
2374 | searchText: this.searchText,
|
2375 | sortName: this.options.sortName,
|
2376 | sortOrder: this.options.sortOrder
|
2377 | };
|
2378 |
|
2379 | if (this.header.sortNames[index]) {
|
2380 | params.sortName = this.header.sortNames[index];
|
2381 | }
|
2382 |
|
2383 | if (this.options.pagination && this.options.sidePagination === 'server') {
|
2384 | params.pageSize = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize;
|
2385 | params.pageNumber = this.options.pageNumber;
|
2386 | }
|
2387 |
|
2388 | if (!(url || this.options.url) && !this.options.ajax) {
|
2389 | return;
|
2390 | }
|
2391 |
|
2392 | if (this.options.queryParamsType === 'limit') {
|
2393 | params = {
|
2394 | search: params.searchText,
|
2395 | sort: params.sortName,
|
2396 | order: params.sortOrder
|
2397 | };
|
2398 |
|
2399 | if (this.options.pagination && this.options.sidePagination === 'server') {
|
2400 | params.offset = this.options.pageSize === this.options.formatAllRows() ? 0 : this.options.pageSize * (this.options.pageNumber - 1);
|
2401 | params.limit = this.options.pageSize === this.options.formatAllRows() ? this.options.totalRows : this.options.pageSize;
|
2402 | if (params.limit === 0) {
|
2403 | delete params.limit;
|
2404 | }
|
2405 | }
|
2406 | }
|
2407 |
|
2408 | if (!$.isEmptyObject(this.filterColumnsPartial)) {
|
2409 | params.filter = JSON.stringify(this.filterColumnsPartial, null);
|
2410 | }
|
2411 |
|
2412 | data = Utils.calculateObjectValue(this.options, this.options.queryParams, [params], data);
|
2413 |
|
2414 | $.extend(data, query || {});
|
2415 |
|
2416 |
|
2417 | if (data === false) {
|
2418 | return;
|
2419 | }
|
2420 |
|
2421 | if (!silent) {
|
2422 | this.$tableLoading.show();
|
2423 | }
|
2424 | var request = $.extend({}, Utils.calculateObjectValue(null, this.options.ajaxOptions), {
|
2425 | type: this.options.method,
|
2426 | url: url || this.options.url,
|
2427 | data: this.options.contentType === 'application/json' && this.options.method === 'post' ? JSON.stringify(data) : data,
|
2428 | cache: this.options.cache,
|
2429 | contentType: this.options.contentType,
|
2430 | dataType: this.options.dataType,
|
2431 | success: function success(_res) {
|
2432 | var res = Utils.calculateObjectValue(_this9.options, _this9.options.responseHandler, [_res], _res);
|
2433 |
|
2434 | _this9.load(res);
|
2435 | _this9.trigger('load-success', res);
|
2436 | if (!silent) {
|
2437 | _this9.$tableLoading.hide();
|
2438 | }
|
2439 | },
|
2440 | error: function error(jqXHR) {
|
2441 | var data = [];
|
2442 | if (_this9.options.sidePagination === 'server') {
|
2443 | data = {};
|
2444 | data[_this9.options.totalField] = 0;
|
2445 | data[_this9.options.dataField] = [];
|
2446 | }
|
2447 | _this9.load(data);
|
2448 | _this9.trigger('load-error', jqXHR.status, jqXHR);
|
2449 | if (!silent) _this9.$tableLoading.hide();
|
2450 | }
|
2451 | });
|
2452 |
|
2453 | if (this.options.ajax) {
|
2454 | Utils.calculateObjectValue(this, this.options.ajax, [request], null);
|
2455 | } else {
|
2456 | if (this._xhr && this._xhr.readyState !== 4) {
|
2457 | this._xhr.abort();
|
2458 | }
|
2459 | this._xhr = $.ajax(request);
|
2460 | }
|
2461 | }
|
2462 | }, {
|
2463 | key: 'initSearchText',
|
2464 | value: function initSearchText() {
|
2465 | if (this.options.search) {
|
2466 | this.searchText = '';
|
2467 | if (this.options.searchText !== '') {
|
2468 | var $search = this.$toolbar.find('.search input');
|
2469 | $search.val(this.options.searchText);
|
2470 | this.onSearch({ currentTarget: $search, firedByInitSearchText: true });
|
2471 | }
|
2472 | }
|
2473 | }
|
2474 | }, {
|
2475 | key: 'getCaret',
|
2476 | value: function getCaret() {
|
2477 | var _this10 = this;
|
2478 |
|
2479 | this.$header.find('th').each(function (i, th) {
|
2480 | $(th).find('.sortable').removeClass('desc asc').addClass($(th).data('field') === _this10.options.sortName ? _this10.options.sortOrder : 'both');
|
2481 | });
|
2482 | }
|
2483 | }, {
|
2484 | key: 'updateSelected',
|
2485 | value: function updateSelected() {
|
2486 | var checkAll = this.$selectItem.filter(':enabled').length && this.$selectItem.filter(':enabled').length === this.$selectItem.filter(':enabled').filter(':checked').length;
|
2487 |
|
2488 | this.$selectAll.add(this.$selectAll_).prop('checked', checkAll);
|
2489 |
|
2490 | this.$selectItem.each(function (i, el) {
|
2491 | $(el).closest('tr')[$(el).prop('checked') ? 'addClass' : 'removeClass']('selected');
|
2492 | });
|
2493 | }
|
2494 | }, {
|
2495 | key: 'updateRows',
|
2496 | value: function updateRows() {
|
2497 | var _this11 = this;
|
2498 |
|
2499 | this.$selectItem.each(function (i, el) {
|
2500 | _this11.data[$(el).data('index')][_this11.header.stateField] = $(el).prop('checked');
|
2501 | });
|
2502 | }
|
2503 | }, {
|
2504 | key: 'resetRows',
|
2505 | value: function resetRows() {
|
2506 | var _iteratorNormalCompletion16 = true;
|
2507 | var _didIteratorError16 = false;
|
2508 | var _iteratorError16 = undefined;
|
2509 |
|
2510 | try {
|
2511 | for (var _iterator16 = this.data[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
|
2512 | var row = _step16.value;
|
2513 |
|
2514 | this.$selectAll.prop('checked', false);
|
2515 | this.$selectItem.prop('checked', false);
|
2516 | if (this.header.stateField) {
|
2517 | row[this.header.stateField] = false;
|
2518 | }
|
2519 | }
|
2520 | } catch (err) {
|
2521 | _didIteratorError16 = true;
|
2522 | _iteratorError16 = err;
|
2523 | } finally {
|
2524 | try {
|
2525 | if (!_iteratorNormalCompletion16 && _iterator16.return) {
|
2526 | _iterator16.return();
|
2527 | }
|
2528 | } finally {
|
2529 | if (_didIteratorError16) {
|
2530 | throw _iteratorError16;
|
2531 | }
|
2532 | }
|
2533 | }
|
2534 |
|
2535 | this.initHiddenRows();
|
2536 | }
|
2537 | }, {
|
2538 | key: 'trigger',
|
2539 | value: function trigger(_name) {
|
2540 | var _options;
|
2541 |
|
2542 | var name = _name + '.bs.table';
|
2543 |
|
2544 | for (var _len2 = arguments.length, args = Array(_len2 > 1 ? _len2 - 1 : 0), _key4 = 1; _key4 < _len2; _key4++) {
|
2545 | args[_key4 - 1] = arguments[_key4];
|
2546 | }
|
2547 |
|
2548 | (_options = this.options)[BootstrapTable.EVENTS[name]].apply(_options, args);
|
2549 | this.$el.trigger($.Event(name), args);
|
2550 |
|
2551 | this.options.onAll(name, args);
|
2552 | this.$el.trigger($.Event('all.bs.table'), [name, args]);
|
2553 | }
|
2554 | }, {
|
2555 | key: 'resetHeader',
|
2556 | value: function resetHeader() {
|
2557 |
|
2558 |
|
2559 | clearTimeout(this.timeoutId_);
|
2560 | this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), this.$el.is(':hidden') ? 100 : 0);
|
2561 | }
|
2562 | }, {
|
2563 | key: 'fitHeader',
|
2564 | value: function fitHeader() {
|
2565 | var _this12 = this;
|
2566 |
|
2567 | if (this.$el.is(':hidden')) {
|
2568 | this.timeoutId_ = setTimeout($.proxy(this.fitHeader, this), 100);
|
2569 | return;
|
2570 | }
|
2571 | var fixedBody = this.$tableBody.get(0);
|
2572 |
|
2573 | var scrollWidth = fixedBody.scrollWidth > fixedBody.clientWidth && fixedBody.scrollHeight > fixedBody.clientHeight + this.$header.outerHeight() ? Utils.getScrollBarWidth() : 0;
|
2574 |
|
2575 | this.$el.css('margin-top', -this.$header.outerHeight());
|
2576 |
|
2577 | var focused = $(':focus');
|
2578 | if (focused.length > 0) {
|
2579 | var $th = focused.parents('th');
|
2580 | if ($th.length > 0) {
|
2581 | var dataField = $th.attr('data-field');
|
2582 | if (dataField !== undefined) {
|
2583 | var $headerTh = this.$header.find('[data-field=\'' + dataField + '\']');
|
2584 | if ($headerTh.length > 0) {
|
2585 | $headerTh.find(':input').addClass('focus-temp');
|
2586 | }
|
2587 | }
|
2588 | }
|
2589 | }
|
2590 |
|
2591 | this.$header_ = this.$header.clone(true, true);
|
2592 | this.$selectAll_ = this.$header_.find('[name="btSelectAll"]');
|
2593 | this.$tableHeader.css({
|
2594 | 'margin-right': scrollWidth
|
2595 | }).find('table').css('width', this.$el.outerWidth()).html('').attr('class', this.$el.attr('class')).append(this.$header_);
|
2596 |
|
2597 | var focusedTemp = $('.focus-temp:visible:eq(0)');
|
2598 | if (focusedTemp.length > 0) {
|
2599 | focusedTemp.focus();
|
2600 | this.$header.find('.focus-temp').removeClass('focus-temp');
|
2601 | }
|
2602 |
|
2603 |
|
2604 | this.$header.find('th[data-field]').each(function (i, el) {
|
2605 | _this12.$header_.find(Utils.sprintf('th[data-field="%s"]', $(el).data('field'))).data($(el).data());
|
2606 | });
|
2607 |
|
2608 | var visibleFields = this.getVisibleFields();
|
2609 | var $ths = this.$header_.find('th');
|
2610 | var $tr = this.$body.find('>tr:first-child:not(.no-records-found)');
|
2611 |
|
2612 | while ($tr.length && $tr.find('>td[colspan]:not([colspan="1"])').length) {
|
2613 | $tr = $tr.next();
|
2614 | }
|
2615 |
|
2616 | $tr.find('> *').each(function (i, el) {
|
2617 | var $this = $(el);
|
2618 | var index = i;
|
2619 |
|
2620 | if (_this12.options.detailView && !_this12.options.cardView) {
|
2621 | if (i === 0) {
|
2622 | var $thDetail = $ths.filter('.detail');
|
2623 | var _zoomWidth = $thDetail.width() - $thDetail.find('.fht-cell').width();
|
2624 | $thDetail.find('.fht-cell').width($this.innerWidth() - _zoomWidth);
|
2625 | }
|
2626 | index = i - 1;
|
2627 | }
|
2628 |
|
2629 | if (index === -1) {
|
2630 | return;
|
2631 | }
|
2632 |
|
2633 | var $th = _this12.$header_.find(Utils.sprintf('th[data-field="%s"]', visibleFields[index]));
|
2634 | if ($th.length > 1) {
|
2635 | $th = $($ths[$this[0].cellIndex]);
|
2636 | }
|
2637 |
|
2638 | var zoomWidth = $th.width() - $th.find('.fht-cell').width();
|
2639 | $th.find('.fht-cell').width($this.innerWidth() - zoomWidth);
|
2640 | });
|
2641 |
|
2642 | this.horizontalScroll();
|
2643 | this.trigger('post-header');
|
2644 | }
|
2645 | }, {
|
2646 | key: 'resetFooter',
|
2647 | value: function resetFooter() {
|
2648 | var data = this.getData();
|
2649 | var html = [];
|
2650 |
|
2651 | if (!this.options.showFooter || this.options.cardView) {
|
2652 |
|
2653 | return;
|
2654 | }
|
2655 |
|
2656 | if (!this.options.cardView && this.options.detailView) {
|
2657 | html.push('<td><div class="th-inner"> </div><div class="fht-cell"></div></td>');
|
2658 | }
|
2659 |
|
2660 | var _iteratorNormalCompletion17 = true;
|
2661 | var _didIteratorError17 = false;
|
2662 | var _iteratorError17 = undefined;
|
2663 |
|
2664 | try {
|
2665 | for (var _iterator17 = this.columns[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
|
2666 | var column = _step17.value;
|
2667 |
|
2668 | var falign = '';
|
2669 |
|
2670 | var valign = '';
|
2671 | var csses = [];
|
2672 | var style = {};
|
2673 | var class_ = Utils.sprintf(' class="%s"', column['class']);
|
2674 |
|
2675 | if (!column.visible) {
|
2676 | return;
|
2677 | }
|
2678 |
|
2679 | if (this.options.cardView && !column.cardVisible) {
|
2680 | return;
|
2681 | }
|
2682 |
|
2683 | falign = Utils.sprintf('text-align: %s; ', column.falign ? column.falign : column.align);
|
2684 | valign = Utils.sprintf('vertical-align: %s; ', column.valign);
|
2685 |
|
2686 | style = Utils.calculateObjectValue(null, this.options.footerStyle);
|
2687 |
|
2688 | if (style && style.css) {
|
2689 | var _iteratorNormalCompletion18 = true;
|
2690 | var _didIteratorError18 = false;
|
2691 | var _iteratorError18 = undefined;
|
2692 |
|
2693 | try {
|
2694 | for (var _iterator18 = Object.keys(style.css)[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {
|
2695 | var _ref23 = _step18.value;
|
2696 |
|
2697 | var _ref24 = _slicedToArray(_ref23, 2);
|
2698 |
|
2699 | var key = _ref24[0];
|
2700 | var value = _ref24[1];
|
2701 |
|
2702 | csses.push(key + ': ' + value);
|
2703 | }
|
2704 | } catch (err) {
|
2705 | _didIteratorError18 = true;
|
2706 | _iteratorError18 = err;
|
2707 | } finally {
|
2708 | try {
|
2709 | if (!_iteratorNormalCompletion18 && _iterator18.return) {
|
2710 | _iterator18.return();
|
2711 | }
|
2712 | } finally {
|
2713 | if (_didIteratorError18) {
|
2714 | throw _iteratorError18;
|
2715 | }
|
2716 | }
|
2717 | }
|
2718 | }
|
2719 |
|
2720 | html.push('<td', class_, Utils.sprintf(' style="%s"', falign + valign + csses.concat().join('; ')), '>');
|
2721 | html.push('<div class="th-inner">');
|
2722 |
|
2723 | html.push(Utils.calculateObjectValue(column, column.footerFormatter, [data], ' ') || ' ');
|
2724 |
|
2725 | html.push('</div>');
|
2726 | html.push('<div class="fht-cell"></div>');
|
2727 | html.push('</div>');
|
2728 | html.push('</td>');
|
2729 | }
|
2730 | } catch (err) {
|
2731 | _didIteratorError17 = true;
|
2732 | _iteratorError17 = err;
|
2733 | } finally {
|
2734 | try {
|
2735 | if (!_iteratorNormalCompletion17 && _iterator17.return) {
|
2736 | _iterator17.return();
|
2737 | }
|
2738 | } finally {
|
2739 | if (_didIteratorError17) {
|
2740 | throw _iteratorError17;
|
2741 | }
|
2742 | }
|
2743 | }
|
2744 |
|
2745 | this.$tableFooter.find('tr').html(html.join(''));
|
2746 | this.$tableFooter.show();
|
2747 | clearTimeout(this.timeoutFooter_);
|
2748 | this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), this.$el.is(':hidden') ? 100 : 0);
|
2749 | }
|
2750 | }, {
|
2751 | key: 'fitFooter',
|
2752 | value: function fitFooter() {
|
2753 | clearTimeout(this.timeoutFooter_);
|
2754 | if (this.$el.is(':hidden')) {
|
2755 | this.timeoutFooter_ = setTimeout($.proxy(this.fitFooter, this), 100);
|
2756 | return;
|
2757 | }
|
2758 |
|
2759 | var elWidth = this.$el.css('width');
|
2760 | var scrollWidth = elWidth > this.$tableBody.width() ? Utils.getScrollBarWidth() : 0;
|
2761 |
|
2762 | this.$tableFooter.css({
|
2763 | 'margin-right': scrollWidth
|
2764 | }).find('table').css('width', elWidth).attr('class', this.$el.attr('class'));
|
2765 |
|
2766 | var $footerTd = this.$tableFooter.find('td');
|
2767 |
|
2768 | this.$body.find('>tr:first-child:not(.no-records-found) > *').each(function (i, el) {
|
2769 | var $this = $(el);
|
2770 |
|
2771 | $footerTd.eq(i).find('.fht-cell').width($this.innerWidth());
|
2772 | });
|
2773 |
|
2774 | this.horizontalScroll();
|
2775 | }
|
2776 | }, {
|
2777 | key: 'horizontalScroll',
|
2778 | value: function horizontalScroll() {
|
2779 | var _this13 = this;
|
2780 |
|
2781 |
|
2782 |
|
2783 |
|
2784 | this.trigger('scroll-body');
|
2785 | this.$tableBody.off('scroll').on('scroll', function (_ref25) {
|
2786 | var currentTarget = _ref25.currentTarget;
|
2787 |
|
2788 | if (_this13.options.showHeader && _this13.options.height) {
|
2789 | _this13.$tableHeader.scrollLeft($(currentTarget).scrollLeft());
|
2790 | }
|
2791 |
|
2792 | if (_this13.options.showFooter && !_this13.options.cardView) {
|
2793 | _this13.$tableFooter.scrollLeft($(currentTarget).scrollLeft());
|
2794 | }
|
2795 | });
|
2796 | }
|
2797 | }, {
|
2798 | key: 'toggleColumn',
|
2799 | value: function toggleColumn(index, checked, needUpdate) {
|
2800 | if (index === -1) {
|
2801 | return;
|
2802 | }
|
2803 | this.columns[index].visible = checked;
|
2804 | this.initHeader();
|
2805 | this.initSearch();
|
2806 | this.initPagination();
|
2807 | this.initBody();
|
2808 |
|
2809 | if (this.options.showColumns) {
|
2810 | var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
|
2811 |
|
2812 | if (needUpdate) {
|
2813 | $items.filter(Utils.sprintf('[value="%s"]', index)).prop('checked', checked);
|
2814 | }
|
2815 |
|
2816 | if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
|
2817 | $items.filter(':checked').prop('disabled', true);
|
2818 | }
|
2819 | }
|
2820 | }
|
2821 | }, {
|
2822 | key: 'getVisibleFields',
|
2823 | value: function getVisibleFields() {
|
2824 | var visibleFields = [];
|
2825 |
|
2826 | var _iteratorNormalCompletion19 = true;
|
2827 | var _didIteratorError19 = false;
|
2828 | var _iteratorError19 = undefined;
|
2829 |
|
2830 | try {
|
2831 | for (var _iterator19 = this.header.fields[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {
|
2832 | var field = _step19.value;
|
2833 |
|
2834 | var column = this.columns[this.fieldsColumnsIndex[field]];
|
2835 |
|
2836 | if (!column.visible) {
|
2837 | continue;
|
2838 | }
|
2839 | visibleFields.push(field);
|
2840 | }
|
2841 | } catch (err) {
|
2842 | _didIteratorError19 = true;
|
2843 | _iteratorError19 = err;
|
2844 | } finally {
|
2845 | try {
|
2846 | if (!_iteratorNormalCompletion19 && _iterator19.return) {
|
2847 | _iterator19.return();
|
2848 | }
|
2849 | } finally {
|
2850 | if (_didIteratorError19) {
|
2851 | throw _iteratorError19;
|
2852 | }
|
2853 | }
|
2854 | }
|
2855 |
|
2856 | return visibleFields;
|
2857 | }
|
2858 | }, {
|
2859 | key: 'resetView',
|
2860 | value: function resetView(params) {
|
2861 | var padding = 0;
|
2862 |
|
2863 | if (params && params.height) {
|
2864 | this.options.height = params.height;
|
2865 | }
|
2866 |
|
2867 | this.$selectAll.prop('checked', this.$selectItem.length > 0 && this.$selectItem.length === this.$selectItem.filter(':checked').length);
|
2868 |
|
2869 | if (this.options.cardView) {
|
2870 |
|
2871 | this.$el.css('margin-top', '0');
|
2872 | this.$tableContainer.css('padding-bottom', '0');
|
2873 | this.$tableFooter.hide();
|
2874 | return;
|
2875 | }
|
2876 |
|
2877 | if (this.options.showHeader && this.options.height) {
|
2878 | this.$tableHeader.show();
|
2879 | this.resetHeader();
|
2880 | padding += this.$header.outerHeight();
|
2881 | } else {
|
2882 | this.$tableHeader.hide();
|
2883 | this.trigger('post-header');
|
2884 | }
|
2885 |
|
2886 | if (this.options.showFooter) {
|
2887 | this.resetFooter();
|
2888 | if (this.options.height) {
|
2889 | padding += this.$tableFooter.outerHeight() + 1;
|
2890 | }
|
2891 | }
|
2892 |
|
2893 | if (this.options.height) {
|
2894 | var toolbarHeight = this.$toolbar.outerHeight(true);
|
2895 | var paginationHeight = this.$pagination.outerHeight(true);
|
2896 | var height = this.options.height - toolbarHeight - paginationHeight;
|
2897 | var tableHeight = this.$tableBody.find('table').outerHeight(true);
|
2898 | this.$tableContainer.css('height', height + 'px');
|
2899 | this.$tableBorder && this.$tableBorder.css('height', height - tableHeight - padding - 1 + 'px');
|
2900 | }
|
2901 |
|
2902 |
|
2903 | this.getCaret();
|
2904 | this.$tableContainer.css('padding-bottom', padding + 'px');
|
2905 | this.trigger('reset-view');
|
2906 | }
|
2907 | }, {
|
2908 | key: 'getData',
|
2909 | value: function getData(useCurrentPage) {
|
2910 | var data = this.options.data;
|
2911 | if (this.searchText || this.options.sortName || !$.isEmptyObject(this.filterColumns) || !$.isEmptyObject(this.filterColumnsPartial)) {
|
2912 | data = this.data;
|
2913 | }
|
2914 |
|
2915 | if (useCurrentPage) {
|
2916 | return data.slice(this.pageFrom - 1, this.pageTo);
|
2917 | }
|
2918 |
|
2919 | return data;
|
2920 | }
|
2921 | }, {
|
2922 | key: 'load',
|
2923 | value: function load(_data) {
|
2924 | var fixedScroll = false;
|
2925 | var data = _data;
|
2926 |
|
2927 |
|
2928 | if (this.options.pagination && this.options.sidePagination === 'server') {
|
2929 | this.options.totalRows = data[this.options.totalField];
|
2930 | }
|
2931 |
|
2932 | fixedScroll = data.fixedScroll;
|
2933 | data = Array.isArray(data) ? data : data[this.options.dataField];
|
2934 |
|
2935 | this.initData(data);
|
2936 | this.initSearch();
|
2937 | this.initPagination();
|
2938 | this.initBody(fixedScroll);
|
2939 | }
|
2940 | }, {
|
2941 | key: 'append',
|
2942 | value: function append(data) {
|
2943 | this.initData(data, 'append');
|
2944 | this.initSearch();
|
2945 | this.initPagination();
|
2946 | this.initSort();
|
2947 | this.initBody(true);
|
2948 | }
|
2949 | }, {
|
2950 | key: 'prepend',
|
2951 | value: function prepend(data) {
|
2952 | this.initData(data, 'prepend');
|
2953 | this.initSearch();
|
2954 | this.initPagination();
|
2955 | this.initSort();
|
2956 | this.initBody(true);
|
2957 | }
|
2958 | }, {
|
2959 | key: 'remove',
|
2960 | value: function remove(params) {
|
2961 | var len = this.options.data.length;
|
2962 | var i = void 0;
|
2963 | var row = void 0;
|
2964 |
|
2965 | if (!params.hasOwnProperty('field') || !params.hasOwnProperty('values')) {
|
2966 | return;
|
2967 | }
|
2968 |
|
2969 | for (i = len - 1; i >= 0; i--) {
|
2970 | row = this.options.data[i];
|
2971 |
|
2972 | if (!row.hasOwnProperty(params.field)) {
|
2973 | continue;
|
2974 | }
|
2975 | if (params.values.includes(row[params.field])) {
|
2976 | this.options.data.splice(i, 1);
|
2977 | if (this.options.sidePagination === 'server') {
|
2978 | this.options.totalRows -= 1;
|
2979 | }
|
2980 | }
|
2981 | }
|
2982 |
|
2983 | if (len === this.options.data.length) {
|
2984 | return;
|
2985 | }
|
2986 |
|
2987 | this.initSearch();
|
2988 | this.initPagination();
|
2989 | this.initSort();
|
2990 | this.initBody(true);
|
2991 | }
|
2992 | }, {
|
2993 | key: 'removeAll',
|
2994 | value: function removeAll() {
|
2995 | if (this.options.data.length > 0) {
|
2996 | this.options.data.splice(0, this.options.data.length);
|
2997 | this.initSearch();
|
2998 | this.initPagination();
|
2999 | this.initBody(true);
|
3000 | }
|
3001 | }
|
3002 | }, {
|
3003 | key: 'getRowByUniqueId',
|
3004 | value: function getRowByUniqueId(_id) {
|
3005 | var uniqueId = this.options.uniqueId;
|
3006 | var len = this.options.data.length;
|
3007 | var id = _id;
|
3008 | var dataRow = null;
|
3009 | var i = void 0;
|
3010 | var row = void 0;
|
3011 | var rowUniqueId = void 0;
|
3012 |
|
3013 | for (i = len - 1; i >= 0; i--) {
|
3014 | row = this.options.data[i];
|
3015 |
|
3016 | if (row.hasOwnProperty(uniqueId)) {
|
3017 |
|
3018 | rowUniqueId = row[uniqueId];
|
3019 | } else if (row._data && row._data.hasOwnProperty(uniqueId)) {
|
3020 |
|
3021 | rowUniqueId = row._data[uniqueId];
|
3022 | } else {
|
3023 | continue;
|
3024 | }
|
3025 |
|
3026 | if (typeof rowUniqueId === 'string') {
|
3027 | id = id.toString();
|
3028 | } else if (typeof rowUniqueId === 'number') {
|
3029 | if (Number(rowUniqueId) === rowUniqueId && rowUniqueId % 1 === 0) {
|
3030 | id = parseInt(id);
|
3031 | } else if (rowUniqueId === Number(rowUniqueId) && rowUniqueId !== 0) {
|
3032 | id = parseFloat(id);
|
3033 | }
|
3034 | }
|
3035 |
|
3036 | if (rowUniqueId === id) {
|
3037 | dataRow = row;
|
3038 | break;
|
3039 | }
|
3040 | }
|
3041 |
|
3042 | return dataRow;
|
3043 | }
|
3044 | }, {
|
3045 | key: 'removeByUniqueId',
|
3046 | value: function removeByUniqueId(id) {
|
3047 | var len = this.options.data.length;
|
3048 | var row = this.getRowByUniqueId(id);
|
3049 |
|
3050 | if (row) {
|
3051 | this.options.data.splice(this.options.data.indexOf(row), 1);
|
3052 | }
|
3053 |
|
3054 | if (len === this.options.data.length) {
|
3055 | return;
|
3056 | }
|
3057 |
|
3058 | this.initSearch();
|
3059 | this.initPagination();
|
3060 | this.initBody(true);
|
3061 | }
|
3062 | }, {
|
3063 | key: 'updateByUniqueId',
|
3064 | value: function updateByUniqueId(params) {
|
3065 | var allParams = Array.isArray(params) ? params : [params];
|
3066 |
|
3067 | var _iteratorNormalCompletion20 = true;
|
3068 | var _didIteratorError20 = false;
|
3069 | var _iteratorError20 = undefined;
|
3070 |
|
3071 | try {
|
3072 | for (var _iterator20 = allParams[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {
|
3073 | var _params = _step20.value;
|
3074 |
|
3075 | if (!_params.hasOwnProperty('id') || !_params.hasOwnProperty('row')) {
|
3076 | continue;
|
3077 | }
|
3078 |
|
3079 | var rowId = this.options.data.indexOf(this.getRowByUniqueId(_params.id));
|
3080 |
|
3081 | if (rowId === -1) {
|
3082 | continue;
|
3083 | }
|
3084 | $.extend(this.options.data[rowId], _params.row);
|
3085 | }
|
3086 | } catch (err) {
|
3087 | _didIteratorError20 = true;
|
3088 | _iteratorError20 = err;
|
3089 | } finally {
|
3090 | try {
|
3091 | if (!_iteratorNormalCompletion20 && _iterator20.return) {
|
3092 | _iterator20.return();
|
3093 | }
|
3094 | } finally {
|
3095 | if (_didIteratorError20) {
|
3096 | throw _iteratorError20;
|
3097 | }
|
3098 | }
|
3099 | }
|
3100 |
|
3101 | this.initSearch();
|
3102 | this.initPagination();
|
3103 | this.initSort();
|
3104 | this.initBody(true);
|
3105 | }
|
3106 | }, {
|
3107 | key: 'refreshColumnTitle',
|
3108 | value: function refreshColumnTitle(params) {
|
3109 | if (!params.hasOwnProperty('field') || !params.hasOwnProperty('title')) {
|
3110 | return;
|
3111 | }
|
3112 |
|
3113 | this.columns[this.fieldsColumnsIndex[params.field]].title = this.options.escape ? Utils.escapeHTML(params.title) : params.title;
|
3114 |
|
3115 | if (this.columns[this.fieldsColumnsIndex[params.field]].visible) {
|
3116 | var header = this.options.height !== undefined ? this.$tableHeader : this.$header;
|
3117 | header.find('th[data-field]').each(function (i, el) {
|
3118 | if ($(el).data('field') === params.field) {
|
3119 | $($(el).find('.th-inner')[0]).text(params.title);
|
3120 | return false;
|
3121 | }
|
3122 | });
|
3123 | }
|
3124 | }
|
3125 | }, {
|
3126 | key: 'insertRow',
|
3127 | value: function insertRow(params) {
|
3128 | if (!params.hasOwnProperty('index') || !params.hasOwnProperty('row')) {
|
3129 | return;
|
3130 | }
|
3131 | this.options.data.splice(params.index, 0, params.row);
|
3132 | this.initSearch();
|
3133 | this.initPagination();
|
3134 | this.initSort();
|
3135 | this.initBody(true);
|
3136 | }
|
3137 | }, {
|
3138 | key: 'updateRow',
|
3139 | value: function updateRow(params) {
|
3140 | var allParams = Array.isArray(params) ? params : [params];
|
3141 |
|
3142 | var _iteratorNormalCompletion21 = true;
|
3143 | var _didIteratorError21 = false;
|
3144 | var _iteratorError21 = undefined;
|
3145 |
|
3146 | try {
|
3147 | for (var _iterator21 = allParams[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {
|
3148 | var _params2 = _step21.value;
|
3149 |
|
3150 | if (!_params2.hasOwnProperty('index') || !_params2.hasOwnProperty('row')) {
|
3151 | continue;
|
3152 | }
|
3153 | $.extend(this.options.data[_params2.index], _params2.row);
|
3154 | }
|
3155 | } catch (err) {
|
3156 | _didIteratorError21 = true;
|
3157 | _iteratorError21 = err;
|
3158 | } finally {
|
3159 | try {
|
3160 | if (!_iteratorNormalCompletion21 && _iterator21.return) {
|
3161 | _iterator21.return();
|
3162 | }
|
3163 | } finally {
|
3164 | if (_didIteratorError21) {
|
3165 | throw _iteratorError21;
|
3166 | }
|
3167 | }
|
3168 | }
|
3169 |
|
3170 | this.initSearch();
|
3171 | this.initPagination();
|
3172 | this.initSort();
|
3173 | this.initBody(true);
|
3174 | }
|
3175 | }, {
|
3176 | key: 'initHiddenRows',
|
3177 | value: function initHiddenRows() {
|
3178 | this.hiddenRows = [];
|
3179 | }
|
3180 | }, {
|
3181 | key: 'showRow',
|
3182 | value: function showRow(params) {
|
3183 | this.toggleRow(params, true);
|
3184 | }
|
3185 | }, {
|
3186 | key: 'hideRow',
|
3187 | value: function hideRow(params) {
|
3188 | this.toggleRow(params, false);
|
3189 | }
|
3190 | }, {
|
3191 | key: 'toggleRow',
|
3192 | value: function toggleRow(params, visible) {
|
3193 | var row = void 0;
|
3194 |
|
3195 | if (params.hasOwnProperty('index')) {
|
3196 | row = this.getData()[params.index];
|
3197 | } else if (params.hasOwnProperty('uniqueId')) {
|
3198 | row = this.getRowByUniqueId(params.uniqueId);
|
3199 | }
|
3200 |
|
3201 | if (!row) {
|
3202 | return;
|
3203 | }
|
3204 |
|
3205 | var index = Utils.findIndex(this.hiddenRows, row);
|
3206 |
|
3207 | if (!visible && index === -1) {
|
3208 | this.hiddenRows.push(row);
|
3209 | } else if (visible && index > -1) {
|
3210 | this.hiddenRows.splice(index, 1);
|
3211 | }
|
3212 | this.initBody(true);
|
3213 | }
|
3214 | }, {
|
3215 | key: 'getHiddenRows',
|
3216 | value: function getHiddenRows(show) {
|
3217 | if (show) {
|
3218 | this.initHiddenRows();
|
3219 | this.initBody(true);
|
3220 | return;
|
3221 | }
|
3222 | var data = this.getData();
|
3223 | var rows = [];
|
3224 |
|
3225 | var _iteratorNormalCompletion22 = true;
|
3226 | var _didIteratorError22 = false;
|
3227 | var _iteratorError22 = undefined;
|
3228 |
|
3229 | try {
|
3230 | for (var _iterator22 = data[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {
|
3231 | var row = _step22.value;
|
3232 |
|
3233 | if (this.hiddenRows.includes(row)) {
|
3234 | rows.push(row);
|
3235 | }
|
3236 | }
|
3237 | } catch (err) {
|
3238 | _didIteratorError22 = true;
|
3239 | _iteratorError22 = err;
|
3240 | } finally {
|
3241 | try {
|
3242 | if (!_iteratorNormalCompletion22 && _iterator22.return) {
|
3243 | _iterator22.return();
|
3244 | }
|
3245 | } finally {
|
3246 | if (_didIteratorError22) {
|
3247 | throw _iteratorError22;
|
3248 | }
|
3249 | }
|
3250 | }
|
3251 |
|
3252 | this.hiddenRows = rows;
|
3253 | return rows;
|
3254 | }
|
3255 | }, {
|
3256 | key: 'mergeCells',
|
3257 | value: function mergeCells(options) {
|
3258 | var row = options.index;
|
3259 | var col = this.getVisibleFields().indexOf(options.field);
|
3260 | var rowspan = options.rowspan || 1;
|
3261 | var colspan = options.colspan || 1;
|
3262 | var i = void 0;
|
3263 | var j = void 0;
|
3264 | var $tr = this.$body.find('>tr');
|
3265 |
|
3266 | if (this.options.detailView && !this.options.cardView) {
|
3267 | col += 1;
|
3268 | }
|
3269 |
|
3270 | var $td = $tr.eq(row).find('>td').eq(col);
|
3271 |
|
3272 | if (row < 0 || col < 0 || row >= this.data.length) {
|
3273 | return;
|
3274 | }
|
3275 |
|
3276 | for (i = row; i < row + rowspan; i++) {
|
3277 | for (j = col; j < col + colspan; j++) {
|
3278 | $tr.eq(i).find('>td').eq(j).hide();
|
3279 | }
|
3280 | }
|
3281 |
|
3282 | $td.attr('rowspan', rowspan).attr('colspan', colspan).show();
|
3283 | }
|
3284 | }, {
|
3285 | key: 'updateCell',
|
3286 | value: function updateCell(params) {
|
3287 | if (!params.hasOwnProperty('index') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) {
|
3288 | return;
|
3289 | }
|
3290 | this.data[params.index][params.field] = params.value;
|
3291 |
|
3292 | if (params.reinit === false) {
|
3293 | return;
|
3294 | }
|
3295 | this.initSort();
|
3296 | this.initBody(true);
|
3297 | }
|
3298 | }, {
|
3299 | key: 'updateCellById',
|
3300 | value: function updateCellById(params) {
|
3301 | var _this14 = this;
|
3302 |
|
3303 | if (!params.hasOwnProperty('id') || !params.hasOwnProperty('field') || !params.hasOwnProperty('value')) {
|
3304 | return;
|
3305 | }
|
3306 | var allParams = Array.isArray(params) ? params : [params];
|
3307 |
|
3308 | allParams.forEach(function (_ref26) {
|
3309 | var id = _ref26.id,
|
3310 | field = _ref26.field,
|
3311 | value = _ref26.value;
|
3312 |
|
3313 | var rowId = _this14.options.data.indexOf(_this14.getRowByUniqueId(id));
|
3314 |
|
3315 | if (rowId === -1) {
|
3316 | return;
|
3317 | }
|
3318 | _this14.data[rowId][field] = value;
|
3319 | });
|
3320 |
|
3321 | if (params.reinit === false) {
|
3322 | return;
|
3323 | }
|
3324 | this.initSort();
|
3325 | this.initBody(true);
|
3326 | }
|
3327 | }, {
|
3328 | key: 'getOptions',
|
3329 | value: function getOptions() {
|
3330 |
|
3331 | var options = $.extend({}, this.options);
|
3332 | delete options.data;
|
3333 | return $.extend(true, {}, options);
|
3334 | }
|
3335 | }, {
|
3336 | key: 'getSelections',
|
3337 | value: function getSelections() {
|
3338 | var _this15 = this;
|
3339 |
|
3340 |
|
3341 | return this.options.data.filter(function (row) {
|
3342 | return row[_this15.header.stateField] === true;
|
3343 | });
|
3344 | }
|
3345 | }, {
|
3346 | key: 'getAllSelections',
|
3347 | value: function getAllSelections() {
|
3348 | var _this16 = this;
|
3349 |
|
3350 | return this.options.data.filter(function (row) {
|
3351 | return row[_this16.header.stateField];
|
3352 | });
|
3353 | }
|
3354 | }, {
|
3355 | key: 'checkAll',
|
3356 | value: function checkAll() {
|
3357 | this.checkAll_(true);
|
3358 | }
|
3359 | }, {
|
3360 | key: 'uncheckAll',
|
3361 | value: function uncheckAll() {
|
3362 | this.checkAll_(false);
|
3363 | }
|
3364 | }, {
|
3365 | key: 'checkInvert',
|
3366 | value: function checkInvert() {
|
3367 | var $items = this.$selectItem.filter(':enabled');
|
3368 | var checked = $items.filter(':checked');
|
3369 | $items.each(function (i, el) {
|
3370 | $(el).prop('checked', !$(el).prop('checked'));
|
3371 | });
|
3372 | this.updateRows();
|
3373 | this.updateSelected();
|
3374 | this.trigger('uncheck-some', checked);
|
3375 | checked = this.getSelections();
|
3376 | this.trigger('check-some', checked);
|
3377 | }
|
3378 | }, {
|
3379 | key: 'checkAll_',
|
3380 | value: function checkAll_(checked) {
|
3381 | var rows = void 0;
|
3382 | if (!checked) {
|
3383 | rows = this.getSelections();
|
3384 | }
|
3385 | this.$selectAll.add(this.$selectAll_).prop('checked', checked);
|
3386 | this.$selectItem.filter(':enabled').prop('checked', checked);
|
3387 | this.updateRows();
|
3388 | if (checked) {
|
3389 | rows = this.getSelections();
|
3390 | }
|
3391 | this.trigger(checked ? 'check-all' : 'uncheck-all', rows);
|
3392 | }
|
3393 | }, {
|
3394 | key: 'check',
|
3395 | value: function check(index) {
|
3396 | this.check_(true, index);
|
3397 | }
|
3398 | }, {
|
3399 | key: 'uncheck',
|
3400 | value: function uncheck(index) {
|
3401 | this.check_(false, index);
|
3402 | }
|
3403 | }, {
|
3404 | key: 'check_',
|
3405 | value: function check_(checked, index) {
|
3406 | var $el = this.$selectItem.filter('[data-index="' + index + '"]');
|
3407 | var row = this.data[index];
|
3408 |
|
3409 | if ($el.is(':radio') || this.options.singleSelect) {
|
3410 | var _iteratorNormalCompletion23 = true;
|
3411 | var _didIteratorError23 = false;
|
3412 | var _iteratorError23 = undefined;
|
3413 |
|
3414 | try {
|
3415 | for (var _iterator23 = this.options.data[Symbol.iterator](), _step23; !(_iteratorNormalCompletion23 = (_step23 = _iterator23.next()).done); _iteratorNormalCompletion23 = true) {
|
3416 | var r = _step23.value;
|
3417 |
|
3418 | r[this.header.stateField] = false;
|
3419 | }
|
3420 | } catch (err) {
|
3421 | _didIteratorError23 = true;
|
3422 | _iteratorError23 = err;
|
3423 | } finally {
|
3424 | try {
|
3425 | if (!_iteratorNormalCompletion23 && _iterator23.return) {
|
3426 | _iterator23.return();
|
3427 | }
|
3428 | } finally {
|
3429 | if (_didIteratorError23) {
|
3430 | throw _iteratorError23;
|
3431 | }
|
3432 | }
|
3433 | }
|
3434 |
|
3435 | this.$selectItem.filter(':checked').not($el).prop('checked', false);
|
3436 | }
|
3437 |
|
3438 | row[this.header.stateField] = checked;
|
3439 | $el.prop('checked', checked);
|
3440 | this.updateSelected();
|
3441 | this.trigger(checked ? 'check' : 'uncheck', this.data[index], $el);
|
3442 | }
|
3443 | }, {
|
3444 | key: 'checkBy',
|
3445 | value: function checkBy(obj) {
|
3446 | this.checkBy_(true, obj);
|
3447 | }
|
3448 | }, {
|
3449 | key: 'uncheckBy',
|
3450 | value: function uncheckBy(obj) {
|
3451 | this.checkBy_(false, obj);
|
3452 | }
|
3453 | }, {
|
3454 | key: 'checkBy_',
|
3455 | value: function checkBy_(checked, obj) {
|
3456 | var _this17 = this;
|
3457 |
|
3458 | if (!obj.hasOwnProperty('field') || !obj.hasOwnProperty('values')) {
|
3459 | return;
|
3460 | }
|
3461 |
|
3462 | var rows = [];
|
3463 | this.options.data.forEach(function (row, i) {
|
3464 | if (!row.hasOwnProperty(obj.field)) {
|
3465 | return false;
|
3466 | }
|
3467 | if (obj.values.includes(row[obj.field])) {
|
3468 | var $el = _this17.$selectItem.filter(':enabled').filter(Utils.sprintf('[data-index="%s"]', i)).prop('checked', checked);
|
3469 | row[_this17.header.stateField] = checked;
|
3470 | rows.push(row);
|
3471 | _this17.trigger(checked ? 'check' : 'uncheck', row, $el);
|
3472 | }
|
3473 | });
|
3474 | this.updateSelected();
|
3475 | this.trigger(checked ? 'check-some' : 'uncheck-some', rows);
|
3476 | }
|
3477 | }, {
|
3478 | key: 'destroy',
|
3479 | value: function destroy() {
|
3480 | this.$el.insertBefore(this.$container);
|
3481 | $(this.options.toolbar).insertBefore(this.$el);
|
3482 | this.$container.next().remove();
|
3483 | this.$container.remove();
|
3484 | this.$el.html(this.$el_.html()).css('margin-top', '0').attr('class', this.$el_.attr('class') || '');
|
3485 | }
|
3486 | }, {
|
3487 | key: 'showLoading',
|
3488 | value: function showLoading() {
|
3489 | this.$tableLoading.show();
|
3490 | }
|
3491 | }, {
|
3492 | key: 'hideLoading',
|
3493 | value: function hideLoading() {
|
3494 | this.$tableLoading.hide();
|
3495 | }
|
3496 | }, {
|
3497 | key: 'togglePagination',
|
3498 | value: function togglePagination() {
|
3499 | this.options.pagination = !this.options.pagination;
|
3500 | var button = this.$toolbar.find('button[name="paginationSwitch"] i');
|
3501 | if (this.options.pagination) {
|
3502 | button.attr('class', this.options.iconsPrefix + ' ' + this.options.icons.paginationSwitchDown);
|
3503 | } else {
|
3504 | button.attr('class', this.options.iconsPrefix + ' ' + this.options.icons.paginationSwitchUp);
|
3505 | }
|
3506 | this.updatePagination();
|
3507 | }
|
3508 | }, {
|
3509 | key: 'toggleFullscreen',
|
3510 | value: function toggleFullscreen() {
|
3511 | this.$el.closest('.bootstrap-table').toggleClass('fullscreen');
|
3512 | }
|
3513 | }, {
|
3514 | key: 'refresh',
|
3515 | value: function refresh(params) {
|
3516 | if (params && params.url) {
|
3517 | this.options.url = params.url;
|
3518 | }
|
3519 | if (params && params.pageNumber) {
|
3520 | this.options.pageNumber = params.pageNumber;
|
3521 | }
|
3522 | if (params && params.pageSize) {
|
3523 | this.options.pageSize = params.pageSize;
|
3524 | }
|
3525 | this.initServer(params && params.silent, params && params.query, params && params.url);
|
3526 | this.trigger('refresh', params);
|
3527 | }
|
3528 | }, {
|
3529 | key: 'resetWidth',
|
3530 | value: function resetWidth() {
|
3531 | if (this.options.showHeader && this.options.height) {
|
3532 | this.fitHeader();
|
3533 | }
|
3534 | if (this.options.showFooter && !this.options.cardView) {
|
3535 | this.fitFooter();
|
3536 | }
|
3537 | }
|
3538 | }, {
|
3539 | key: 'showColumn',
|
3540 | value: function showColumn(field) {
|
3541 | this.toggleColumn(this.fieldsColumnsIndex[field], true, true);
|
3542 | }
|
3543 | }, {
|
3544 | key: 'hideColumn',
|
3545 | value: function hideColumn(field) {
|
3546 | this.toggleColumn(this.fieldsColumnsIndex[field], false, true);
|
3547 | }
|
3548 | }, {
|
3549 | key: 'getHiddenColumns',
|
3550 | value: function getHiddenColumns() {
|
3551 | return this.columns.filter(function (_ref27) {
|
3552 | var visible = _ref27.visible;
|
3553 | return !visible;
|
3554 | });
|
3555 | }
|
3556 | }, {
|
3557 | key: 'getVisibleColumns',
|
3558 | value: function getVisibleColumns() {
|
3559 | return this.columns.filter(function (_ref28) {
|
3560 | var visible = _ref28.visible;
|
3561 | return visible;
|
3562 | });
|
3563 | }
|
3564 | }, {
|
3565 | key: 'toggleAllColumns',
|
3566 | value: function toggleAllColumns(visible) {
|
3567 | var _iteratorNormalCompletion24 = true;
|
3568 | var _didIteratorError24 = false;
|
3569 | var _iteratorError24 = undefined;
|
3570 |
|
3571 | try {
|
3572 | for (var _iterator24 = this.columns[Symbol.iterator](), _step24; !(_iteratorNormalCompletion24 = (_step24 = _iterator24.next()).done); _iteratorNormalCompletion24 = true) {
|
3573 | var column = _step24.value;
|
3574 |
|
3575 | column.visible = visible;
|
3576 | }
|
3577 | } catch (err) {
|
3578 | _didIteratorError24 = true;
|
3579 | _iteratorError24 = err;
|
3580 | } finally {
|
3581 | try {
|
3582 | if (!_iteratorNormalCompletion24 && _iterator24.return) {
|
3583 | _iterator24.return();
|
3584 | }
|
3585 | } finally {
|
3586 | if (_didIteratorError24) {
|
3587 | throw _iteratorError24;
|
3588 | }
|
3589 | }
|
3590 | }
|
3591 |
|
3592 | this.initHeader();
|
3593 | this.initSearch();
|
3594 | this.initPagination();
|
3595 | this.initBody();
|
3596 | if (this.options.showColumns) {
|
3597 | var $items = this.$toolbar.find('.keep-open input').prop('disabled', false);
|
3598 |
|
3599 | if ($items.filter(':checked').length <= this.options.minimumCountColumns) {
|
3600 | $items.filter(':checked').prop('disabled', true);
|
3601 | }
|
3602 | }
|
3603 | }
|
3604 | }, {
|
3605 | key: 'showAllColumns',
|
3606 | value: function showAllColumns() {
|
3607 | this.toggleAllColumns(true);
|
3608 | }
|
3609 | }, {
|
3610 | key: 'hideAllColumns',
|
3611 | value: function hideAllColumns() {
|
3612 | this.toggleAllColumns(false);
|
3613 | }
|
3614 | }, {
|
3615 | key: 'filterBy',
|
3616 | value: function filterBy(columns) {
|
3617 | this.filterColumns = $.isEmptyObject(columns) ? {} : columns;
|
3618 | this.options.pageNumber = 1;
|
3619 | this.initSearch();
|
3620 | this.updatePagination();
|
3621 | }
|
3622 | }, {
|
3623 | key: 'scrollTo',
|
3624 | value: function scrollTo(_value) {
|
3625 | if (typeof _value === 'undefined') {
|
3626 | return this.$tableBody.scrollTop();
|
3627 | }
|
3628 |
|
3629 | var value = _value;
|
3630 | if (typeof _value === 'string' && _value === 'bottom') {
|
3631 | value = this.$tableBody[0].scrollHeight;
|
3632 | }
|
3633 | this.$tableBody.scrollTop(value);
|
3634 | }
|
3635 | }, {
|
3636 | key: 'getScrollPosition',
|
3637 | value: function getScrollPosition() {
|
3638 | return this.scrollTo();
|
3639 | }
|
3640 | }, {
|
3641 | key: 'selectPage',
|
3642 | value: function selectPage(page) {
|
3643 | if (page > 0 && page <= this.options.totalPages) {
|
3644 | this.options.pageNumber = page;
|
3645 | this.updatePagination();
|
3646 | }
|
3647 | }
|
3648 | }, {
|
3649 | key: 'prevPage',
|
3650 | value: function prevPage() {
|
3651 | if (this.options.pageNumber > 1) {
|
3652 | this.options.pageNumber--;
|
3653 | this.updatePagination();
|
3654 | }
|
3655 | }
|
3656 | }, {
|
3657 | key: 'nextPage',
|
3658 | value: function nextPage() {
|
3659 | if (this.options.pageNumber < this.options.totalPages) {
|
3660 | this.options.pageNumber++;
|
3661 | this.updatePagination();
|
3662 | }
|
3663 | }
|
3664 | }, {
|
3665 | key: 'toggleView',
|
3666 | value: function toggleView() {
|
3667 | this.options.cardView = !this.options.cardView;
|
3668 | this.initHeader();
|
3669 |
|
3670 |
|
3671 | var $icon = this.$toolbar.find('button[name="toggle"] i');
|
3672 | if (this.options.cardView) {
|
3673 | $icon.removeClass(this.options.icons.toggleOff);
|
3674 | $icon.addClass(this.options.icons.toggleOn);
|
3675 | } else {
|
3676 | $icon.removeClass(this.options.icons.toggleOn);
|
3677 | $icon.addClass(this.options.icons.toggleOff);
|
3678 | }
|
3679 | this.initBody();
|
3680 | this.trigger('toggle', this.options.cardView);
|
3681 | }
|
3682 | }, {
|
3683 | key: 'refreshOptions',
|
3684 | value: function refreshOptions(options) {
|
3685 |
|
3686 | if (Utils.compareObjects(this.options, options, true)) {
|
3687 | return;
|
3688 | }
|
3689 | this.options = $.extend(this.options, options);
|
3690 | this.trigger('refresh-options', this.options);
|
3691 | this.destroy();
|
3692 | this.init();
|
3693 | }
|
3694 | }, {
|
3695 | key: 'resetSearch',
|
3696 | value: function resetSearch(text) {
|
3697 | var $search = this.$toolbar.find('.search input');
|
3698 | $search.val(text || '');
|
3699 | this.onSearch({ currentTarget: $search });
|
3700 | }
|
3701 | }, {
|
3702 | key: 'expandRow_',
|
3703 | value: function expandRow_(expand, index) {
|
3704 | var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', index));
|
3705 | if ($tr.next().is('tr.detail-view') === !expand) {
|
3706 | $tr.find('> td > .detail-icon').click();
|
3707 | }
|
3708 | }
|
3709 | }, {
|
3710 | key: 'expandRow',
|
3711 | value: function expandRow(index) {
|
3712 | this.expandRow_(true, index);
|
3713 | }
|
3714 | }, {
|
3715 | key: 'collapseRow',
|
3716 | value: function collapseRow(index) {
|
3717 | this.expandRow_(false, index);
|
3718 | }
|
3719 | }, {
|
3720 | key: 'expandAllRows',
|
3721 | value: function expandAllRows(isSubTable) {
|
3722 | var _this18 = this;
|
3723 |
|
3724 | if (isSubTable) {
|
3725 | var $tr = this.$body.find(Utils.sprintf('> tr[data-index="%s"]', 0));
|
3726 | var detailIcon = null;
|
3727 | var executeInterval = false;
|
3728 | var idInterval = -1;
|
3729 |
|
3730 | if (!$tr.next().is('tr.detail-view')) {
|
3731 | $tr.find('> td > .detail-icon').click();
|
3732 | executeInterval = true;
|
3733 | } else if (!$tr.next().next().is('tr.detail-view')) {
|
3734 | $tr.next().find('.detail-icon').click();
|
3735 | executeInterval = true;
|
3736 | }
|
3737 |
|
3738 | if (executeInterval) {
|
3739 | try {
|
3740 | idInterval = setInterval(function () {
|
3741 | detailIcon = _this18.$body.find('tr.detail-view').last().find('.detail-icon');
|
3742 | if (detailIcon.length > 0) {
|
3743 | detailIcon.click();
|
3744 | } else {
|
3745 | clearInterval(idInterval);
|
3746 | }
|
3747 | }, 1);
|
3748 | } catch (ex) {
|
3749 | clearInterval(idInterval);
|
3750 | }
|
3751 | }
|
3752 | } else {
|
3753 | var trs = this.$body.children();
|
3754 | for (var i = 0; i < trs.length; i++) {
|
3755 | this.expandRow_(true, $(trs[i]).data('index'));
|
3756 | }
|
3757 | }
|
3758 | }
|
3759 | }, {
|
3760 | key: 'collapseAllRows',
|
3761 | value: function collapseAllRows(isSubTable) {
|
3762 | if (isSubTable) {
|
3763 | this.expandRow_(false, 0);
|
3764 | } else {
|
3765 | var trs = this.$body.children();
|
3766 | for (var i = 0; i < trs.length; i++) {
|
3767 | this.expandRow_(false, $(trs[i]).data('index'));
|
3768 | }
|
3769 | }
|
3770 | }
|
3771 | }, {
|
3772 | key: 'updateFormatText',
|
3773 | value: function updateFormatText(name, text) {
|
3774 | if (this.options[Utils.sprintf('format%s', name)]) {
|
3775 | if (typeof text === 'string') {
|
3776 | this.options[Utils.sprintf('format%s', name)] = function () {
|
3777 | return text;
|
3778 | };
|
3779 | } else if (typeof text === 'function') {
|
3780 | this.options[Utils.sprintf('format%s', name)] = text;
|
3781 | }
|
3782 | }
|
3783 | this.initToolbar();
|
3784 | this.initPagination();
|
3785 | this.initBody();
|
3786 | }
|
3787 | }]);
|
3788 |
|
3789 | return BootstrapTable;
|
3790 | }();
|
3791 |
|
3792 | BootstrapTable.DEFAULTS = DEFAULTS;
|
3793 | BootstrapTable.LOCALES = LOCALES;
|
3794 | BootstrapTable.COLUMN_DEFAULTS = COLUMN_DEFAULTS;
|
3795 | BootstrapTable.EVENTS = EVENTS;
|
3796 |
|
3797 |
|
3798 |
|
3799 |
|
3800 | var allowedMethods = ['getOptions', 'getSelections', 'getAllSelections', 'getData', 'load', 'append', 'prepend', 'remove', 'removeAll', 'insertRow', 'updateRow', 'updateCell', 'updateByUniqueId', 'removeByUniqueId', 'getRowByUniqueId', 'showRow', 'hideRow', 'getHiddenRows', 'mergeCells', 'refreshColumnTitle', 'checkAll', 'uncheckAll', 'checkInvert', 'check', 'uncheck', 'checkBy', 'uncheckBy', 'refresh', 'resetView', 'resetWidth', 'destroy', 'showLoading', 'hideLoading', 'showColumn', 'hideColumn', 'getHiddenColumns', 'getVisibleColumns', 'showAllColumns', 'hideAllColumns', 'filterBy', 'scrollTo', 'getScrollPosition', 'selectPage', 'prevPage', 'nextPage', 'togglePagination', 'toggleView', 'refreshOptions', 'resetSearch', 'expandRow', 'collapseRow', 'expandAllRows', 'collapseAllRows', 'updateFormatText', 'updateCellById'];
|
3801 |
|
3802 | $.BootstrapTable = BootstrapTable;
|
3803 | $.fn.bootstrapTable = function (option) {
|
3804 | for (var _len3 = arguments.length, args = Array(_len3 > 1 ? _len3 - 1 : 0), _key5 = 1; _key5 < _len3; _key5++) {
|
3805 | args[_key5 - 1] = arguments[_key5];
|
3806 | }
|
3807 |
|
3808 | var value = void 0;
|
3809 |
|
3810 | this.each(function (i, el) {
|
3811 | var data = $(el).data('bootstrap.table');
|
3812 | var options = $.extend({}, BootstrapTable.DEFAULTS, $(el).data(), (typeof option === 'undefined' ? 'undefined' : _typeof(option)) === 'object' && option);
|
3813 |
|
3814 | if (typeof option === 'string') {
|
3815 | var _data2;
|
3816 |
|
3817 | if (!allowedMethods.includes(option)) {
|
3818 | throw new Error('Unknown method: ' + option);
|
3819 | }
|
3820 |
|
3821 | if (!data) {
|
3822 | return;
|
3823 | }
|
3824 |
|
3825 | value = (_data2 = data)[option].apply(_data2, args);
|
3826 |
|
3827 | if (option === 'destroy') {
|
3828 | $(el).removeData('bootstrap.table');
|
3829 | }
|
3830 | }
|
3831 |
|
3832 | if (!data) {
|
3833 | $(el).data('bootstrap.table', data = new $.BootstrapTable(el, options));
|
3834 | }
|
3835 | });
|
3836 |
|
3837 | return typeof value === 'undefined' ? this : value;
|
3838 | };
|
3839 |
|
3840 | $.fn.bootstrapTable.Constructor = BootstrapTable;
|
3841 | $.fn.bootstrapTable.defaults = BootstrapTable.DEFAULTS;
|
3842 | $.fn.bootstrapTable.columnDefaults = BootstrapTable.COLUMN_DEFAULTS;
|
3843 | $.fn.bootstrapTable.locales = BootstrapTable.LOCALES;
|
3844 | $.fn.bootstrapTable.methods = allowedMethods;
|
3845 | $.fn.bootstrapTable.utils = Utils;
|
3846 |
|
3847 |
|
3848 |
|
3849 |
|
3850 | $(function () {
|
3851 | $('[data-toggle="table"]').bootstrapTable();
|
3852 | });
|
3853 | })(jQuery);
|
3854 | }); |
\ | No newline at end of file |