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
const minEl = document.getElementById("min");
const maxEl = document.getElementById("max");
const searchEl = document.getElementById("search");
const desiredGenderEl = document.getElementById("desired-gender");
DataTable.ext.search.push(function(settings, data, dataIndex) {
let min = parseInt(minEl.value, 10);
let max = parseInt(maxEl.value, 10);
let age = parseFloat(data[1]) || 0;
const ageIsInRange = (isNaN(min) && isNaN(max))
|| (isNaN(min) && age <= max)
|| (min <= age && isNaN(max))
|| (min <= age && age <= max);
let search = searchEl.value;
const searchIsValid = search?.length === 0 || data.some(d => d.toLowerCase().includes(search.toLowerCase()));
const desiredGenderValid = data[2].includes(desiredGenderEl.value);
return ageIsInRange && searchIsValid && desiredGenderValid;
});
const table = new DataTable("#docs", {
order: [[9, "desc"]],
searching: true,
});
// Changes to the inputs will trigger a redraw to update the table
minEl.addEventListener("input", () => table.draw());
maxEl.addEventListener("input", () => table.draw());
searchEl.addEventListener("input", () => table.draw());
desiredGenderEl.addEventListener("change", () => table.draw());
// filters.appendChild(docs_length);
docs_length.remove();
docs_filter.remove();
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
January 9, 2024