Repository navigation
Expand file tree
/
Copy pathselect2-filter.html
More file actions
112 lines (103 loc) · 3.09 KB
/
Copy pathselect2-filter.html
File metadata and controls
112 lines (103 loc) · 3.09 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<script>
init({
title: 'Select2 Filter',
desc: 'Use Plugin: <a href="https://github.com/select2/select2" target="_blank">select2</a> and bootstrap-table-select2-filter.',
links: [
'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css',
'bootstrap-table.min.css'
],
scripts: [
'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js',
'bootstrap-table.min.js',
'extensions/select2-filter/bootstrap-table-select2-filter.min.js'
]
})
</script>
<table id="table"></table>
<script>
function getNumberFilterTemplate(fieldId) {
var numberFilterClass = 'numberFilter-' + fieldId
var template = function(bootstrapTable, col, isVisible) {
var search = function(event, value) {
bootstrapTable.searchText = undefined
clearTimeout(bootstrapTable.timeoutId)
bootstrapTable.timeoutId = setTimeout(function() {
bootstrapTable.onColumnSearch(event, fieldId, value)
}, bootstrapTable.options.searchTimeOut)
}
var $el = $('<div class="input-group input-group-sm ' + numberFilterClass + '" style="width: 100%; visibility:' + isVisible + '">' +
'<span class="input-group-addon">></span>' +
'<input type="number" class="form-control">' +
'</div>')
var $input = $el.find('input')
$input.off('keyup').on('keyup', function(event) {
search(event, $(this).val())
})
$input.off('mouseup').on('mouseup', function(event) {
var $input = $(this)
var oldValue = $input.val()
if (oldValue === '') {
return
}
setTimeout(function() {
var newValue = $input.val()
if (newValue === '') {
search(event, newValue)
}
}, 1)
})
return $el
}
return template
}
function mounted() {
var options = {
url: 'json/data1.json',
columns: [{
field: 'id',
title: 'ID',
filter: {
type: 'input'
}
},
{
field: 'name',
title: 'Item Name',
filter: {
type: 'select',
data: []
}
},
{
field: 'price',
title: 'Item Price',
filter: {
type: 'select',
data: ['', '$1', '$2', '$3']
}
},
{
field: 'amount',
title: 'Amount',
width: 200,
filter: {
template: getNumberFilterTemplate('amount'),
setFilterValue: function($filter, field, value) {
if (value) {
$filter.find('input').val(value.value)
}
}
}
}
],
filter: true,
filterTemplate: {
input: function(bootstrapTable, column, isVisible) {
return '<input type="text" class="form-control input-sm" data-filter-field="' + column.field + '" style="width: 100%; visibility:' + isVisible + '">'
}
}
}
var $table = $('#table').bootstrapTable(options)
$table.bootstrapTable('setSelect2Data', 'name', ['', 'item 1', 'item 2', 'item 3'])
}
</script>