zhaojs
2023-10-07 6c7bba2e05c011a3d640b6565a113204228e92e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
 * @author: Dennis Hernández
 * @webSite: http://djhvscf.github.io/Blog
 * @version: v1.0.0
 */
 
!function ($) {
 
    'use strict';
 
    $.extend($.fn.bootstrapTable.defaults, {
        multipleSearch: false,
        delimeter: " "
    });
 
    var BootstrapTable = $.fn.bootstrapTable.Constructor,
        _initSearch = BootstrapTable.prototype.initSearch;
 
    BootstrapTable.prototype.initSearch = function () {
        if (this.options.multipleSearch) {
            if (this.searchText === undefined) {
                return;
            }
            var strArray = this.searchText.split(this.options.delimeter),
                that = this,
                f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns,
                dataFiltered = [];
 
            if (strArray.length === 1) {
                _initSearch.apply(this, Array.prototype.slice.apply(arguments));
            } else {
                for (var i = 0; i < strArray.length; i++) {
                    var str = strArray[i].trim();
                    dataFiltered = str ? $.grep(dataFiltered.length === 0 ? this.options.data : dataFiltered, function (item, i) {
                        for (var key in item) {
                            key = $.isNumeric(key) ? parseInt(key, 10) : key;
                            var value = item[key],
                                column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, key)],
                                j = $.inArray(key, that.header.fields);
 
                            // Fix #142: search use formated data
                            if (column && column.searchFormatter) {
                                value = $.fn.bootstrapTable.utils.calculateObjectValue(column,
                                    that.header.formatters[j], [value, item, i], value);
                            }
 
                            var index = $.inArray(key, that.header.fields);
                            if (index !== -1 && that.header.searchables[index] && (typeof value === 'string' || typeof value === 'number')) {
                                if (that.options.strictSearch) {
                                    if ((value + '').toLowerCase() === str) {
                                        return true;
                                    }
                                } else {
                                    if ((value + '').toLowerCase().indexOf(str) !== -1) {
                                        return true;
                                    }
                                }
                            }
                        }
                        return false;
                    }) : this.data;
                }
 
                this.data = dataFiltered;
            }
        } else {
            _initSearch.apply(this, Array.prototype.slice.apply(arguments));
        }
    };
 
}(jQuery);