_resources_list.js
2.78 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
jQuery(document).ready(function($) {
if (!$('#resources').length) {
return;
}
var pageL = 8;
var myTable = $('#resources').DataTable({
"pageLength": pageL,
"searchable": false,
"paging": true,
"info": false,
"order": [[2, 'desc']],
"dom": '<"top"<"clear"><"clear">>rt<"bottom"<"clear">p<"clear">>'
});
// use value of search field to filter
var $quicksearch = $('#quicksearch').keyup(function() {
console.log($quicksearch.val());
$('#resources').DataTable().column(0).search($quicksearch.val()).draw();
});
// filter with selects and checkboxes
var $checkboxes = $('.category-filter input');
var filterValue;
$checkboxes.change(function() {
// map input values to an array
var inclusives = [];
// inclusive filters from checkboxes
$checkboxes.each(function(i, elem) {
// if checkbox, use value if checked
if (elem.checked) {
inclusives.push(elem.value);
}
});
// combine inclusive filters
filterValue = inclusives.length ? inclusives.join('|') : '';
console.log(filterValue);
$('#resources').DataTable().column(1).search(filterValue,true,false).draw();
});
// filter with selects and checkboxes
var $typecheckboxes = $('.category-type input');
var typeFilterValue;
$typecheckboxes.change(function() {
// map input values to an array
var inclusives = [];
// inclusive filters from checkboxes
$typecheckboxes.each(function(i, elem) {
// if checkbox, use value if checked
if (elem.checked) {
inclusives.push(elem.value);
}
});
// combine inclusive filters
typeFilterValue = inclusives.length ? inclusives.join('|') : '';
$('#resources').DataTable().column(0).search(typeFilterValue,true,false).draw();
});
$('.sort-button-group').on('click', 'button', function() {
var sortValue = $(this).attr('data-sort-value');
var direction = $(this).attr('data-sort-direction');
var isAscending = (direction == 'asc');
var newDirection = (isAscending) ? 'desc' : 'asc';
console.log(sortValue);
console.log(isAscending);
$(this).attr('data-sort-direction', newDirection);
var span = $(this).find('.glyphicon');
span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
myTable.order([sortValue, newDirection]).draw();
});
$(document).on("click", "#filter-more", function(e) {
e.preventDefault();
$('.filter-group').toggleClass('open');
var span = $(this).find('.glyphicon');
span.toggleClass('glyphicon-chevron-up glyphicon-chevron-down');
});
$(document).on("click", ".flag", function(e) {
$("#nf-field-16").val($(this).data('title'));
});
});