-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
85 lines (70 loc) · 2.45 KB
/
script.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
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
console.log("Hi! If you want to check this project's code you can find it here: https://github.com/ecologismo-argentina")
var publicSpreadsheetUrl = 'https://docs.google.com/spreadsheets/d/1QQKTVEIHFY1OTlYWXgCE2Nw1JrcnKOLARkGtGAPoF5o/pub?output=csv';
var sheet_data;
function init() {
Papa.parse(publicSpreadsheetUrl, {
download: true,
header: true,
complete: function(results) {
var data = results.data
loadSheet(data)
}
})
}
function loadSheet(data, tabletop) {
var data_processed = data.map( x => ['<a href="'+ x["Link"] +'" target="blank">'+ x["Título"] + '</a>', x["Descripción"], x["Provincia"], x["Categorías"], x["Localidad"]] )
var table = $('#example').DataTable({
"bPaginate": false,
"bLengthChange": false,
"bFilter": true,
"bInfo": false,
"bAutoWidth": false,
"data" : data_processed,
"column": [
{ "data" : "Titulo" },
{ "data" : "Descripción" },
{ "data" : "Provincia" },
{ "data" : "Categorías" },
{ "data" : "Localidad" },
],
"columnDefs": [
{
"targets": [2],
"visible": false
},
{
"targets": [3],
"visible": false
},
{
"targets": [4],
"visible": false
},
],
});
var indices = [2,3]
$("#search b").each( function ( i ) {
i = indices[i];
if ($(this).text() !== '') {
var isStatusColumn = (($(this).text() == 'Status') ? true : false);
var select = $('<select><option value="">'+$(this).text()+'</option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
var val = $(this).val();
table.column( i )
//.search( val ? '^'+$(this).val()+'$' : val, true, false ) // Soporta regex esto ;)
.search( val ? $(this).val() : val, true, false )
.draw();
} );
var values = [];
table.column( i ).data().unique().sort().each( function ( d, j ) {
d.split(", ").map( d => values.push(d))
});
values = [...new Set(values)];
values.map( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' );
} );
}
} );
}
init();