-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunction.js
40 lines (35 loc) · 1.17 KB
/
function.js
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
$(document).ready(function() {
var table = $('#example').DataTable( {
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
} );
column.data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' );
} );
} );
}
} );
table.on('draw', function () {
table.columns().indexes().each( function ( idx ) {
var select = $(table.column( idx ).footer()).find('select');
if ( select.val() === '' ) {
select
.empty()
.append('<option value=""/>');
table.column(idx, {search:'applied'}).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' );
} );
}
} );
} );
} );