dropdown menu, only refresh graphs on filter changes + don't close when clicking inside

This commit is contained in:
Sam Hadow 2024-02-18 17:11:48 +01:00
parent d06b5aabae
commit 094439eb73

View File

@ -54,6 +54,12 @@ render_graphs_wrapper();
// filters checkboxes
function filters_checkboxes() {
fetch_list().then(function(data){
{
const node = document.getElementById("filters_checkboxes");
while (node.firstChild) {
node.removeChild(node.lastChild);
}
}
const node = d3.select("#filters_checkboxes");
for (const itemlist of data) {
var label = node.append("label");
@ -69,14 +75,18 @@ function filters_checkboxes() {
}
filters_checkboxes()
// listen to filters changes
var checkedBefore = getCheckedCheckboxIds('.checkbox-filters');
$(document).ready(function(){
$('#filters').on('show.bs.dropdown', function () {
console.log("Opening dropdown");
});
$('#filters').on('hidden.bs.dropdown', function () {
// console.log("Dropdown hidden");
refresh_graphs();
const checkedAfter = getCheckedCheckboxIds('.checkbox-filters');
if (!(checkedAfter.every(item => checkedBefore.includes(item)) && checkedBefore.every(item => checkedAfter.includes(item)))) {
refresh_graphs();
}
checkedBefore = checkedAfter;
});
// prevent dropdown menu from closing when clicking inside
$('#filters_checkboxes').on('click', function (e) {
e.stopPropagation();
});
});