utils.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('core-js/modules/es.array.concat.js'), require('core-js/modules/es.array.filter.js'), require('core-js/modules/es.array.find.js'), require('core-js/modules/es.array.includes.js'), require('core-js/modules/es.array.index-of.js'), require('core-js/modules/es.array.join.js'), require('core-js/modules/es.array.sort.js'), require('core-js/modules/es.object.keys.js'), require('core-js/modules/es.object.to-string.js'), require('core-js/modules/es.regexp.exec.js'), require('core-js/modules/es.regexp.to-string.js'), require('core-js/modules/es.string.match.js'), require('core-js/modules/es.string.replace.js'), require('core-js/modules/es.string.starts-with.js'), require('core-js/modules/es.string.trim.js'), require('core-js/modules/web.dom-collections.for-each.js'), require('jquery')) :
  3. typeof define === 'function' && define.amd ? define(['exports', 'core-js/modules/es.array.concat.js', 'core-js/modules/es.array.filter.js', 'core-js/modules/es.array.find.js', 'core-js/modules/es.array.includes.js', 'core-js/modules/es.array.index-of.js', 'core-js/modules/es.array.join.js', 'core-js/modules/es.array.sort.js', 'core-js/modules/es.object.keys.js', 'core-js/modules/es.object.to-string.js', 'core-js/modules/es.regexp.exec.js', 'core-js/modules/es.regexp.to-string.js', 'core-js/modules/es.string.match.js', 'core-js/modules/es.string.replace.js', 'core-js/modules/es.string.starts-with.js', 'core-js/modules/es.string.trim.js', 'core-js/modules/web.dom-collections.for-each.js', 'jquery'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.BootstrapTable = {}, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, global.jQuery));
  5. })(this, (function (exports, es_array_concat_js, es_array_filter_js, es_array_find_js, es_array_includes_js, es_array_indexOf_js, es_array_join_js, es_array_sort_js, es_object_keys_js, es_object_toString_js, es_regexp_exec_js, es_regexp_toString_js, es_string_match_js, es_string_replace_js, es_string_startsWith_js, es_string_trim_js, web_domCollections_forEach_js, $) { 'use strict';
  6. function _typeof(o) {
  7. "@babel/helpers - typeof";
  8. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  9. return typeof o;
  10. } : function (o) {
  11. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  12. }, _typeof(o);
  13. }
  14. /* eslint-disable no-use-before-define */
  15. var Utils = $.fn.bootstrapTable.utils;
  16. var searchControls = 'select, input:not([type="checkbox"]):not([type="radio"])';
  17. function getInputClass(that) {
  18. var isSelect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  19. var formControlClass = isSelect ? that.constants.classes.select : that.constants.classes.input;
  20. return that.options.iconSize ? Utils.sprintf('%s %s-%s', formControlClass, formControlClass, that.options.iconSize) : formControlClass;
  21. }
  22. function getOptionsFromSelectControl(selectControl) {
  23. return selectControl[0].options;
  24. }
  25. function getControlContainer(that) {
  26. if (that.options.filterControlContainer) {
  27. return $("".concat(that.options.filterControlContainer));
  28. }
  29. if (that.options.height && that._initialized) {
  30. return that.$tableContainer.find('.fixed-table-header table thead');
  31. }
  32. return that.$header;
  33. }
  34. function isKeyAllowed(keyCode) {
  35. return $.inArray(keyCode, [37, 38, 39, 40]) > -1;
  36. }
  37. function getSearchControls(that) {
  38. return getControlContainer(that).find(searchControls);
  39. }
  40. function hideUnusedSelectOptions(selectControl, uniqueValues) {
  41. var options = getOptionsFromSelectControl(selectControl);
  42. for (var i = 0; i < options.length; i++) {
  43. if (options[i].value !== '') {
  44. if (!uniqueValues.hasOwnProperty(options[i].value)) {
  45. selectControl.find(Utils.sprintf('option[value=\'%s\']', options[i].value)).hide();
  46. } else {
  47. selectControl.find(Utils.sprintf('option[value=\'%s\']', options[i].value)).show();
  48. }
  49. }
  50. }
  51. }
  52. function existOptionInSelectControl(selectControl, value) {
  53. var options = getOptionsFromSelectControl(selectControl);
  54. for (var i = 0; i < options.length; i++) {
  55. if (options[i].value === Utils.unescapeHTML(value)) {
  56. // The value is not valid to add
  57. return true;
  58. }
  59. }
  60. // If we get here, the value is valid to add
  61. return false;
  62. }
  63. function addOptionToSelectControl(selectControl, _value, text, selected, shouldCompareText) {
  64. var value = _value === undefined || _value === null ? '' : _value.toString().trim();
  65. value = Utils.removeHTML(Utils.unescapeHTML(value));
  66. text = Utils.removeHTML(Utils.unescapeHTML(text));
  67. if (existOptionInSelectControl(selectControl, value)) {
  68. return;
  69. }
  70. var isSelected = shouldCompareText ? value === selected || text === selected : value === selected;
  71. var option = new Option(text, value, false, isSelected);
  72. selectControl.get(0).add(option);
  73. }
  74. function sortSelectControl(selectControl, orderBy, options) {
  75. var $selectControl = selectControl.get(0);
  76. if (orderBy === 'server') {
  77. return;
  78. }
  79. var tmpAry = new Array();
  80. for (var i = 0; i < $selectControl.options.length; i++) {
  81. tmpAry[i] = new Array();
  82. tmpAry[i][0] = $selectControl.options[i].text;
  83. tmpAry[i][1] = $selectControl.options[i].value;
  84. tmpAry[i][2] = $selectControl.options[i].selected;
  85. }
  86. tmpAry.sort(function (a, b) {
  87. return Utils.sort(a[0], b[0], orderBy === 'desc' ? -1 : 1, options);
  88. });
  89. while ($selectControl.options.length > 0) {
  90. $selectControl.options[0] = null;
  91. }
  92. for (var _i = 0; _i < tmpAry.length; _i++) {
  93. var op = new Option(tmpAry[_i][0], tmpAry[_i][1], false, tmpAry[_i][2]);
  94. $selectControl.add(op);
  95. }
  96. }
  97. function fixHeaderCSS(_ref) {
  98. var $tableHeader = _ref.$tableHeader;
  99. $tableHeader.css('height', $tableHeader.find('table').outerHeight(true));
  100. }
  101. function getElementClass($element) {
  102. return $element.attr('class').split(' ').filter(function (className) {
  103. return className.startsWith('bootstrap-table-filter-control-');
  104. });
  105. }
  106. function getCursorPosition(el) {
  107. if ($(el).is('input[type=search]')) {
  108. var pos = 0;
  109. if ('selectionStart' in el) {
  110. pos = el.selectionStart;
  111. } else if ('selection' in document) {
  112. el.focus();
  113. var Sel = document.selection.createRange();
  114. var SelLength = document.selection.createRange().text.length;
  115. Sel.moveStart('character', -el.value.length);
  116. pos = Sel.text.length - SelLength;
  117. }
  118. return pos;
  119. }
  120. return -1;
  121. }
  122. function cacheValues(that) {
  123. var searchControls = getSearchControls(that);
  124. that._valuesFilterControl = [];
  125. searchControls.each(function () {
  126. var $field = $(this);
  127. var fieldClass = escapeID(getElementClass($field));
  128. if (that.options.height && !that.options.filterControlContainer) {
  129. $field = that.$el.find(".fixed-table-header .".concat(fieldClass));
  130. } else if (that.options.filterControlContainer) {
  131. $field = $("".concat(that.options.filterControlContainer, " .").concat(fieldClass));
  132. } else {
  133. $field = that.$el.find(".".concat(fieldClass));
  134. }
  135. that._valuesFilterControl.push({
  136. field: $field.closest('[data-field]').data('field'),
  137. value: $field.val(),
  138. position: getCursorPosition($field.get(0)),
  139. hasFocus: $field.is(':focus')
  140. });
  141. });
  142. }
  143. function setCaretPosition(elem, caretPos) {
  144. try {
  145. if (elem) {
  146. if (elem.createTextRange) {
  147. var range = elem.createTextRange();
  148. range.move('character', caretPos);
  149. range.select();
  150. } else {
  151. elem.setSelectionRange(caretPos, caretPos);
  152. }
  153. }
  154. } catch (ex) {
  155. // ignored
  156. }
  157. }
  158. function setValues(that) {
  159. var field = null;
  160. var result = [];
  161. var searchControls = getSearchControls(that);
  162. if (that._valuesFilterControl.length > 0) {
  163. // Callback to apply after settings fields values
  164. var callbacks = [];
  165. searchControls.each(function (i, el) {
  166. var $this = $(el);
  167. field = $this.closest('[data-field]').data('field');
  168. result = that._valuesFilterControl.filter(function (valueObj) {
  169. return valueObj.field === field;
  170. });
  171. if (result.length > 0) {
  172. if (result[0].hasFocus || result[0].value) {
  173. var fieldToFocusCallback = function (element, cacheElementInfo) {
  174. // Closure here to capture the field information
  175. var closedCallback = function closedCallback() {
  176. if (cacheElementInfo.hasFocus) {
  177. element.focus();
  178. }
  179. if (Array.isArray(cacheElementInfo.value)) {
  180. var $element = $(element);
  181. $.each(cacheElementInfo.value, function (i, e) {
  182. $element.find(Utils.sprintf('option[value=\'%s\']', e)).prop('selected', true);
  183. });
  184. } else {
  185. element.value = cacheElementInfo.value;
  186. }
  187. setCaretPosition(element, cacheElementInfo.position);
  188. };
  189. return closedCallback;
  190. }($this.get(0), result[0]);
  191. callbacks.push(fieldToFocusCallback);
  192. }
  193. }
  194. });
  195. // Callback call.
  196. if (callbacks.length > 0) {
  197. callbacks.forEach(function (callback) {
  198. return callback();
  199. });
  200. }
  201. }
  202. }
  203. function collectBootstrapTableFilterCookies() {
  204. var cookies = [];
  205. var cookieRegex = /bs\.table\.(filterControl|searchText)/g;
  206. var foundCookies = document.cookie.match(cookieRegex);
  207. var foundLocalStorage = localStorage;
  208. if (foundCookies) {
  209. $.each(foundCookies, function (i, _cookie) {
  210. var cookie = _cookie;
  211. if (/./.test(cookie)) {
  212. cookie = cookie.split('.').pop();
  213. }
  214. if ($.inArray(cookie, cookies) === -1) {
  215. cookies.push(cookie);
  216. }
  217. });
  218. }
  219. if (!foundLocalStorage) {
  220. return cookies;
  221. }
  222. Object.keys(localStorage).forEach(function (cookie) {
  223. if (!cookieRegex.test(cookie)) {
  224. return;
  225. }
  226. cookie = cookie.split('.').pop();
  227. if (!cookies.includes(cookie)) {
  228. cookies.push(cookie);
  229. }
  230. });
  231. return cookies;
  232. }
  233. function escapeID(id) {
  234. // eslint-disable-next-line no-useless-escape
  235. return String(id).replace(/([:.\[\],])/g, '\\$1');
  236. }
  237. function isColumnSearchableViaSelect(_ref2) {
  238. var filterControl = _ref2.filterControl,
  239. searchable = _ref2.searchable;
  240. return filterControl && filterControl.toLowerCase() === 'select' && searchable;
  241. }
  242. function isFilterDataNotGiven(_ref3) {
  243. var filterData = _ref3.filterData;
  244. return filterData === undefined || filterData.toLowerCase() === 'column';
  245. }
  246. function hasSelectControlElement(selectControl) {
  247. return selectControl && selectControl.length > 0;
  248. }
  249. function initFilterSelectControls(that) {
  250. var data = that.options.data;
  251. $.each(that.header.fields, function (j, field) {
  252. var column = that.columns[that.fieldsColumnsIndex[field]];
  253. var selectControl = getControlContainer(that).find("select.bootstrap-table-filter-control-".concat(escapeID(column.field)));
  254. if (isColumnSearchableViaSelect(column) && isFilterDataNotGiven(column) && hasSelectControlElement(selectControl)) {
  255. if (!selectControl[0].multiple && selectControl.get(selectControl.length - 1).options.length === 0) {
  256. // Added the default option, must use a non-breaking space(&nbsp;) to pass the W3C validator
  257. addOptionToSelectControl(selectControl, '', column.filterControlPlaceholder || ' ', column.filterDefault);
  258. }
  259. var uniqueValues = {};
  260. for (var i = 0; i < data.length; i++) {
  261. // Added a new value
  262. var fieldValue = Utils.getItemField(data[i], field, false);
  263. var formatter = that.options.editable && column.editable ? column._formatter : that.header.formatters[j];
  264. var formattedValue = Utils.calculateObjectValue(that.header, formatter, [fieldValue, data[i], i], fieldValue);
  265. if (fieldValue === undefined || fieldValue === null) {
  266. fieldValue = formattedValue;
  267. column._forceFormatter = true;
  268. }
  269. if (column.filterDataCollector) {
  270. formattedValue = Utils.calculateObjectValue(that.header, column.filterDataCollector, [fieldValue, data[i], formattedValue], formattedValue);
  271. }
  272. if (column.searchFormatter) {
  273. fieldValue = formattedValue;
  274. }
  275. uniqueValues[formattedValue] = fieldValue;
  276. if (_typeof(formattedValue) === 'object' && formattedValue !== null) {
  277. formattedValue.forEach(function (value) {
  278. addOptionToSelectControl(selectControl, value, value, column.filterDefault);
  279. });
  280. continue;
  281. }
  282. }
  283. // eslint-disable-next-line guard-for-in
  284. for (var key in uniqueValues) {
  285. addOptionToSelectControl(selectControl, uniqueValues[key], key, column.filterDefault);
  286. }
  287. if (that.options.sortSelectOptions) {
  288. sortSelectControl(selectControl, column.filterOrderBy, that.options);
  289. }
  290. }
  291. });
  292. }
  293. function getFilterDataMethod(objFilterDataMethod, searchTerm) {
  294. var keys = Object.keys(objFilterDataMethod);
  295. for (var i = 0; i < keys.length; i++) {
  296. if (keys[i] === searchTerm) {
  297. return objFilterDataMethod[searchTerm];
  298. }
  299. }
  300. return null;
  301. }
  302. function createControls(that, header) {
  303. var addedFilterControl = false;
  304. var html;
  305. $.each(that.columns, function (_, column) {
  306. html = [];
  307. if (!column.visible && !(that.options.filterControlContainer && $(".bootstrap-table-filter-control-".concat(escapeID(column.field))).length >= 1)) {
  308. return;
  309. }
  310. if (!column.filterControl && !that.options.filterControlContainer) {
  311. html.push('<div class="no-filter-control"></div>');
  312. } else if (that.options.filterControlContainer) {
  313. // Use a filter control container instead of th
  314. var $filterControls = $(".bootstrap-table-filter-control-".concat(escapeID(column.field)));
  315. $.each($filterControls, function (_, filterControl) {
  316. var $filterControl = $(filterControl);
  317. if (!$filterControl.is('[type=radio]')) {
  318. var placeholder = column.filterControlPlaceholder || '';
  319. $filterControl.attr('placeholder', placeholder).val(column.filterDefault);
  320. }
  321. $filterControl.attr('data-field', column.field);
  322. });
  323. addedFilterControl = true;
  324. } else {
  325. // Create the control based on the html defined in the filterTemplate array.
  326. var nameControl = column.filterControl.toLowerCase();
  327. html.push('<div class="filter-control">');
  328. addedFilterControl = true;
  329. if (column.searchable && that.options.filterTemplate[nameControl]) {
  330. html.push(that.options.filterTemplate[nameControl](that, column, column.filterControlPlaceholder ? column.filterControlPlaceholder : '', column.filterDefault));
  331. }
  332. }
  333. // Filtering by default when it is set.
  334. if (column.filterControl && '' !== column.filterDefault && 'undefined' !== typeof column.filterDefault) {
  335. if ($.isEmptyObject(that.filterColumnsPartial)) {
  336. that.filterColumnsPartial = {};
  337. }
  338. if (!(column.field in that.filterColumnsPartial)) {
  339. that.filterColumnsPartial[column.field] = column.filterDefault;
  340. }
  341. }
  342. $.each(header.find('th'), function (_, th) {
  343. var $th = $(th);
  344. if ($th.data('field') === column.field) {
  345. $th.find('.filter-control').remove();
  346. $th.find('.fht-cell').html(html.join(''));
  347. return false;
  348. }
  349. });
  350. if (column.filterData && column.filterData.toLowerCase() !== 'column') {
  351. var filterDataType = getFilterDataMethod(filterDataMethods, column.filterData.substring(0, column.filterData.indexOf(':')));
  352. var filterDataSource;
  353. var selectControl;
  354. if (filterDataType) {
  355. filterDataSource = column.filterData.substring(column.filterData.indexOf(':') + 1, column.filterData.length);
  356. selectControl = header.find(".bootstrap-table-filter-control-".concat(escapeID(column.field)));
  357. addOptionToSelectControl(selectControl, '', column.filterControlPlaceholder, column.filterDefault, true);
  358. filterDataType(that, filterDataSource, selectControl, that.options.filterOrderBy, column.filterDefault);
  359. } else {
  360. throw new SyntaxError('Error. You should use any of these allowed filter data methods: var, obj, json, url, func.' + ' Use like this: var: {key: "value"}');
  361. }
  362. }
  363. });
  364. if (addedFilterControl) {
  365. header.off('keyup', 'input').on('keyup', 'input', function (_ref4, obj) {
  366. var currentTarget = _ref4.currentTarget,
  367. keyCode = _ref4.keyCode;
  368. keyCode = obj ? obj.keyCode : keyCode;
  369. if (that.options.searchOnEnterKey && keyCode !== 13) {
  370. return;
  371. }
  372. if (isKeyAllowed(keyCode)) {
  373. return;
  374. }
  375. var $currentTarget = $(currentTarget);
  376. if ($currentTarget.is(':checkbox') || $currentTarget.is(':radio')) {
  377. return;
  378. }
  379. clearTimeout(currentTarget.timeoutId || 0);
  380. currentTarget.timeoutId = setTimeout(function () {
  381. that.onColumnSearch({
  382. currentTarget: currentTarget,
  383. keyCode: keyCode
  384. });
  385. }, that.options.searchTimeOut);
  386. });
  387. header.off('change', 'select', '.fc-multipleselect').on('change', 'select', '.fc-multipleselect', function (_ref5) {
  388. var currentTarget = _ref5.currentTarget,
  389. keyCode = _ref5.keyCode;
  390. var $selectControl = $(currentTarget);
  391. var value = $selectControl.val();
  392. if (Array.isArray(value)) {
  393. for (var i = 0; i < value.length; i++) {
  394. if (value[i] && value[i].length > 0 && value[i].trim()) {
  395. $selectControl.find("option[value=\"".concat(value[i], "\"]")).attr('selected', true);
  396. }
  397. }
  398. } else if (value && value.length > 0 && value.trim()) {
  399. $selectControl.find('option[selected]').removeAttr('selected');
  400. $selectControl.find("option[value=\"".concat(value, "\"]")).attr('selected', true);
  401. } else {
  402. $selectControl.find('option[selected]').removeAttr('selected');
  403. }
  404. clearTimeout(currentTarget.timeoutId || 0);
  405. currentTarget.timeoutId = setTimeout(function () {
  406. that.onColumnSearch({
  407. currentTarget: currentTarget,
  408. keyCode: keyCode
  409. });
  410. }, that.options.searchTimeOut);
  411. });
  412. header.off('mouseup', 'input:not([type=radio])').on('mouseup', 'input:not([type=radio])', function (_ref6) {
  413. var currentTarget = _ref6.currentTarget,
  414. keyCode = _ref6.keyCode;
  415. var $input = $(currentTarget);
  416. var oldValue = $input.val();
  417. if (oldValue === '') {
  418. return;
  419. }
  420. setTimeout(function () {
  421. var newValue = $input.val();
  422. if (newValue === '') {
  423. clearTimeout(currentTarget.timeoutId || 0);
  424. currentTarget.timeoutId = setTimeout(function () {
  425. that.onColumnSearch({
  426. currentTarget: currentTarget,
  427. keyCode: keyCode
  428. });
  429. }, that.options.searchTimeOut);
  430. }
  431. }, 1);
  432. });
  433. header.off('change', 'input[type=radio]').on('change', 'input[type=radio]', function (_ref7) {
  434. var currentTarget = _ref7.currentTarget,
  435. keyCode = _ref7.keyCode;
  436. clearTimeout(currentTarget.timeoutId || 0);
  437. currentTarget.timeoutId = setTimeout(function () {
  438. that.onColumnSearch({
  439. currentTarget: currentTarget,
  440. keyCode: keyCode
  441. });
  442. }, that.options.searchTimeOut);
  443. });
  444. // See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
  445. if (header.find('.date-filter-control').length > 0) {
  446. $.each(that.columns, function (i, _ref8) {
  447. var filterDefault = _ref8.filterDefault,
  448. filterControl = _ref8.filterControl,
  449. field = _ref8.field,
  450. filterDatepickerOptions = _ref8.filterDatepickerOptions;
  451. if (filterControl !== undefined && filterControl.toLowerCase() === 'datepicker') {
  452. var $datepicker = header.find(".date-filter-control.bootstrap-table-filter-control-".concat(escapeID(field)));
  453. if (filterDefault) {
  454. $datepicker.value(filterDefault);
  455. }
  456. if (filterDatepickerOptions.min) {
  457. $datepicker.attr('min', filterDatepickerOptions.min);
  458. }
  459. if (filterDatepickerOptions.max) {
  460. $datepicker.attr('max', filterDatepickerOptions.max);
  461. }
  462. if (filterDatepickerOptions.step) {
  463. $datepicker.attr('step', filterDatepickerOptions.step);
  464. }
  465. if (filterDatepickerOptions.pattern) {
  466. $datepicker.attr('pattern', filterDatepickerOptions.pattern);
  467. }
  468. $datepicker.on('change', function (_ref9) {
  469. var currentTarget = _ref9.currentTarget;
  470. clearTimeout(currentTarget.timeoutId || 0);
  471. currentTarget.timeoutId = setTimeout(function () {
  472. that.onColumnSearch({
  473. currentTarget: currentTarget
  474. });
  475. }, that.options.searchTimeOut);
  476. });
  477. }
  478. });
  479. }
  480. if (that.options.sidePagination !== 'server') {
  481. that.triggerSearch();
  482. }
  483. if (!that.options.filterControlVisible) {
  484. header.find('.filter-control, .no-filter-control').hide();
  485. }
  486. } else {
  487. header.find('.filter-control, .no-filter-control').hide();
  488. }
  489. that.trigger('created-controls');
  490. }
  491. function getDirectionOfSelectOptions(_alignment) {
  492. var alignment = _alignment === undefined ? 'left' : _alignment.toLowerCase();
  493. switch (alignment) {
  494. case 'left':
  495. return 'ltr';
  496. case 'right':
  497. return 'rtl';
  498. case 'auto':
  499. return 'auto';
  500. default:
  501. return 'ltr';
  502. }
  503. }
  504. function syncHeaders(that) {
  505. if (!that.options.height) {
  506. return;
  507. }
  508. var fixedHeader = that.$tableContainer.find('.fixed-table-header table thead');
  509. if (fixedHeader.length === 0) {
  510. return;
  511. }
  512. that.$header.children().find('th[data-field]').each(function (_, element) {
  513. if (element.classList[0] !== 'bs-checkbox') {
  514. var $element = $(element);
  515. var $field = $element.data('field');
  516. var $fixedField = that.$tableContainer.find("th[data-field='".concat($field, "']")).not($element);
  517. var input = $element.find('input');
  518. var fixedInput = $fixedField.find('input');
  519. if (input.length > 0 && fixedInput.length > 0) {
  520. if (input.val() !== fixedInput.val()) {
  521. input.val(fixedInput.val());
  522. }
  523. }
  524. }
  525. });
  526. }
  527. var filterDataMethods = {
  528. func: function func(that, filterDataSource, selectControl, filterOrderBy, selected) {
  529. var variableValues = window[filterDataSource].apply();
  530. // eslint-disable-next-line guard-for-in
  531. for (var key in variableValues) {
  532. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  533. }
  534. if (that.options.sortSelectOptions) {
  535. sortSelectControl(selectControl, filterOrderBy, that.options);
  536. }
  537. setValues(that);
  538. },
  539. obj: function obj(that, filterDataSource, selectControl, filterOrderBy, selected) {
  540. var objectKeys = filterDataSource.split('.');
  541. var variableName = objectKeys.shift();
  542. var variableValues = window[variableName];
  543. if (objectKeys.length > 0) {
  544. objectKeys.forEach(function (key) {
  545. variableValues = variableValues[key];
  546. });
  547. }
  548. // eslint-disable-next-line guard-for-in
  549. for (var key in variableValues) {
  550. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  551. }
  552. if (that.options.sortSelectOptions) {
  553. sortSelectControl(selectControl, filterOrderBy, that.options);
  554. }
  555. setValues(that);
  556. },
  557. var: function _var(that, filterDataSource, selectControl, filterOrderBy, selected) {
  558. var variableValues = window[filterDataSource];
  559. var isArray = Array.isArray(variableValues);
  560. for (var key in variableValues) {
  561. if (isArray) {
  562. addOptionToSelectControl(selectControl, variableValues[key], variableValues[key], selected, true);
  563. } else {
  564. addOptionToSelectControl(selectControl, key, variableValues[key], selected, true);
  565. }
  566. }
  567. if (that.options.sortSelectOptions) {
  568. sortSelectControl(selectControl, filterOrderBy, that.options);
  569. }
  570. setValues(that);
  571. },
  572. url: function url(that, filterDataSource, selectControl, filterOrderBy, selected) {
  573. $.ajax({
  574. url: filterDataSource,
  575. dataType: 'json',
  576. success: function success(data) {
  577. // eslint-disable-next-line guard-for-in
  578. for (var key in data) {
  579. addOptionToSelectControl(selectControl, key, data[key], selected);
  580. }
  581. if (that.options.sortSelectOptions) {
  582. sortSelectControl(selectControl, filterOrderBy, that.options);
  583. }
  584. setValues(that);
  585. }
  586. });
  587. },
  588. json: function json(that, filterDataSource, selectControl, filterOrderBy, selected) {
  589. var variableValues = JSON.parse(filterDataSource);
  590. // eslint-disable-next-line guard-for-in
  591. for (var key in variableValues) {
  592. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  593. }
  594. if (that.options.sortSelectOptions) {
  595. sortSelectControl(selectControl, filterOrderBy, that.options);
  596. }
  597. setValues(that);
  598. }
  599. };
  600. exports.addOptionToSelectControl = addOptionToSelectControl;
  601. exports.cacheValues = cacheValues;
  602. exports.collectBootstrapTableFilterCookies = collectBootstrapTableFilterCookies;
  603. exports.createControls = createControls;
  604. exports.escapeID = escapeID;
  605. exports.existOptionInSelectControl = existOptionInSelectControl;
  606. exports.fixHeaderCSS = fixHeaderCSS;
  607. exports.getControlContainer = getControlContainer;
  608. exports.getCursorPosition = getCursorPosition;
  609. exports.getDirectionOfSelectOptions = getDirectionOfSelectOptions;
  610. exports.getElementClass = getElementClass;
  611. exports.getFilterDataMethod = getFilterDataMethod;
  612. exports.getInputClass = getInputClass;
  613. exports.getOptionsFromSelectControl = getOptionsFromSelectControl;
  614. exports.getSearchControls = getSearchControls;
  615. exports.hasSelectControlElement = hasSelectControlElement;
  616. exports.hideUnusedSelectOptions = hideUnusedSelectOptions;
  617. exports.initFilterSelectControls = initFilterSelectControls;
  618. exports.isColumnSearchableViaSelect = isColumnSearchableViaSelect;
  619. exports.isFilterDataNotGiven = isFilterDataNotGiven;
  620. exports.isKeyAllowed = isKeyAllowed;
  621. exports.setCaretPosition = setCaretPosition;
  622. exports.setValues = setValues;
  623. exports.sortSelectControl = sortSelectControl;
  624. exports.syncHeaders = syncHeaders;
  625. }));