UNPKG

3.46 kBJavaScriptView Raw
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.bootstrapTableMultipleSearch = mod.exports;
12 }
13})(this, function () {
14 'use strict';
15
16 /**
17 * @author: Dennis Hernández
18 * @webSite: http://djhvscf.github.io/Blog
19 * @version: v1.0.0
20 */
21
22 !function ($) {
23
24 'use strict';
25
26 $.extend($.fn.bootstrapTable.defaults, {
27 multipleSearch: false,
28 delimeter: " "
29 });
30
31 var BootstrapTable = $.fn.bootstrapTable.Constructor,
32 _initSearch = BootstrapTable.prototype.initSearch;
33
34 BootstrapTable.prototype.initSearch = function () {
35 if (this.options.multipleSearch) {
36 if (this.searchText === undefined) {
37 return;
38 }
39 var strArray = this.searchText.split(this.options.delimeter),
40 that = this,
41 f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns,
42 dataFiltered = [];
43
44 if (strArray.length === 1) {
45 _initSearch.apply(this, Array.prototype.slice.apply(arguments));
46 } else {
47 for (var i = 0; i < strArray.length; i++) {
48 var str = strArray[i].trim();
49 dataFiltered = str ? $.grep(dataFiltered.length === 0 ? this.options.data : dataFiltered, function (item, i) {
50 for (var key in item) {
51 key = $.isNumeric(key) ? parseInt(key, 10) : key;
52 var value = item[key],
53 column = that.columns[that.fieldsColumnsIndex[key]],
54 j = $.inArray(key, that.header.fields);
55
56 // Fix #142: search use formated data
57 if (column && column.searchFormatter) {
58 value = $.fn.bootstrapTable.utils.calculateObjectValue(column, that.header.formatters[j], [value, item, i], value);
59 }
60
61 var index = $.inArray(key, that.header.fields);
62 if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
63 if (that.options.strictSearch) {
64 if ((value + '').toLowerCase() === str) {
65 return true;
66 }
67 } else {
68 if ((value + '').toLowerCase().indexOf(str) !== -1) {
69 return true;
70 }
71 }
72 }
73 }
74 return false;
75 }) : this.data;
76 }
77
78 this.data = dataFiltered;
79 }
80 } else {
81 _initSearch.apply(this, Array.prototype.slice.apply(arguments));
82 }
83 };
84 }(jQuery);
85});
\No newline at end of file