bootstrap-table-filter-control.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. (function (global, factory) {
  2. typeof exports === 'object' && typeof module !== 'undefined' ? factory(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.object.assign.js'), require('core-js/modules/es.object.keys.js'), require('core-js/modules/es.object.to-string.js'), require('core-js/modules/es.object.values.js'), require('core-js/modules/es.parse-int.js'), require('core-js/modules/es.promise.js'), require('core-js/modules/es.regexp.exec.js'), require('core-js/modules/es.regexp.to-string.js'), require('core-js/modules/es.string.includes.js'), require('core-js/modules/es.string.split.js'), require('core-js/modules/es.string.trim.js'), require('core-js/modules/web.dom-collections.for-each.js'), require('jquery'), require('core-js/modules/es.array.join.js'), require('core-js/modules/es.array.sort.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')) :
  3. typeof define === 'function' && define.amd ? define(['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.object.assign.js', 'core-js/modules/es.object.keys.js', 'core-js/modules/es.object.to-string.js', 'core-js/modules/es.object.values.js', 'core-js/modules/es.parse-int.js', 'core-js/modules/es.promise.js', 'core-js/modules/es.regexp.exec.js', 'core-js/modules/es.regexp.to-string.js', 'core-js/modules/es.string.includes.js', 'core-js/modules/es.string.split.js', 'core-js/modules/es.string.trim.js', 'core-js/modules/web.dom-collections.for-each.js', 'jquery', 'core-js/modules/es.array.join.js', 'core-js/modules/es.array.sort.js', 'core-js/modules/es.string.match.js', 'core-js/modules/es.string.replace.js', 'core-js/modules/es.string.starts-with.js'], factory) :
  4. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, global.jQuery));
  5. })(this, (function (es_array_concat_js, es_array_filter_js, es_array_find_js, es_array_includes_js, es_array_indexOf_js, es_object_assign_js, es_object_keys_js, es_object_toString_js, es_object_values_js, es_parseInt_js, es_promise_js, es_regexp_exec_js, es_regexp_toString_js, es_string_includes_js, es_string_split_js, es_string_trim_js, web_domCollections_forEach_js, $) { 'use strict';
  6. function _arrayLikeToArray(r, a) {
  7. (null == a || a > r.length) && (a = r.length);
  8. for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
  9. return n;
  10. }
  11. function _arrayWithoutHoles(r) {
  12. if (Array.isArray(r)) return _arrayLikeToArray(r);
  13. }
  14. function _assertThisInitialized(e) {
  15. if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  16. return e;
  17. }
  18. function _callSuper(t, o, e) {
  19. return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
  20. }
  21. function _classCallCheck(a, n) {
  22. if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
  23. }
  24. function _defineProperties(e, r) {
  25. for (var t = 0; t < r.length; t++) {
  26. var o = r[t];
  27. o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
  28. }
  29. }
  30. function _createClass(e, r, t) {
  31. return r && _defineProperties(e.prototype, r), Object.defineProperty(e, "prototype", {
  32. writable: !1
  33. }), e;
  34. }
  35. function _get() {
  36. return _get = "undefined" != typeof Reflect && Reflect.get ? Reflect.get.bind() : function (e, t, r) {
  37. var p = _superPropBase(e, t);
  38. if (p) {
  39. var n = Object.getOwnPropertyDescriptor(p, t);
  40. return n.get ? n.get.call(arguments.length < 3 ? e : r) : n.value;
  41. }
  42. }, _get.apply(null, arguments);
  43. }
  44. function _getPrototypeOf(t) {
  45. return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
  46. return t.__proto__ || Object.getPrototypeOf(t);
  47. }, _getPrototypeOf(t);
  48. }
  49. function _inherits(t, e) {
  50. if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function");
  51. t.prototype = Object.create(e && e.prototype, {
  52. constructor: {
  53. value: t,
  54. writable: !0,
  55. configurable: !0
  56. }
  57. }), Object.defineProperty(t, "prototype", {
  58. writable: !1
  59. }), e && _setPrototypeOf(t, e);
  60. }
  61. function _isNativeReflectConstruct() {
  62. try {
  63. var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
  64. } catch (t) {}
  65. return (_isNativeReflectConstruct = function () {
  66. return !!t;
  67. })();
  68. }
  69. function _iterableToArray(r) {
  70. if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
  71. }
  72. function _nonIterableSpread() {
  73. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  74. }
  75. function _possibleConstructorReturn(t, e) {
  76. if (e && ("object" == typeof e || "function" == typeof e)) return e;
  77. if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined");
  78. return _assertThisInitialized(t);
  79. }
  80. function _setPrototypeOf(t, e) {
  81. return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
  82. return t.__proto__ = e, t;
  83. }, _setPrototypeOf(t, e);
  84. }
  85. function _superPropBase(t, o) {
  86. for (; !{}.hasOwnProperty.call(t, o) && null !== (t = _getPrototypeOf(t)););
  87. return t;
  88. }
  89. function _toConsumableArray(r) {
  90. return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
  91. }
  92. function _toPrimitive(t, r) {
  93. if ("object" != typeof t || !t) return t;
  94. var e = t[Symbol.toPrimitive];
  95. if (void 0 !== e) {
  96. var i = e.call(t, r );
  97. if ("object" != typeof i) return i;
  98. throw new TypeError("@@toPrimitive must return a primitive value.");
  99. }
  100. return (String )(t);
  101. }
  102. function _toPropertyKey(t) {
  103. var i = _toPrimitive(t, "string");
  104. return "symbol" == typeof i ? i : i + "";
  105. }
  106. function _typeof(o) {
  107. "@babel/helpers - typeof";
  108. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
  109. return typeof o;
  110. } : function (o) {
  111. return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
  112. }, _typeof(o);
  113. }
  114. function _unsupportedIterableToArray(r, a) {
  115. if (r) {
  116. if ("string" == typeof r) return _arrayLikeToArray(r, a);
  117. var t = {}.toString.call(r).slice(8, -1);
  118. return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
  119. }
  120. }
  121. /* eslint-disable no-use-before-define */
  122. var Utils$1 = $.fn.bootstrapTable.utils;
  123. var searchControls = 'select, input:not([type="checkbox"]):not([type="radio"])';
  124. function getInputClass(that) {
  125. var isSelect = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  126. var formControlClass = isSelect ? that.constants.classes.select : that.constants.classes.input;
  127. return that.options.iconSize ? Utils$1.sprintf('%s %s-%s', formControlClass, formControlClass, that.options.iconSize) : formControlClass;
  128. }
  129. function getOptionsFromSelectControl(selectControl) {
  130. return selectControl[0].options;
  131. }
  132. function getControlContainer(that) {
  133. if (that.options.filterControlContainer) {
  134. return $("".concat(that.options.filterControlContainer));
  135. }
  136. if (that.options.height && that._initialized) {
  137. return that.$tableContainer.find('.fixed-table-header table thead');
  138. }
  139. return that.$header;
  140. }
  141. function isKeyAllowed(keyCode) {
  142. return $.inArray(keyCode, [37, 38, 39, 40]) > -1;
  143. }
  144. function getSearchControls(that) {
  145. return getControlContainer(that).find(searchControls);
  146. }
  147. function existOptionInSelectControl(selectControl, value) {
  148. var options = getOptionsFromSelectControl(selectControl);
  149. for (var i = 0; i < options.length; i++) {
  150. if (options[i].value === Utils$1.unescapeHTML(value)) {
  151. // The value is not valid to add
  152. return true;
  153. }
  154. }
  155. // If we get here, the value is valid to add
  156. return false;
  157. }
  158. function addOptionToSelectControl(selectControl, _value, text, selected, shouldCompareText) {
  159. var value = _value === undefined || _value === null ? '' : _value.toString().trim();
  160. value = Utils$1.removeHTML(Utils$1.unescapeHTML(value));
  161. text = Utils$1.removeHTML(Utils$1.unescapeHTML(text));
  162. if (existOptionInSelectControl(selectControl, value)) {
  163. return;
  164. }
  165. var isSelected = shouldCompareText ? value === selected || text === selected : value === selected;
  166. var option = new Option(text, value, false, isSelected);
  167. selectControl.get(0).add(option);
  168. }
  169. function sortSelectControl(selectControl, orderBy, options) {
  170. var $selectControl = selectControl.get(0);
  171. if (orderBy === 'server') {
  172. return;
  173. }
  174. var tmpAry = new Array();
  175. for (var i = 0; i < $selectControl.options.length; i++) {
  176. tmpAry[i] = new Array();
  177. tmpAry[i][0] = $selectControl.options[i].text;
  178. tmpAry[i][1] = $selectControl.options[i].value;
  179. tmpAry[i][2] = $selectControl.options[i].selected;
  180. }
  181. tmpAry.sort(function (a, b) {
  182. return Utils$1.sort(a[0], b[0], orderBy === 'desc' ? -1 : 1, options);
  183. });
  184. while ($selectControl.options.length > 0) {
  185. $selectControl.options[0] = null;
  186. }
  187. for (var _i = 0; _i < tmpAry.length; _i++) {
  188. var op = new Option(tmpAry[_i][0], tmpAry[_i][1], false, tmpAry[_i][2]);
  189. $selectControl.add(op);
  190. }
  191. }
  192. function fixHeaderCSS(_ref) {
  193. var $tableHeader = _ref.$tableHeader;
  194. $tableHeader.css('height', $tableHeader.find('table').outerHeight(true));
  195. }
  196. function getElementClass($element) {
  197. return $element.attr('class').split(' ').filter(function (className) {
  198. return className.startsWith('bootstrap-table-filter-control-');
  199. });
  200. }
  201. function getCursorPosition(el) {
  202. if ($(el).is('input[type=search]')) {
  203. var pos = 0;
  204. if ('selectionStart' in el) {
  205. pos = el.selectionStart;
  206. } else if ('selection' in document) {
  207. el.focus();
  208. var Sel = document.selection.createRange();
  209. var SelLength = document.selection.createRange().text.length;
  210. Sel.moveStart('character', -el.value.length);
  211. pos = Sel.text.length - SelLength;
  212. }
  213. return pos;
  214. }
  215. return -1;
  216. }
  217. function cacheValues(that) {
  218. var searchControls = getSearchControls(that);
  219. that._valuesFilterControl = [];
  220. searchControls.each(function () {
  221. var $field = $(this);
  222. var fieldClass = escapeID(getElementClass($field));
  223. if (that.options.height && !that.options.filterControlContainer) {
  224. $field = that.$el.find(".fixed-table-header .".concat(fieldClass));
  225. } else if (that.options.filterControlContainer) {
  226. $field = $("".concat(that.options.filterControlContainer, " .").concat(fieldClass));
  227. } else {
  228. $field = that.$el.find(".".concat(fieldClass));
  229. }
  230. that._valuesFilterControl.push({
  231. field: $field.closest('[data-field]').data('field'),
  232. value: $field.val(),
  233. position: getCursorPosition($field.get(0)),
  234. hasFocus: $field.is(':focus')
  235. });
  236. });
  237. }
  238. function setCaretPosition(elem, caretPos) {
  239. try {
  240. if (elem) {
  241. if (elem.createTextRange) {
  242. var range = elem.createTextRange();
  243. range.move('character', caretPos);
  244. range.select();
  245. } else {
  246. elem.setSelectionRange(caretPos, caretPos);
  247. }
  248. }
  249. } catch (ex) {
  250. // ignored
  251. }
  252. }
  253. function setValues(that) {
  254. var field = null;
  255. var result = [];
  256. var searchControls = getSearchControls(that);
  257. if (that._valuesFilterControl.length > 0) {
  258. // Callback to apply after settings fields values
  259. var callbacks = [];
  260. searchControls.each(function (i, el) {
  261. var $this = $(el);
  262. field = $this.closest('[data-field]').data('field');
  263. result = that._valuesFilterControl.filter(function (valueObj) {
  264. return valueObj.field === field;
  265. });
  266. if (result.length > 0) {
  267. if (result[0].hasFocus || result[0].value) {
  268. var fieldToFocusCallback = function (element, cacheElementInfo) {
  269. // Closure here to capture the field information
  270. var closedCallback = function closedCallback() {
  271. if (cacheElementInfo.hasFocus) {
  272. element.focus();
  273. }
  274. if (Array.isArray(cacheElementInfo.value)) {
  275. var $element = $(element);
  276. $.each(cacheElementInfo.value, function (i, e) {
  277. $element.find(Utils$1.sprintf('option[value=\'%s\']', e)).prop('selected', true);
  278. });
  279. } else {
  280. element.value = cacheElementInfo.value;
  281. }
  282. setCaretPosition(element, cacheElementInfo.position);
  283. };
  284. return closedCallback;
  285. }($this.get(0), result[0]);
  286. callbacks.push(fieldToFocusCallback);
  287. }
  288. }
  289. });
  290. // Callback call.
  291. if (callbacks.length > 0) {
  292. callbacks.forEach(function (callback) {
  293. return callback();
  294. });
  295. }
  296. }
  297. }
  298. function collectBootstrapTableFilterCookies() {
  299. var cookies = [];
  300. var cookieRegex = /bs\.table\.(filterControl|searchText)/g;
  301. var foundCookies = document.cookie.match(cookieRegex);
  302. var foundLocalStorage = localStorage;
  303. if (foundCookies) {
  304. $.each(foundCookies, function (i, _cookie) {
  305. var cookie = _cookie;
  306. if (/./.test(cookie)) {
  307. cookie = cookie.split('.').pop();
  308. }
  309. if ($.inArray(cookie, cookies) === -1) {
  310. cookies.push(cookie);
  311. }
  312. });
  313. }
  314. if (!foundLocalStorage) {
  315. return cookies;
  316. }
  317. Object.keys(localStorage).forEach(function (cookie) {
  318. if (!cookieRegex.test(cookie)) {
  319. return;
  320. }
  321. cookie = cookie.split('.').pop();
  322. if (!cookies.includes(cookie)) {
  323. cookies.push(cookie);
  324. }
  325. });
  326. return cookies;
  327. }
  328. function escapeID(id) {
  329. // eslint-disable-next-line no-useless-escape
  330. return String(id).replace(/([:.\[\],])/g, '\\$1');
  331. }
  332. function isColumnSearchableViaSelect(_ref2) {
  333. var filterControl = _ref2.filterControl,
  334. searchable = _ref2.searchable;
  335. return filterControl && filterControl.toLowerCase() === 'select' && searchable;
  336. }
  337. function isFilterDataNotGiven(_ref3) {
  338. var filterData = _ref3.filterData;
  339. return filterData === undefined || filterData.toLowerCase() === 'column';
  340. }
  341. function hasSelectControlElement(selectControl) {
  342. return selectControl && selectControl.length > 0;
  343. }
  344. function initFilterSelectControls(that) {
  345. var data = that.options.data;
  346. $.each(that.header.fields, function (j, field) {
  347. var column = that.columns[that.fieldsColumnsIndex[field]];
  348. var selectControl = getControlContainer(that).find("select.bootstrap-table-filter-control-".concat(escapeID(column.field)));
  349. if (isColumnSearchableViaSelect(column) && isFilterDataNotGiven(column) && hasSelectControlElement(selectControl)) {
  350. if (!selectControl[0].multiple && selectControl.get(selectControl.length - 1).options.length === 0) {
  351. // Added the default option, must use a non-breaking space(&nbsp;) to pass the W3C validator
  352. addOptionToSelectControl(selectControl, '', column.filterControlPlaceholder || ' ', column.filterDefault);
  353. }
  354. var uniqueValues = {};
  355. for (var i = 0; i < data.length; i++) {
  356. // Added a new value
  357. var fieldValue = Utils$1.getItemField(data[i], field, false);
  358. var formatter = that.options.editable && column.editable ? column._formatter : that.header.formatters[j];
  359. var formattedValue = Utils$1.calculateObjectValue(that.header, formatter, [fieldValue, data[i], i], fieldValue);
  360. if (fieldValue === undefined || fieldValue === null) {
  361. fieldValue = formattedValue;
  362. column._forceFormatter = true;
  363. }
  364. if (column.filterDataCollector) {
  365. formattedValue = Utils$1.calculateObjectValue(that.header, column.filterDataCollector, [fieldValue, data[i], formattedValue], formattedValue);
  366. }
  367. if (column.searchFormatter) {
  368. fieldValue = formattedValue;
  369. }
  370. uniqueValues[formattedValue] = fieldValue;
  371. if (_typeof(formattedValue) === 'object' && formattedValue !== null) {
  372. formattedValue.forEach(function (value) {
  373. addOptionToSelectControl(selectControl, value, value, column.filterDefault);
  374. });
  375. continue;
  376. }
  377. }
  378. // eslint-disable-next-line guard-for-in
  379. for (var key in uniqueValues) {
  380. addOptionToSelectControl(selectControl, uniqueValues[key], key, column.filterDefault);
  381. }
  382. if (that.options.sortSelectOptions) {
  383. sortSelectControl(selectControl, column.filterOrderBy, that.options);
  384. }
  385. }
  386. });
  387. }
  388. function getFilterDataMethod(objFilterDataMethod, searchTerm) {
  389. var keys = Object.keys(objFilterDataMethod);
  390. for (var i = 0; i < keys.length; i++) {
  391. if (keys[i] === searchTerm) {
  392. return objFilterDataMethod[searchTerm];
  393. }
  394. }
  395. return null;
  396. }
  397. function createControls(that, header) {
  398. var addedFilterControl = false;
  399. var html;
  400. $.each(that.columns, function (_, column) {
  401. html = [];
  402. if (!column.visible && !(that.options.filterControlContainer && $(".bootstrap-table-filter-control-".concat(escapeID(column.field))).length >= 1)) {
  403. return;
  404. }
  405. if (!column.filterControl && !that.options.filterControlContainer) {
  406. html.push('<div class="no-filter-control"></div>');
  407. } else if (that.options.filterControlContainer) {
  408. // Use a filter control container instead of th
  409. var $filterControls = $(".bootstrap-table-filter-control-".concat(escapeID(column.field)));
  410. $.each($filterControls, function (_, filterControl) {
  411. var $filterControl = $(filterControl);
  412. if (!$filterControl.is('[type=radio]')) {
  413. var placeholder = column.filterControlPlaceholder || '';
  414. $filterControl.attr('placeholder', placeholder).val(column.filterDefault);
  415. }
  416. $filterControl.attr('data-field', column.field);
  417. });
  418. addedFilterControl = true;
  419. } else {
  420. // Create the control based on the html defined in the filterTemplate array.
  421. var nameControl = column.filterControl.toLowerCase();
  422. html.push('<div class="filter-control">');
  423. addedFilterControl = true;
  424. if (column.searchable && that.options.filterTemplate[nameControl]) {
  425. html.push(that.options.filterTemplate[nameControl](that, column, column.filterControlPlaceholder ? column.filterControlPlaceholder : '', column.filterDefault));
  426. }
  427. }
  428. // Filtering by default when it is set.
  429. if (column.filterControl && '' !== column.filterDefault && 'undefined' !== typeof column.filterDefault) {
  430. if ($.isEmptyObject(that.filterColumnsPartial)) {
  431. that.filterColumnsPartial = {};
  432. }
  433. if (!(column.field in that.filterColumnsPartial)) {
  434. that.filterColumnsPartial[column.field] = column.filterDefault;
  435. }
  436. }
  437. $.each(header.find('th'), function (_, th) {
  438. var $th = $(th);
  439. if ($th.data('field') === column.field) {
  440. $th.find('.filter-control').remove();
  441. $th.find('.fht-cell').html(html.join(''));
  442. return false;
  443. }
  444. });
  445. if (column.filterData && column.filterData.toLowerCase() !== 'column') {
  446. var filterDataType = getFilterDataMethod(filterDataMethods, column.filterData.substring(0, column.filterData.indexOf(':')));
  447. var filterDataSource;
  448. var selectControl;
  449. if (filterDataType) {
  450. filterDataSource = column.filterData.substring(column.filterData.indexOf(':') + 1, column.filterData.length);
  451. selectControl = header.find(".bootstrap-table-filter-control-".concat(escapeID(column.field)));
  452. addOptionToSelectControl(selectControl, '', column.filterControlPlaceholder, column.filterDefault, true);
  453. filterDataType(that, filterDataSource, selectControl, that.options.filterOrderBy, column.filterDefault);
  454. } else {
  455. 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"}');
  456. }
  457. }
  458. });
  459. if (addedFilterControl) {
  460. header.off('keyup', 'input').on('keyup', 'input', function (_ref4, obj) {
  461. var currentTarget = _ref4.currentTarget,
  462. keyCode = _ref4.keyCode;
  463. keyCode = obj ? obj.keyCode : keyCode;
  464. if (that.options.searchOnEnterKey && keyCode !== 13) {
  465. return;
  466. }
  467. if (isKeyAllowed(keyCode)) {
  468. return;
  469. }
  470. var $currentTarget = $(currentTarget);
  471. if ($currentTarget.is(':checkbox') || $currentTarget.is(':radio')) {
  472. return;
  473. }
  474. clearTimeout(currentTarget.timeoutId || 0);
  475. currentTarget.timeoutId = setTimeout(function () {
  476. that.onColumnSearch({
  477. currentTarget: currentTarget,
  478. keyCode: keyCode
  479. });
  480. }, that.options.searchTimeOut);
  481. });
  482. header.off('change', 'select', '.fc-multipleselect').on('change', 'select', '.fc-multipleselect', function (_ref5) {
  483. var currentTarget = _ref5.currentTarget,
  484. keyCode = _ref5.keyCode;
  485. var $selectControl = $(currentTarget);
  486. var value = $selectControl.val();
  487. if (Array.isArray(value)) {
  488. for (var i = 0; i < value.length; i++) {
  489. if (value[i] && value[i].length > 0 && value[i].trim()) {
  490. $selectControl.find("option[value=\"".concat(value[i], "\"]")).attr('selected', true);
  491. }
  492. }
  493. } else if (value && value.length > 0 && value.trim()) {
  494. $selectControl.find('option[selected]').removeAttr('selected');
  495. $selectControl.find("option[value=\"".concat(value, "\"]")).attr('selected', true);
  496. } else {
  497. $selectControl.find('option[selected]').removeAttr('selected');
  498. }
  499. clearTimeout(currentTarget.timeoutId || 0);
  500. currentTarget.timeoutId = setTimeout(function () {
  501. that.onColumnSearch({
  502. currentTarget: currentTarget,
  503. keyCode: keyCode
  504. });
  505. }, that.options.searchTimeOut);
  506. });
  507. header.off('mouseup', 'input:not([type=radio])').on('mouseup', 'input:not([type=radio])', function (_ref6) {
  508. var currentTarget = _ref6.currentTarget,
  509. keyCode = _ref6.keyCode;
  510. var $input = $(currentTarget);
  511. var oldValue = $input.val();
  512. if (oldValue === '') {
  513. return;
  514. }
  515. setTimeout(function () {
  516. var newValue = $input.val();
  517. if (newValue === '') {
  518. clearTimeout(currentTarget.timeoutId || 0);
  519. currentTarget.timeoutId = setTimeout(function () {
  520. that.onColumnSearch({
  521. currentTarget: currentTarget,
  522. keyCode: keyCode
  523. });
  524. }, that.options.searchTimeOut);
  525. }
  526. }, 1);
  527. });
  528. header.off('change', 'input[type=radio]').on('change', 'input[type=radio]', function (_ref7) {
  529. var currentTarget = _ref7.currentTarget,
  530. keyCode = _ref7.keyCode;
  531. clearTimeout(currentTarget.timeoutId || 0);
  532. currentTarget.timeoutId = setTimeout(function () {
  533. that.onColumnSearch({
  534. currentTarget: currentTarget,
  535. keyCode: keyCode
  536. });
  537. }, that.options.searchTimeOut);
  538. });
  539. // See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
  540. if (header.find('.date-filter-control').length > 0) {
  541. $.each(that.columns, function (i, _ref8) {
  542. var filterDefault = _ref8.filterDefault,
  543. filterControl = _ref8.filterControl,
  544. field = _ref8.field,
  545. filterDatepickerOptions = _ref8.filterDatepickerOptions;
  546. if (filterControl !== undefined && filterControl.toLowerCase() === 'datepicker') {
  547. var $datepicker = header.find(".date-filter-control.bootstrap-table-filter-control-".concat(escapeID(field)));
  548. if (filterDefault) {
  549. $datepicker.value(filterDefault);
  550. }
  551. if (filterDatepickerOptions.min) {
  552. $datepicker.attr('min', filterDatepickerOptions.min);
  553. }
  554. if (filterDatepickerOptions.max) {
  555. $datepicker.attr('max', filterDatepickerOptions.max);
  556. }
  557. if (filterDatepickerOptions.step) {
  558. $datepicker.attr('step', filterDatepickerOptions.step);
  559. }
  560. if (filterDatepickerOptions.pattern) {
  561. $datepicker.attr('pattern', filterDatepickerOptions.pattern);
  562. }
  563. $datepicker.on('change', function (_ref9) {
  564. var currentTarget = _ref9.currentTarget;
  565. clearTimeout(currentTarget.timeoutId || 0);
  566. currentTarget.timeoutId = setTimeout(function () {
  567. that.onColumnSearch({
  568. currentTarget: currentTarget
  569. });
  570. }, that.options.searchTimeOut);
  571. });
  572. }
  573. });
  574. }
  575. if (that.options.sidePagination !== 'server') {
  576. that.triggerSearch();
  577. }
  578. if (!that.options.filterControlVisible) {
  579. header.find('.filter-control, .no-filter-control').hide();
  580. }
  581. } else {
  582. header.find('.filter-control, .no-filter-control').hide();
  583. }
  584. that.trigger('created-controls');
  585. }
  586. function getDirectionOfSelectOptions(_alignment) {
  587. var alignment = _alignment === undefined ? 'left' : _alignment.toLowerCase();
  588. switch (alignment) {
  589. case 'left':
  590. return 'ltr';
  591. case 'right':
  592. return 'rtl';
  593. case 'auto':
  594. return 'auto';
  595. default:
  596. return 'ltr';
  597. }
  598. }
  599. function syncHeaders(that) {
  600. if (!that.options.height) {
  601. return;
  602. }
  603. var fixedHeader = that.$tableContainer.find('.fixed-table-header table thead');
  604. if (fixedHeader.length === 0) {
  605. return;
  606. }
  607. that.$header.children().find('th[data-field]').each(function (_, element) {
  608. if (element.classList[0] !== 'bs-checkbox') {
  609. var $element = $(element);
  610. var $field = $element.data('field');
  611. var $fixedField = that.$tableContainer.find("th[data-field='".concat($field, "']")).not($element);
  612. var input = $element.find('input');
  613. var fixedInput = $fixedField.find('input');
  614. if (input.length > 0 && fixedInput.length > 0) {
  615. if (input.val() !== fixedInput.val()) {
  616. input.val(fixedInput.val());
  617. }
  618. }
  619. }
  620. });
  621. }
  622. var filterDataMethods = {
  623. func: function func(that, filterDataSource, selectControl, filterOrderBy, selected) {
  624. var variableValues = window[filterDataSource].apply();
  625. // eslint-disable-next-line guard-for-in
  626. for (var key in variableValues) {
  627. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  628. }
  629. if (that.options.sortSelectOptions) {
  630. sortSelectControl(selectControl, filterOrderBy, that.options);
  631. }
  632. setValues(that);
  633. },
  634. obj: function obj(that, filterDataSource, selectControl, filterOrderBy, selected) {
  635. var objectKeys = filterDataSource.split('.');
  636. var variableName = objectKeys.shift();
  637. var variableValues = window[variableName];
  638. if (objectKeys.length > 0) {
  639. objectKeys.forEach(function (key) {
  640. variableValues = variableValues[key];
  641. });
  642. }
  643. // eslint-disable-next-line guard-for-in
  644. for (var key in variableValues) {
  645. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  646. }
  647. if (that.options.sortSelectOptions) {
  648. sortSelectControl(selectControl, filterOrderBy, that.options);
  649. }
  650. setValues(that);
  651. },
  652. var: function _var(that, filterDataSource, selectControl, filterOrderBy, selected) {
  653. var variableValues = window[filterDataSource];
  654. var isArray = Array.isArray(variableValues);
  655. for (var key in variableValues) {
  656. if (isArray) {
  657. addOptionToSelectControl(selectControl, variableValues[key], variableValues[key], selected, true);
  658. } else {
  659. addOptionToSelectControl(selectControl, key, variableValues[key], selected, true);
  660. }
  661. }
  662. if (that.options.sortSelectOptions) {
  663. sortSelectControl(selectControl, filterOrderBy, that.options);
  664. }
  665. setValues(that);
  666. },
  667. url: function url(that, filterDataSource, selectControl, filterOrderBy, selected) {
  668. $.ajax({
  669. url: filterDataSource,
  670. dataType: 'json',
  671. success: function success(data) {
  672. // eslint-disable-next-line guard-for-in
  673. for (var key in data) {
  674. addOptionToSelectControl(selectControl, key, data[key], selected);
  675. }
  676. if (that.options.sortSelectOptions) {
  677. sortSelectControl(selectControl, filterOrderBy, that.options);
  678. }
  679. setValues(that);
  680. }
  681. });
  682. },
  683. json: function json(that, filterDataSource, selectControl, filterOrderBy, selected) {
  684. var variableValues = JSON.parse(filterDataSource);
  685. // eslint-disable-next-line guard-for-in
  686. for (var key in variableValues) {
  687. addOptionToSelectControl(selectControl, key, variableValues[key], selected);
  688. }
  689. if (that.options.sortSelectOptions) {
  690. sortSelectControl(selectControl, filterOrderBy, that.options);
  691. }
  692. setValues(that);
  693. }
  694. };
  695. var Utils = $.fn.bootstrapTable.utils;
  696. Object.assign($.fn.bootstrapTable.defaults, {
  697. filterControl: false,
  698. filterControlVisible: true,
  699. filterControlMultipleSearch: false,
  700. filterControlMultipleSearchDelimiter: ',',
  701. filterControlSearchClear: true,
  702. // eslint-disable-next-line no-unused-vars
  703. onColumnSearch: function onColumnSearch(field, text) {
  704. return false;
  705. },
  706. onCreatedControls: function onCreatedControls() {
  707. return false;
  708. },
  709. alignmentSelectControlOptions: undefined,
  710. filterTemplate: {
  711. input: function input(that, column, placeholder, value) {
  712. return Utils.sprintf('<input type="search" class="%s bootstrap-table-filter-control-%s search-input" style="width: 100%;" placeholder="%s" value="%s">', getInputClass(that), column.field, 'undefined' === typeof placeholder ? '' : placeholder, 'undefined' === typeof value ? '' : value);
  713. },
  714. select: function select(that, column) {
  715. return Utils.sprintf('<select class="%s bootstrap-table-filter-control-%s %s" %s style="width: 100%;" dir="%s"></select>', getInputClass(that, true), column.field, '', '', getDirectionOfSelectOptions(that.options.alignmentSelectControlOptions));
  716. },
  717. datepicker: function datepicker(that, column, value) {
  718. return Utils.sprintf('<input type="date" class="%s date-filter-control bootstrap-table-filter-control-%s" style="width: 100%;" value="%s">', getInputClass(that), column.field, 'undefined' === typeof value ? '' : value);
  719. }
  720. },
  721. searchOnEnterKey: false,
  722. showFilterControlSwitch: false,
  723. sortSelectOptions: false,
  724. // internal variables
  725. _valuesFilterControl: [],
  726. _initialized: false,
  727. _isRendering: false,
  728. _usingMultipleSelect: false
  729. });
  730. Object.assign($.fn.bootstrapTable.columnDefaults, {
  731. filterControl: undefined,
  732. // input, select, datepicker
  733. filterControlMultipleSelect: false,
  734. filterControlMultipleSelectOptions: {},
  735. filterDataCollector: undefined,
  736. filterData: undefined,
  737. filterDatepickerOptions: {},
  738. filterStrictSearch: false,
  739. filterStartsWithSearch: false,
  740. filterControlPlaceholder: '',
  741. filterDefault: '',
  742. filterOrderBy: 'asc',
  743. // asc || desc
  744. filterCustomSearch: undefined
  745. });
  746. Object.assign($.fn.bootstrapTable.events, {
  747. 'column-search.bs.table': 'onColumnSearch',
  748. 'created-controls.bs.table': 'onCreatedControls'
  749. });
  750. Object.assign($.fn.bootstrapTable.defaults.icons, {
  751. filterControlSwitchHide: {
  752. bootstrap3: 'glyphicon-zoom-out icon-zoom-out',
  753. bootstrap5: 'bi-zoom-out',
  754. materialize: 'zoom_out'
  755. }[$.fn.bootstrapTable.theme] || 'fa-search-minus',
  756. filterControlSwitchShow: {
  757. bootstrap3: 'glyphicon-zoom-in icon-zoom-in',
  758. bootstrap5: 'bi-zoom-in',
  759. materialize: 'zoom_in'
  760. }[$.fn.bootstrapTable.theme] || 'fa-search-plus'
  761. });
  762. Object.assign($.fn.bootstrapTable.locales, {
  763. formatFilterControlSwitch: function formatFilterControlSwitch() {
  764. return 'Hide/Show controls';
  765. },
  766. formatFilterControlSwitchHide: function formatFilterControlSwitchHide() {
  767. return 'Hide controls';
  768. },
  769. formatFilterControlSwitchShow: function formatFilterControlSwitchShow() {
  770. return 'Show controls';
  771. },
  772. formatClearSearch: function formatClearSearch() {
  773. return 'Clear filters';
  774. }
  775. });
  776. Object.assign($.fn.bootstrapTable.defaults, $.fn.bootstrapTable.locales);
  777. $.fn.bootstrapTable.methods.push('triggerSearch');
  778. $.fn.bootstrapTable.methods.push('clearFilterControl');
  779. $.fn.bootstrapTable.methods.push('toggleFilterControl');
  780. $.BootstrapTable = /*#__PURE__*/function (_$$BootstrapTable) {
  781. function _class() {
  782. _classCallCheck(this, _class);
  783. return _callSuper(this, _class, arguments);
  784. }
  785. _inherits(_class, _$$BootstrapTable);
  786. return _createClass(_class, [{
  787. key: "init",
  788. value: function init() {
  789. var _this = this;
  790. // Make sure that the filterControl option is set
  791. if (this.options.filterControl) {
  792. // Make sure that the internal variables are set correctly
  793. this._valuesFilterControl = [];
  794. this._initialized = false;
  795. this._usingMultipleSelect = false;
  796. this._isRendering = false;
  797. this.$el.on('reset-view.bs.table', Utils.debounce(function () {
  798. initFilterSelectControls(_this);
  799. setValues(_this);
  800. }, 3)).on('toggle.bs.table', Utils.debounce(function (_, cardView) {
  801. _this._initialized = false;
  802. if (!cardView) {
  803. initFilterSelectControls(_this);
  804. setValues(_this);
  805. _this._initialized = true;
  806. }
  807. }, 1)).on('post-header.bs.table', Utils.debounce(function () {
  808. initFilterSelectControls(_this);
  809. setValues(_this);
  810. }, 3)).on('column-switch.bs.table', Utils.debounce(function () {
  811. setValues(_this);
  812. if (_this.options.height) {
  813. _this.fitHeader();
  814. }
  815. }, 1)).on('post-body.bs.table', Utils.debounce(function () {
  816. if (_this.options.height && !_this.options.filterControlContainer && _this.options.filterControlVisible) {
  817. fixHeaderCSS(_this);
  818. }
  819. _this.$tableLoading.css('top', _this.$header.outerHeight() + 1);
  820. }, 1)).on('all.bs.table', function () {
  821. syncHeaders(_this);
  822. });
  823. }
  824. _get(_getPrototypeOf(_class.prototype), "init", this).call(this);
  825. }
  826. }, {
  827. key: "initBody",
  828. value: function initBody() {
  829. var _this2 = this;
  830. _get(_getPrototypeOf(_class.prototype), "initBody", this).call(this);
  831. if (!this.options.filterControl) {
  832. return;
  833. }
  834. setTimeout(function () {
  835. initFilterSelectControls(_this2);
  836. setValues(_this2);
  837. }, 3);
  838. }
  839. }, {
  840. key: "load",
  841. value: function load(data) {
  842. _get(_getPrototypeOf(_class.prototype), "load", this).call(this, data);
  843. if (!this.options.filterControl) {
  844. return;
  845. }
  846. createControls(this, getControlContainer(this));
  847. setValues(this);
  848. }
  849. }, {
  850. key: "initHeader",
  851. value: function initHeader() {
  852. _get(_getPrototypeOf(_class.prototype), "initHeader", this).call(this);
  853. if (!this.options.filterControl) {
  854. return;
  855. }
  856. createControls(this, getControlContainer(this));
  857. this._initialized = true;
  858. }
  859. }, {
  860. key: "initSearch",
  861. value: function initSearch() {
  862. var _this3 = this;
  863. var that = this;
  864. var filterPartial = $.isEmptyObject(that.filterColumnsPartial) ? null : that.filterColumnsPartial;
  865. _get(_getPrototypeOf(_class.prototype), "initSearch", this).call(this);
  866. if (this.options.sidePagination === 'server' || filterPartial === null) {
  867. return;
  868. }
  869. // Check partial column filter
  870. that.data = filterPartial ? that.data.filter(function (item, i) {
  871. var itemIsExpected = [];
  872. var keys1 = Object.keys(item);
  873. var keys2 = Object.keys(filterPartial);
  874. var keys = keys1.concat(keys2.filter(function (item) {
  875. return !keys1.includes(item);
  876. }));
  877. keys.forEach(function (key) {
  878. var thisColumn = that.columns[that.fieldsColumnsIndex[key]];
  879. var rawFilterValue = filterPartial[key] || '';
  880. var filterValue = rawFilterValue.toLowerCase();
  881. var value = Utils.unescapeHTML(Utils.getItemField(item, key, false));
  882. var tmpItemIsExpected;
  883. if (_this3.options.searchAccentNeutralise) {
  884. filterValue = Utils.normalizeAccent(filterValue);
  885. }
  886. var filterValues = [filterValue];
  887. if (_this3.options.filterControlMultipleSearch) {
  888. filterValues = filterValue.split(_this3.options.filterControlMultipleSearchDelimiter);
  889. }
  890. filterValues.forEach(function (filterValue) {
  891. if (tmpItemIsExpected === true) {
  892. return;
  893. }
  894. filterValue = filterValue.trim();
  895. if (filterValue === '') {
  896. tmpItemIsExpected = true;
  897. } else {
  898. // Fix #142: search use formatted data
  899. if (thisColumn) {
  900. if (thisColumn.searchFormatter || thisColumn._forceFormatter) {
  901. value = $.fn.bootstrapTable.utils.calculateObjectValue(thisColumn, that.header.formatters[$.inArray(key, that.header.fields)], [value, item, i], value);
  902. }
  903. }
  904. if ($.inArray(key, that.header.fields) !== -1) {
  905. if (value === undefined || value === null) {
  906. tmpItemIsExpected = false;
  907. } else if (_typeof(value) === 'object' && thisColumn.filterCustomSearch) {
  908. itemIsExpected.push(that.isValueExpected(rawFilterValue, value, thisColumn, key));
  909. } else if (_typeof(value) === 'object' && Array.isArray(value)) {
  910. value.forEach(function (objectValue) {
  911. if (tmpItemIsExpected) {
  912. return;
  913. }
  914. tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key);
  915. });
  916. } else if (_typeof(value) === 'object' && !Array.isArray(value)) {
  917. Object.values(value).forEach(function (objectValue) {
  918. if (tmpItemIsExpected) {
  919. return;
  920. }
  921. tmpItemIsExpected = that.isValueExpected(filterValue, objectValue, thisColumn, key);
  922. });
  923. } else if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
  924. tmpItemIsExpected = that.isValueExpected(filterValue, value, thisColumn, key);
  925. }
  926. }
  927. }
  928. });
  929. itemIsExpected.push(tmpItemIsExpected);
  930. });
  931. return !itemIsExpected.includes(false);
  932. }) : that.data;
  933. that.unsortedData = _toConsumableArray(that.data);
  934. }
  935. }, {
  936. key: "isValueExpected",
  937. value: function isValueExpected(searchValue, value, column, key) {
  938. var tmpItemIsExpected;
  939. if (column.filterControl === 'select') {
  940. value = Utils.removeHTML(value.toString().toLowerCase());
  941. }
  942. if (this.options.searchAccentNeutralise) {
  943. value = Utils.normalizeAccent(value);
  944. }
  945. if (column.filterStrictSearch || column.filterControl === 'select' && column.passed.filterStrictSearch !== false) {
  946. tmpItemIsExpected = value.toString().toLowerCase() === searchValue.toString().toLowerCase();
  947. } else if (column.filterStartsWithSearch) {
  948. tmpItemIsExpected = "".concat(value).toLowerCase().indexOf(searchValue) === 0;
  949. } else if (column.filterControl === 'datepicker') {
  950. tmpItemIsExpected = new Date(value).getTime() === new Date(searchValue).getTime();
  951. } else if (this.options.regexSearch) {
  952. tmpItemIsExpected = Utils.regexCompare(value, searchValue);
  953. } else {
  954. tmpItemIsExpected = "".concat(value).toLowerCase().includes(searchValue);
  955. }
  956. var largerSmallerEqualsRegex = /(?:(<=|=>|=<|>=|>|<)(?:\s+)?(\d+)?|(\d+)?(\s+)?(<=|=>|=<|>=|>|<))/gm;
  957. var matches = largerSmallerEqualsRegex.exec(searchValue);
  958. if (matches) {
  959. var operator = matches[1] || "".concat(matches[5], "l");
  960. var comparisonValue = matches[2] || matches[3];
  961. var int = parseInt(value, 10);
  962. var comparisonInt = parseInt(comparisonValue, 10);
  963. switch (operator) {
  964. case '>':
  965. case '<l':
  966. tmpItemIsExpected = int > comparisonInt;
  967. break;
  968. case '<':
  969. case '>l':
  970. tmpItemIsExpected = int < comparisonInt;
  971. break;
  972. case '<=':
  973. case '=<':
  974. case '>=l':
  975. case '=>l':
  976. tmpItemIsExpected = int <= comparisonInt;
  977. break;
  978. case '>=':
  979. case '=>':
  980. case '<=l':
  981. case '=<l':
  982. tmpItemIsExpected = int >= comparisonInt;
  983. break;
  984. }
  985. }
  986. if (column.filterCustomSearch) {
  987. var customSearchResult = Utils.calculateObjectValue(column, column.filterCustomSearch, [searchValue, value, key, this.options.data], true);
  988. if (customSearchResult !== null) {
  989. tmpItemIsExpected = customSearchResult;
  990. }
  991. }
  992. return tmpItemIsExpected;
  993. }
  994. }, {
  995. key: "initColumnSearch",
  996. value: function initColumnSearch(filterColumnsDefaults) {
  997. cacheValues(this);
  998. if (filterColumnsDefaults) {
  999. this.filterColumnsPartial = filterColumnsDefaults;
  1000. this.updatePagination();
  1001. // eslint-disable-next-line guard-for-in
  1002. for (var filter in filterColumnsDefaults) {
  1003. this.trigger('column-search', filter, filterColumnsDefaults[filter]);
  1004. }
  1005. }
  1006. }
  1007. }, {
  1008. key: "initToolbar",
  1009. value: function initToolbar() {
  1010. this.showToolbar = this.showToolbar || this.options.showFilterControlSwitch;
  1011. this.showSearchClearButton = this.options.filterControl && this.options.showSearchClearButton;
  1012. if (this.options.showFilterControlSwitch) {
  1013. this.buttons = Object.assign(this.buttons, {
  1014. filterControlSwitch: {
  1015. text: this.options.filterControlVisible ? this.options.formatFilterControlSwitchHide() : this.options.formatFilterControlSwitchShow(),
  1016. icon: this.options.filterControlVisible ? this.options.icons.filterControlSwitchHide : this.options.icons.filterControlSwitchShow,
  1017. event: this.toggleFilterControl,
  1018. attributes: {
  1019. 'aria-label': this.options.formatFilterControlSwitch(),
  1020. title: this.options.formatFilterControlSwitch()
  1021. }
  1022. }
  1023. });
  1024. }
  1025. _get(_getPrototypeOf(_class.prototype), "initToolbar", this).call(this);
  1026. }
  1027. }, {
  1028. key: "resetSearch",
  1029. value: function resetSearch(text) {
  1030. if (this.options.filterControl && this.options.filterControlSearchClear && this.options.showSearchClearButton) {
  1031. this.clearFilterControl();
  1032. }
  1033. _get(_getPrototypeOf(_class.prototype), "resetSearch", this).call(this, text);
  1034. }
  1035. }, {
  1036. key: "clearFilterControl",
  1037. value: function clearFilterControl() {
  1038. if (!this.options.filterControl) {
  1039. return;
  1040. }
  1041. var that = this;
  1042. var table = this.$el.closest('table');
  1043. var cookies = collectBootstrapTableFilterCookies();
  1044. var controls = getSearchControls(that);
  1045. // const search = Utils.getSearchInput(this)
  1046. var hasValues = false;
  1047. var timeoutId = 0;
  1048. // Clear cache values
  1049. $.each(that._valuesFilterControl, function (i, item) {
  1050. hasValues = hasValues ? true : item.value !== '';
  1051. item.value = '';
  1052. });
  1053. // Clear controls in UI
  1054. $.each(controls, function (i, item) {
  1055. item.value = '';
  1056. });
  1057. // Cache controls again
  1058. setValues(that);
  1059. // clear cookies once the filters are clean
  1060. clearTimeout(timeoutId);
  1061. timeoutId = setTimeout(function () {
  1062. if (cookies && cookies.length > 0) {
  1063. $.each(cookies, function (i, item) {
  1064. if (that.deleteCookie !== undefined) {
  1065. that.deleteCookie(item);
  1066. }
  1067. });
  1068. }
  1069. }, that.options.searchTimeOut);
  1070. // If there is not any value in the controls exit this method
  1071. if (!hasValues) {
  1072. return;
  1073. }
  1074. // Clear each type of filter if it exists.
  1075. // Requires the body to reload each time a type of filter is found because we never know
  1076. // which ones are going to be present.
  1077. if (controls.length > 0) {
  1078. this.filterColumnsPartial = {};
  1079. controls.eq(0).trigger(this.tagName === 'INPUT' ? 'keyup' : 'change', {
  1080. keyCode: 13
  1081. });
  1082. /* controls.each(function () {
  1083. $(this).trigger(this.tagName === 'INPUT' ? 'keyup' : 'change', { keyCode: 13 })
  1084. })*/
  1085. } else {
  1086. return;
  1087. }
  1088. /* if (search.length > 0) {
  1089. that.resetSearch('fc')
  1090. }*/
  1091. // use the default sort order if it exists. do nothing if it does not
  1092. if (that.options.sortName !== table.data('sortName') || that.options.sortOrder !== table.data('sortOrder')) {
  1093. var sorter = this.$header.find(Utils.sprintf('[data-field="%s"]', $(controls[0]).closest('table').data('sortName')));
  1094. if (sorter.length > 0) {
  1095. that.onSort({
  1096. type: 'keypress',
  1097. currentTarget: sorter
  1098. });
  1099. $(sorter).find('.sortable').trigger('click');
  1100. }
  1101. }
  1102. }
  1103. // EVENTS
  1104. }, {
  1105. key: "onColumnSearch",
  1106. value: function onColumnSearch(_ref) {
  1107. var _this4 = this;
  1108. var currentTarget = _ref.currentTarget,
  1109. keyCode = _ref.keyCode;
  1110. if (isKeyAllowed(keyCode)) {
  1111. return;
  1112. }
  1113. cacheValues(this);
  1114. // Cookie extension support
  1115. if (!this.options.cookie) {
  1116. this.options.pageNumber = 1;
  1117. } else {
  1118. // Force call the initServer method in Cookie extension
  1119. this._filterControlValuesLoaded = true;
  1120. }
  1121. if ($.isEmptyObject(this.filterColumnsPartial)) {
  1122. this.filterColumnsPartial = {};
  1123. }
  1124. // If searchOnEnterKey is set to true, then we need to iterate over all controls and grab their values.
  1125. var controls = this.options.searchOnEnterKey ? getSearchControls(this).toArray() : [currentTarget];
  1126. controls.forEach(function (element) {
  1127. var $element = $(element);
  1128. var elementValue = $element.val();
  1129. var text = elementValue ? elementValue.trim() : '';
  1130. var $field = $element.closest('[data-field]').data('field');
  1131. _this4.trigger('column-search', $field, text);
  1132. if (text) {
  1133. _this4.filterColumnsPartial[$field] = text;
  1134. } else {
  1135. delete _this4.filterColumnsPartial[$field];
  1136. }
  1137. });
  1138. this.onSearch({
  1139. currentTarget: currentTarget
  1140. }, false);
  1141. }
  1142. }, {
  1143. key: "toggleFilterControl",
  1144. value: function toggleFilterControl() {
  1145. this.options.filterControlVisible = !this.options.filterControlVisible;
  1146. // Controls in original header or container.
  1147. var $filterControls = getControlContainer(this).find('.filter-control, .no-filter-control');
  1148. if (this.options.filterControlVisible) {
  1149. $filterControls.show();
  1150. } else {
  1151. $filterControls.hide();
  1152. this.clearFilterControl();
  1153. }
  1154. // Controls in fixed header
  1155. if (this.options.height) {
  1156. var $fixedControls = this.$tableContainer.find('.fixed-table-header table thead').find('.filter-control, .no-filter-control');
  1157. $fixedControls.toggle(this.options.filterControlVisible);
  1158. fixHeaderCSS(this);
  1159. }
  1160. var icon = this.options.showButtonIcons ? this.options.filterControlVisible ? this.options.icons.filterControlSwitchHide : this.options.icons.filterControlSwitchShow : '';
  1161. var text = this.options.showButtonText ? this.options.filterControlVisible ? this.options.formatFilterControlSwitchHide() : this.options.formatFilterControlSwitchShow() : '';
  1162. this.$toolbar.find('>.columns').find('.filter-control-switch').html("".concat(Utils.sprintf(this.constants.html.icon, this.options.iconsPrefix, icon), " ").concat(text));
  1163. }
  1164. }, {
  1165. key: "triggerSearch",
  1166. value: function triggerSearch() {
  1167. var searchControls = getSearchControls(this);
  1168. searchControls.each(function () {
  1169. var $element = $(this);
  1170. if ($element.is('select')) {
  1171. $element.trigger('change');
  1172. } else {
  1173. $element.trigger('keyup');
  1174. }
  1175. });
  1176. }
  1177. }, {
  1178. key: "_toggleColumn",
  1179. value: function _toggleColumn(index, checked, needUpdate) {
  1180. this._initialized = false;
  1181. _get(_getPrototypeOf(_class.prototype), "_toggleColumn", this).call(this, index, checked, needUpdate);
  1182. syncHeaders(this);
  1183. }
  1184. }]);
  1185. }($.BootstrapTable);
  1186. }));