Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions column_toggle/static/column_toggle/column_toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ document.addEventListener("DOMContentLoaded", function () {
field: field,
};
});

// Create the container for the checkboxes
const container = document.createElement("div");
container.classList.add("column-toggle-container");

// Initially hide the checkboxes container
container.style.display = "none";

const shouldShowAllColumns =
!defaultSelectedColumns || defaultSelectedColumns.length === 0;

Expand All @@ -46,6 +51,15 @@ document.addEventListener("DOMContentLoaded", function () {
container.appendChild(label);
});

// Find the toggle link in the HTML
const toggleLink = document.getElementById("toggle-columns-link");
if (toggleLink) {
toggleLink.addEventListener("click", (event) => {
event.preventDefault();
container.style.display = container.style.display === "none" ? "flex" : "none";
});
}

const actionsContainer = document.querySelector("div.actions");
if (actionsContainer) {
actionsContainer.parentNode.insertBefore(
Expand Down Expand Up @@ -83,4 +97,7 @@ document.addEventListener("DOMContentLoaded", function () {
}
localStorage.setItem(storageKey, JSON.stringify(storedSelectedColumns));
}

// Call createColumnToggle with default parameters for testing
createColumnToggle([], 'column-toggle-storage');
});
6 changes: 6 additions & 0 deletions column_toggle/templates/column_toggle/change_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{% extends "admin/change_list.html" %}
{% load i18n %}

{% block extrahead %}
{{ block.super }}
{{ column_toggle_html }}
{% endblock %}

{% block object-tools-items %}
<li><a href="#" id="toggle-columns-link">{% translate 'Columns' %}</a></li>
{{ block.super }}
{% endblock object-tools-items %}