bootstrap-table-rails 1.10.1 → 1.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bootstrap-table-rails/version.rb +1 -1
- data/vendor/assets/javascripts/bootstrap-table-locale-all.js +60 -19
- data/vendor/assets/javascripts/bootstrap-table.js +305 -94
- data/vendor/assets/javascripts/extensions/bootstrap-table-angular.js +5 -3
- data/vendor/assets/javascripts/extensions/bootstrap-table-cookie.js +85 -28
- data/vendor/assets/javascripts/extensions/bootstrap-table-copy-rows.js +102 -0
- data/vendor/assets/javascripts/extensions/bootstrap-table-editable.js +51 -33
- data/vendor/assets/javascripts/extensions/bootstrap-table-export.js +11 -2
- data/vendor/assets/javascripts/extensions/bootstrap-table-filter-control.js +216 -71
- data/vendor/assets/javascripts/extensions/bootstrap-table-group-by.js +1 -1
- data/vendor/assets/javascripts/extensions/bootstrap-table-i18n-enhance.js +34 -0
- data/vendor/assets/javascripts/extensions/bootstrap-table-multi-toggle.js +88 -0
- data/vendor/assets/javascripts/extensions/bootstrap-table-multiple-search.js +6 -2
- data/vendor/assets/javascripts/extensions/bootstrap-table-multiple-sort.js +39 -24
- data/vendor/assets/javascripts/extensions/bootstrap-table-natural-sorting.js +12 -2
- data/vendor/assets/javascripts/extensions/bootstrap-table-reorder-columns.js +57 -1
- data/vendor/assets/javascripts/extensions/bootstrap-table-select2-filter.js +303 -0
- data/vendor/assets/javascripts/extensions/bootstrap-table-sticky-header.js +16 -9
- data/vendor/assets/javascripts/locale/bootstrap-table-en-US.js +6 -0
- data/vendor/assets/javascripts/locale/bootstrap-table-it-IT.js +5 -1
- data/vendor/assets/javascripts/locale/bootstrap-table-nl-NL.js +24 -15
- data/vendor/assets/javascripts/locale/bootstrap-table-pt-PT.js +18 -3
- data/vendor/assets/javascripts/locale/bootstrap-table-zh-CN.js +7 -1
- data/vendor/assets/stylesheets/bootstrap-table.css +9 -2
- metadata +7 -3
@@ -0,0 +1,34 @@
|
|
1
|
+
/**
|
2
|
+
* @author: Jewway
|
3
|
+
* @version: v1.0.0
|
4
|
+
*/
|
5
|
+
|
6
|
+
!function ($) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
var BootstrapTable = $.fn.bootstrapTable.Constructor;
|
10
|
+
|
11
|
+
BootstrapTable.prototype.changeTitle = function (locale) {
|
12
|
+
$.each(this.options.columns, function (idx, columnList) {
|
13
|
+
$.each(columnList, function (idx, column) {
|
14
|
+
if (column.field) {
|
15
|
+
column.title = locale[column.field];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
19
|
+
|
20
|
+
this.initHeader();
|
21
|
+
this.initBody();
|
22
|
+
this.initToolbar();
|
23
|
+
};
|
24
|
+
|
25
|
+
BootstrapTable.prototype.changeLocale = function (localeId) {
|
26
|
+
this.options.locale = localeId;
|
27
|
+
this.initLocale();
|
28
|
+
this.initPagination();
|
29
|
+
};
|
30
|
+
|
31
|
+
$.fn.bootstrapTable.methods.push('changeTitle');
|
32
|
+
$.fn.bootstrapTable.methods.push('changeLocale');
|
33
|
+
|
34
|
+
}(jQuery);
|
@@ -0,0 +1,88 @@
|
|
1
|
+
/**
|
2
|
+
* @author Homer Glascock <HopGlascock@gmail.com>
|
3
|
+
* @version: v1.0.0
|
4
|
+
*/
|
5
|
+
|
6
|
+
!function ($) {
|
7
|
+
"use strict";
|
8
|
+
|
9
|
+
var sprintf = $.fn.bootstrapTable.utils.sprintf;
|
10
|
+
|
11
|
+
var reInit = function (self) {
|
12
|
+
self.initHeader();
|
13
|
+
self.initSearch();
|
14
|
+
self.initPagination();
|
15
|
+
self.initBody();
|
16
|
+
};
|
17
|
+
|
18
|
+
$.extend($.fn.bootstrapTable.defaults, {
|
19
|
+
showToggleBtn: false,
|
20
|
+
multiToggleDefaults: [], //column names go here
|
21
|
+
});
|
22
|
+
|
23
|
+
$.fn.bootstrapTable.methods.push('hideAllColumns', 'showAllColumns');
|
24
|
+
|
25
|
+
var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
26
|
+
_initToolbar = BootstrapTable.prototype.initToolbar;
|
27
|
+
|
28
|
+
BootstrapTable.prototype.initToolbar = function () {
|
29
|
+
|
30
|
+
_initToolbar.apply(this, Array.prototype.slice.apply(arguments));
|
31
|
+
|
32
|
+
var that = this,
|
33
|
+
$btnGroup = this.$toolbar.find('>.btn-group');
|
34
|
+
|
35
|
+
if (typeof this.options.multiToggleDefaults === 'string') {
|
36
|
+
this.options.multiToggleDefaults = JSON.parse(this.options.multiToggleDefaults);
|
37
|
+
}
|
38
|
+
|
39
|
+
if (this.options.showToggleBtn && this.options.showColumns) {
|
40
|
+
var showbtn = "<button class='btn btn-default hidden' id='showAllBtn'><span class='glyphicon glyphicon-resize-full icon-zoom-in'></span></button>",
|
41
|
+
hidebtn = "<button class='btn btn-default' id='hideAllBtn'><span class='glyphicon glyphicon-resize-small icon-zoom-out'></span></button>";
|
42
|
+
|
43
|
+
$btnGroup.append(showbtn + hidebtn);
|
44
|
+
|
45
|
+
$btnGroup.find('#showAllBtn').click(function () { that.showAllColumns();
|
46
|
+
$btnGroup.find('#hideAllBtn').toggleClass('hidden');
|
47
|
+
$btnGroup.find('#showAllBtn').toggleClass('hidden');
|
48
|
+
});
|
49
|
+
$btnGroup.find('#hideAllBtn').click(function () { that.hideAllColumns();
|
50
|
+
$btnGroup.find('#hideAllBtn').toggleClass('hidden');
|
51
|
+
$btnGroup.find('#showAllBtn').toggleClass('hidden');
|
52
|
+
});
|
53
|
+
}
|
54
|
+
};
|
55
|
+
|
56
|
+
BootstrapTable.prototype.hideAllColumns = function () {
|
57
|
+
var that = this,
|
58
|
+
defaults = that.options.multiToggleDefaults;
|
59
|
+
|
60
|
+
$.each(this.columns, function (index, column) {
|
61
|
+
//if its one of the defaults dont touch it
|
62
|
+
if (defaults.indexOf(column.field) == -1 && column.switchable) {
|
63
|
+
column.visible = false;
|
64
|
+
var $items = that.$toolbar.find('.keep-open input').prop('disabled', false);
|
65
|
+
$items.filter(sprintf('[value="%s"]', index)).prop('checked', false);
|
66
|
+
}
|
67
|
+
});
|
68
|
+
|
69
|
+
reInit(that);
|
70
|
+
};
|
71
|
+
|
72
|
+
BootstrapTable.prototype.showAllColumns = function () {
|
73
|
+
var that = this;
|
74
|
+
$.each(this.columns, function (index, column) {
|
75
|
+
if (column.switchable) {
|
76
|
+
column.visible = true;
|
77
|
+
}
|
78
|
+
|
79
|
+
var $items = that.$toolbar.find('.keep-open input').prop('disabled', false);
|
80
|
+
$items.filter(sprintf('[value="%s"]', index)).prop('checked', true);
|
81
|
+
});
|
82
|
+
|
83
|
+
reInit(that);
|
84
|
+
|
85
|
+
that.toggleColumn(0, that.columns[0].visible, false);
|
86
|
+
};
|
87
|
+
|
88
|
+
}(jQuery);
|
@@ -9,7 +9,8 @@
|
|
9
9
|
'use strict';
|
10
10
|
|
11
11
|
$.extend($.fn.bootstrapTable.defaults, {
|
12
|
-
multipleSearch: false
|
12
|
+
multipleSearch: false,
|
13
|
+
delimeter: " "
|
13
14
|
});
|
14
15
|
|
15
16
|
var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
@@ -17,7 +18,10 @@
|
|
17
18
|
|
18
19
|
BootstrapTable.prototype.initSearch = function () {
|
19
20
|
if (this.options.multipleSearch) {
|
20
|
-
|
21
|
+
if (this.searchText === undefined) {
|
22
|
+
return;
|
23
|
+
}
|
24
|
+
var strArray = this.searchText.split(this.options.delimeter),
|
21
25
|
that = this,
|
22
26
|
f = $.isEmptyObject(this.filterColumns) ? null : this.filterColumns,
|
23
27
|
dataFiltered = [];
|
@@ -1,7 +1,8 @@
|
|
1
1
|
/**
|
2
2
|
* @author Nadim Basalamah <dimbslmh@gmail.com>
|
3
|
-
* @version: v1.
|
3
|
+
* @version: v1.1.0
|
4
4
|
* https://github.com/dimbslmh/bootstrap-table/tree/master/src/extensions/multiple-sort/bootstrap-table-multiple-sort.js
|
5
|
+
* Modification: ErwannNevou <https://github.com/ErwannNevou>
|
5
6
|
*/
|
6
7
|
|
7
8
|
(function($) {
|
@@ -9,11 +10,6 @@
|
|
9
10
|
|
10
11
|
var isSingleSort = false;
|
11
12
|
|
12
|
-
var sort_order = {
|
13
|
-
asc: 'Ascending',
|
14
|
-
desc: 'Descending'
|
15
|
-
};
|
16
|
-
|
17
13
|
var showSortModal = function(that) {
|
18
14
|
var _selector = that.$sortModal.selector,
|
19
15
|
_id = _selector.substr(1);
|
@@ -58,10 +54,10 @@
|
|
58
54
|
sModal += ' </div>';
|
59
55
|
sModal += ' </div>';
|
60
56
|
|
61
|
-
$(
|
57
|
+
$('body').append($(sModal));
|
62
58
|
|
63
59
|
that.$sortModal = $(_selector);
|
64
|
-
var $rows = that.$sortModal.find(
|
60
|
+
var $rows = that.$sortModal.find('tbody > tr');
|
65
61
|
|
66
62
|
that.$sortModal.off('click', '#add').on('click', '#add', function() {
|
67
63
|
var total = that.$sortModal.find('.multi-sort-name:first option').length,
|
@@ -86,7 +82,7 @@
|
|
86
82
|
});
|
87
83
|
|
88
84
|
that.$sortModal.off('click', '.btn-primary').on('click', '.btn-primary', function() {
|
89
|
-
var $rows = that.$sortModal.find(
|
85
|
+
var $rows = that.$sortModal.find('tbody > tr'),
|
90
86
|
$alert = that.$sortModal.find('div.alert'),
|
91
87
|
fields = [],
|
92
88
|
results = [];
|
@@ -123,9 +119,22 @@
|
|
123
119
|
$($alert).remove();
|
124
120
|
}
|
125
121
|
|
126
|
-
that.options.sortName = "";
|
127
|
-
that.onMultipleSort();
|
128
122
|
that.$sortModal.modal('hide');
|
123
|
+
that.options.sortName = '';
|
124
|
+
|
125
|
+
if (that.options.sidePagination === 'server') {
|
126
|
+
|
127
|
+
that.options.queryParams = function(params) {
|
128
|
+
params.multiSort = that.options.sortPriority;
|
129
|
+
return params;
|
130
|
+
};
|
131
|
+
|
132
|
+
that.initServer(that.options.silentSort);
|
133
|
+
return;
|
134
|
+
}
|
135
|
+
|
136
|
+
that.onMultipleSort();
|
137
|
+
|
129
138
|
}
|
130
139
|
});
|
131
140
|
|
@@ -175,34 +184,40 @@
|
|
175
184
|
return 'Multiple Sort';
|
176
185
|
},
|
177
186
|
formatAddLevel: function() {
|
178
|
-
return
|
187
|
+
return 'Add Level';
|
179
188
|
},
|
180
189
|
formatDeleteLevel: function() {
|
181
|
-
return
|
190
|
+
return 'Delete Level';
|
182
191
|
},
|
183
192
|
formatColumn: function() {
|
184
|
-
return
|
193
|
+
return 'Column';
|
185
194
|
},
|
186
195
|
formatOrder: function() {
|
187
|
-
return
|
196
|
+
return 'Order';
|
188
197
|
},
|
189
198
|
formatSortBy: function() {
|
190
|
-
return
|
199
|
+
return 'Sort by';
|
191
200
|
},
|
192
201
|
formatThenBy: function() {
|
193
|
-
return
|
202
|
+
return 'Then by';
|
194
203
|
},
|
195
204
|
formatSort: function() {
|
196
|
-
return
|
205
|
+
return 'Sort';
|
197
206
|
},
|
198
207
|
formatCancel: function() {
|
199
|
-
return
|
208
|
+
return 'Cancel';
|
200
209
|
},
|
201
210
|
formatDuplicateAlertTitle: function() {
|
202
|
-
return
|
211
|
+
return 'Duplicate(s) detected!';
|
203
212
|
},
|
204
213
|
formatDuplicateAlertDescription: function() {
|
205
|
-
return
|
214
|
+
return 'Please remove or change any duplicate column.';
|
215
|
+
},
|
216
|
+
formatSortOrders: function() {
|
217
|
+
return {
|
218
|
+
asc: 'Ascending',
|
219
|
+
desc: 'Descending'
|
220
|
+
};
|
206
221
|
}
|
207
222
|
});
|
208
223
|
|
@@ -323,19 +338,19 @@
|
|
323
338
|
.append($('<td>').text(text))
|
324
339
|
.append($('<td>').append($('<select class="form-control multi-sort-name">')))
|
325
340
|
.append($('<td>').append($('<select class="form-control multi-sort-order">')))
|
326
|
-
|
341
|
+
);
|
327
342
|
|
328
343
|
var $multiSortName = this.$sortModal.find('.multi-sort-name').last(),
|
329
344
|
$multiSortOrder = this.$sortModal.find('.multi-sort-order').last();
|
330
345
|
|
331
|
-
$.each(this.columns, function
|
346
|
+
$.each(this.columns, function(i, column) {
|
332
347
|
if (column.sortable === false || column.visible === false) {
|
333
348
|
return true;
|
334
349
|
}
|
335
350
|
$multiSortName.append('<option value="' + column.field + '">' + column.title + '</option>');
|
336
351
|
});
|
337
352
|
|
338
|
-
$.each(
|
353
|
+
$.each(this.options.formatSortOrders(), function(value, order) {
|
339
354
|
$multiSortOrder.append('<option value="' + value + '">' + order + '</option>');
|
340
355
|
});
|
341
356
|
|
@@ -29,8 +29,18 @@ function alphanum(a, b) {
|
|
29
29
|
return tz;
|
30
30
|
}
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
function stringfy(v) {
|
33
|
+
if (typeof(v) === "number") {
|
34
|
+
v = "" + v;
|
35
|
+
}
|
36
|
+
if (!v) {
|
37
|
+
v = "";
|
38
|
+
}
|
39
|
+
return v;
|
40
|
+
}
|
41
|
+
|
42
|
+
var aa = chunkify(stringfy(a));
|
43
|
+
var bb = chunkify(stringfy(b));
|
34
44
|
|
35
45
|
for (x = 0; aa[x] && bb[x]; x++) {
|
36
46
|
if (aa[x] !== bb[x]) {
|
@@ -8,6 +8,44 @@
|
|
8
8
|
|
9
9
|
'use strict';
|
10
10
|
|
11
|
+
//From MDN site, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
|
12
|
+
var filterFn = function () {
|
13
|
+
if (!Array.prototype.filter) {
|
14
|
+
Array.prototype.filter = function(fun/*, thisArg*/) {
|
15
|
+
'use strict';
|
16
|
+
|
17
|
+
if (this === void 0 || this === null) {
|
18
|
+
throw new TypeError();
|
19
|
+
}
|
20
|
+
|
21
|
+
var t = Object(this);
|
22
|
+
var len = t.length >>> 0;
|
23
|
+
if (typeof fun !== 'function') {
|
24
|
+
throw new TypeError();
|
25
|
+
}
|
26
|
+
|
27
|
+
var res = [];
|
28
|
+
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
|
29
|
+
for (var i = 0; i < len; i++) {
|
30
|
+
if (i in t) {
|
31
|
+
var val = t[i];
|
32
|
+
|
33
|
+
// NOTE: Technically this should Object.defineProperty at
|
34
|
+
// the next index, as push can be affected by
|
35
|
+
// properties on Object.prototype and Array.prototype.
|
36
|
+
// But that method's new, and collisions should be
|
37
|
+
// rare, so use the more-compatible alternative.
|
38
|
+
if (fun.call(thisArg, val, i, t)) {
|
39
|
+
res.push(val);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
return res;
|
45
|
+
};
|
46
|
+
}
|
47
|
+
};
|
48
|
+
|
11
49
|
$.extend($.fn.bootstrapTable.defaults, {
|
12
50
|
reorderableColumns: false,
|
13
51
|
maxMovingRows: 10,
|
@@ -85,7 +123,8 @@
|
|
85
123
|
formatters = [],
|
86
124
|
columns = [],
|
87
125
|
columnsHidden = [],
|
88
|
-
columnIndex = -1
|
126
|
+
columnIndex = -1,
|
127
|
+
optionsColumns = [];
|
89
128
|
that.$header.find('th').each(function (i) {
|
90
129
|
ths.push($(this).data('field'));
|
91
130
|
formatters.push($(this).data('formatter'));
|
@@ -111,6 +150,23 @@
|
|
111
150
|
}
|
112
151
|
|
113
152
|
that.columns = that.columns.concat(columns);
|
153
|
+
|
154
|
+
filterFn(); //Support <IE9
|
155
|
+
$.each(that.columns, function(i, column) {
|
156
|
+
var found = false,
|
157
|
+
field = column.field;
|
158
|
+
that.options.columns[0].filter(function(item) {
|
159
|
+
if(!found && item["field"] == field) {
|
160
|
+
optionsColumns.push(item);
|
161
|
+
found = true;
|
162
|
+
return false;
|
163
|
+
} else
|
164
|
+
return true;
|
165
|
+
})
|
166
|
+
});
|
167
|
+
|
168
|
+
that.options.columns[0] = optionsColumns;
|
169
|
+
|
114
170
|
that.header.fields = ths;
|
115
171
|
that.header.formatters = formatters;
|
116
172
|
that.resetView();
|
@@ -0,0 +1,303 @@
|
|
1
|
+
/**
|
2
|
+
* @author: Jewway
|
3
|
+
* @version: v1.0.0
|
4
|
+
*/
|
5
|
+
|
6
|
+
!function ($) {
|
7
|
+
'use strict';
|
8
|
+
|
9
|
+
function getCurrentHeader(that) {
|
10
|
+
var header = that.$header;
|
11
|
+
if (that.options.height) {
|
12
|
+
header = that.$tableHeader;
|
13
|
+
}
|
14
|
+
|
15
|
+
return header;
|
16
|
+
}
|
17
|
+
|
18
|
+
function getFilterFields(that) {
|
19
|
+
return getCurrentHeader(that).find('[data-filter-field]');
|
20
|
+
}
|
21
|
+
|
22
|
+
function setFilterValues(that) {
|
23
|
+
var $filterElms = getFilterFields(that);
|
24
|
+
if (!$.isEmptyObject(that.filterColumnsPartial)) {
|
25
|
+
$filterElms.each(function (index, ele) {
|
26
|
+
var $ele = $(ele),
|
27
|
+
field = $ele.attr('data-filter-field'),
|
28
|
+
value = that.filterColumnsPartial[field];
|
29
|
+
|
30
|
+
if ($ele.is("select")) {
|
31
|
+
$ele.val(value).trigger('change');
|
32
|
+
}
|
33
|
+
else {
|
34
|
+
$ele.val(value);
|
35
|
+
}
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
function createFilter(that, header) {
|
41
|
+
var enableFilter = false,
|
42
|
+
isVisible,
|
43
|
+
html,
|
44
|
+
timeoutId = 0;
|
45
|
+
|
46
|
+
$.each(that.columns, function (i, column) {
|
47
|
+
isVisible = 'hidden';
|
48
|
+
html = [];
|
49
|
+
|
50
|
+
if (!column.visible) {
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
|
54
|
+
if (!column.filter) {
|
55
|
+
html.push('<div class="no-filter"></div>');
|
56
|
+
} else {
|
57
|
+
var filterClass = column.filter.class ? ' ' + column.filter.class : '';
|
58
|
+
html.push('<div style="margin: 0px 2px 2px 2px;" class="filter' + filterClass + '">');
|
59
|
+
|
60
|
+
if (column.searchable) {
|
61
|
+
enableFilter = true;
|
62
|
+
isVisible = 'visible'
|
63
|
+
}
|
64
|
+
|
65
|
+
switch (column.filter.type.toLowerCase()) {
|
66
|
+
case 'input' :
|
67
|
+
html.push('<input type="text" data-filter-field="' + column.field + '" style="width: 100%; visibility:' + isVisible + '">');
|
68
|
+
break;
|
69
|
+
case 'select':
|
70
|
+
html.push('<select data-filter-field="' + column.field + '" style="width: 100%; visibility:' + isVisible + '"></select>');
|
71
|
+
break;
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
$.each(header.children().children(), function (i, tr) {
|
76
|
+
tr = $(tr);
|
77
|
+
if (tr.data('field') === column.field) {
|
78
|
+
tr.find('.fht-cell').append(html.join(''));
|
79
|
+
return false;
|
80
|
+
}
|
81
|
+
});
|
82
|
+
});
|
83
|
+
|
84
|
+
if (enableFilter) {
|
85
|
+
var $inputs = header.find('input'),
|
86
|
+
$selects = header.find('select');
|
87
|
+
|
88
|
+
|
89
|
+
if ($inputs.length > 0) {
|
90
|
+
$inputs.off('keyup').on('keyup', function (event) {
|
91
|
+
clearTimeout(timeoutId);
|
92
|
+
timeoutId = setTimeout(function () {
|
93
|
+
that.onColumnSearch(event);
|
94
|
+
}, that.options.searchTimeOut);
|
95
|
+
});
|
96
|
+
|
97
|
+
|
98
|
+
$inputs.off('mouseup').on('mouseup', function (event) {
|
99
|
+
var $input = $(this),
|
100
|
+
oldValue = $input.val();
|
101
|
+
|
102
|
+
if (oldValue === "") {
|
103
|
+
return;
|
104
|
+
}
|
105
|
+
|
106
|
+
setTimeout(function () {
|
107
|
+
var newValue = $input.val();
|
108
|
+
|
109
|
+
if (newValue === "") {
|
110
|
+
clearTimeout(timeoutId);
|
111
|
+
timeoutId = setTimeout(function () {
|
112
|
+
that.onColumnSearch(event);
|
113
|
+
}, that.options.searchTimeOut);
|
114
|
+
}
|
115
|
+
}, 1);
|
116
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
if ($selects.length > 0) {
|
120
|
+
$selects.on('select2:select', function (event) {
|
121
|
+
that.onColumnSearch(event);
|
122
|
+
});
|
123
|
+
}
|
124
|
+
} else {
|
125
|
+
header.find('.filter').hide();
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
function initSelect2(that) {
|
130
|
+
var $header = getCurrentHeader(that);
|
131
|
+
|
132
|
+
$.each(that.columns, function (idx, column) {
|
133
|
+
if (column.filter && column.filter.type === 'select') {
|
134
|
+
var $selectEle = $header.find('select[data-filter-field=' + column.field + ']');
|
135
|
+
|
136
|
+
if ($selectEle.length > 0 && !$selectEle.data().select2) {
|
137
|
+
column.filter.data.unshift("");
|
138
|
+
|
139
|
+
var select2Opts = {
|
140
|
+
placeholder: "",
|
141
|
+
allowClear: true,
|
142
|
+
data: column.filter.data,
|
143
|
+
dropdownParent: that.$el.closest(".bootstrap-table")
|
144
|
+
};
|
145
|
+
|
146
|
+
$selectEle.select2(select2Opts);
|
147
|
+
$selectEle.on("select2:unselecting", function (event) {
|
148
|
+
event.preventDefault();
|
149
|
+
$selectEle.val(null).trigger('change');
|
150
|
+
that.searchText = undefined;
|
151
|
+
that.onColumnSearch(event);
|
152
|
+
});
|
153
|
+
}
|
154
|
+
}
|
155
|
+
});
|
156
|
+
}
|
157
|
+
|
158
|
+
$.extend($.fn.bootstrapTable.defaults, {
|
159
|
+
filter: false,
|
160
|
+
filterValues: {}
|
161
|
+
});
|
162
|
+
|
163
|
+
$.extend($.fn.bootstrapTable.COLUMN_DEFAULTS, {
|
164
|
+
filter: undefined
|
165
|
+
});
|
166
|
+
|
167
|
+
var BootstrapTable = $.fn.bootstrapTable.Constructor,
|
168
|
+
_init = BootstrapTable.prototype.init,
|
169
|
+
_initHeader = BootstrapTable.prototype.initHeader,
|
170
|
+
_initSearch = BootstrapTable.prototype.initSearch;
|
171
|
+
|
172
|
+
BootstrapTable.prototype.init = function () {
|
173
|
+
//Make sure that the filtercontrol option is set
|
174
|
+
if (this.options.filter) {
|
175
|
+
var that = this;
|
176
|
+
|
177
|
+
if (!$.isEmptyObject(that.options.filterValues)) {
|
178
|
+
that.filterColumnsPartial = that.options.filterValues;
|
179
|
+
that.options.filterValues = {};
|
180
|
+
}
|
181
|
+
|
182
|
+
this.$el.on('reset-view.bs.table', function () {
|
183
|
+
//Create controls on $tableHeader if the height is set
|
184
|
+
if (!that.options.height) {
|
185
|
+
return;
|
186
|
+
}
|
187
|
+
|
188
|
+
//Avoid recreate the controls
|
189
|
+
if (that.$tableHeader.find('select').length > 0 || that.$tableHeader.find('input').length > 0) {
|
190
|
+
return;
|
191
|
+
}
|
192
|
+
|
193
|
+
createFilter(that, that.$tableHeader);
|
194
|
+
}).on('post-header.bs.table', function () {
|
195
|
+
var timeoutId = 0;
|
196
|
+
|
197
|
+
initSelect2(that);
|
198
|
+
clearTimeout(timeoutId);
|
199
|
+
timeoutId = setTimeout(function () {
|
200
|
+
setFilterValues(that);
|
201
|
+
}, that.options.searchTimeOut - 1000);
|
202
|
+
}).on('column-switch.bs.table', function (field, checked) {
|
203
|
+
setFilterValues(that);
|
204
|
+
});
|
205
|
+
}
|
206
|
+
|
207
|
+
_init.apply(this, Array.prototype.slice.apply(arguments));
|
208
|
+
};
|
209
|
+
|
210
|
+
BootstrapTable.prototype.initHeader = function () {
|
211
|
+
_initHeader.apply(this, Array.prototype.slice.apply(arguments));
|
212
|
+
if (this.options.filter) {
|
213
|
+
createFilter(this, this.$header);
|
214
|
+
}
|
215
|
+
};
|
216
|
+
|
217
|
+
BootstrapTable.prototype.initSearch = function () {
|
218
|
+
_initSearch.apply(this, Array.prototype.slice.apply(arguments));
|
219
|
+
|
220
|
+
var that = this,
|
221
|
+
filterValues = that.filterColumnsPartial;
|
222
|
+
|
223
|
+
// Filter for client
|
224
|
+
if (that.options.sidePagination === 'client') {
|
225
|
+
this.data = $.grep(this.data, function (row, idx) {
|
226
|
+
for (var field in filterValues) {
|
227
|
+
var column = that.columns[$.fn.bootstrapTable.utils.getFieldIndex(that.columns, field)],
|
228
|
+
filterValue = filterValues[field].toLowerCase(),
|
229
|
+
rowValue = row[field];
|
230
|
+
|
231
|
+
rowValue = $.fn.bootstrapTable.utils.calculateObjectValue(
|
232
|
+
that.header,
|
233
|
+
that.header.formatters[$.inArray(field, that.header.fields)],
|
234
|
+
[rowValue, row, idx], rowValue);
|
235
|
+
|
236
|
+
if (column.filterStrictSearch) {
|
237
|
+
if (!($.inArray(field, that.header.fields) !== -1 &&
|
238
|
+
(typeof rowValue === 'string' || typeof rowValue === 'number') &&
|
239
|
+
rowValue.toString().toLowerCase() === filterValue.toString().toLowerCase())) {
|
240
|
+
return false;
|
241
|
+
}
|
242
|
+
} else {
|
243
|
+
if (!($.inArray(field, that.header.fields) !== -1 &&
|
244
|
+
(typeof rowValue === 'string' || typeof rowValue === 'number') &&
|
245
|
+
(rowValue + '').toLowerCase().indexOf(filterValue) !== -1)) {
|
246
|
+
return false;
|
247
|
+
}
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
return true;
|
252
|
+
});
|
253
|
+
}
|
254
|
+
};
|
255
|
+
|
256
|
+
BootstrapTable.prototype.onColumnSearch = function (event) {
|
257
|
+
var field = $(event.currentTarget).attr('data-filter-field'),
|
258
|
+
value = $.trim($(event.currentTarget).val());
|
259
|
+
|
260
|
+
if ($.isEmptyObject(this.filterColumnsPartial)) {
|
261
|
+
this.filterColumnsPartial = {};
|
262
|
+
}
|
263
|
+
|
264
|
+
if (value) {
|
265
|
+
this.filterColumnsPartial[field] = value;
|
266
|
+
} else {
|
267
|
+
delete this.filterColumnsPartial[field];
|
268
|
+
}
|
269
|
+
|
270
|
+
this.options.pageNumber = 1;
|
271
|
+
this.onSearch(event);
|
272
|
+
};
|
273
|
+
|
274
|
+
BootstrapTable.prototype.setFilterData = function (field, data) {
|
275
|
+
var that = this,
|
276
|
+
$header = getCurrentHeader(that),
|
277
|
+
$selectEle = $header.find('select[data-filter-field=\"' + field + '\"]');
|
278
|
+
|
279
|
+
data.unshift("");
|
280
|
+
$selectEle.empty();
|
281
|
+
$selectEle.select2({
|
282
|
+
data: data,
|
283
|
+
placeholder: "",
|
284
|
+
allowClear: true,
|
285
|
+
dropdownParent: that.$el.closest(".bootstrap-table")
|
286
|
+
});
|
287
|
+
|
288
|
+
$.each(this.columns, function (idx, column) {
|
289
|
+
if (column.field === field) {
|
290
|
+
column.filter.data = data;
|
291
|
+
return false;
|
292
|
+
}
|
293
|
+
});
|
294
|
+
};
|
295
|
+
|
296
|
+
BootstrapTable.prototype.setFilterValues = function (values) {
|
297
|
+
this.filterColumnsPartial = values;
|
298
|
+
};
|
299
|
+
|
300
|
+
$.fn.bootstrapTable.methods.push('setFilterData');
|
301
|
+
$.fn.bootstrapTable.methods.push('setFilterValues');
|
302
|
+
|
303
|
+
}(jQuery);
|