fabiocaccamo / django-admin-interface

:superhero: :zap: django's default admin interface with superpowers - customizable themes, popup windows replaced by modals and many other features.
MIT License
1.74k stars 178 forks source link

Collapsible filters in admin listings #252

Open morlandi opened 1 year ago

morlandi commented 1 year ago

Sometime you need to display many columns in the listing, and the horizontal space taken up by the filters results in additional horizontal scrolling which might be inconvenient.

In these situations, the possibility to (optionally) collapse the filters could help; mush like django-grappelli does:

Screenshot 2023-01-31 at 16 48 45 Screenshot 2023-01-31 at 16 46 30

Fund with Polar

fabiocaccamo commented 1 year ago

@morlandi cool suggestion!

smunoz-ml commented 1 year ago

This is similar to what I have suggested in #163!

fabiocaccamo commented 1 year ago

@smunoz-ml true, even if at UI level, having the filter collapsible to the right seems to be more complicated than having it in an absolute position above the changelist.

morlandi commented 1 year ago

@smunoz-ml true, even if at UI level, having the filter collapsible to the right seems to be more complicated than having it in an absolute position above the changelist.

I do agree on this point, partly because the django-grappelli solution is familiar to me and therefore I'm used to it, but above all because having the filters under your nose (even when collapsed they act as a placeholder), is more intuitive compared to an anonymous button.

smunoz-ml commented 1 year ago

Whatever is easier for you @fabiocaccamo or whomever is going to implement this feature. I suggested the solution of collapsing to the right like the left menu because the left menu is already implemented and I thought that the implementation of the same feature on the right side would be easier. But @morlandi's solution also works for me!

merwok commented 1 year ago

Sidebar collapsing would look better and be more usable than the button style in the screenshot! (It looks like a dropdown that shows more dropdowns + the filters are not visible after applying one?)

morlandi commented 1 year ago

The real challenge here is to implement this without interfering too much with Django admin templates .. so the solution can survive across future Django releases ;)

I am available to collaborate in the implementation perhaps with some strategic suggestions from the author @fabiocaccamo , or at the very least to test a temporary solution during development

fabiocaccamo commented 1 year ago

@morlandi if you want to work on a PR for this, I will be glad to discuss it together.

I would opt for the "Grappelli" solution, it seems to me the better at UX level and also easier to develop/maintain in the long term.

fabiocaccamo commented 1 month ago

Some time ago I did some tests, I paste what I did here, so I can delete the file from my desktop :)

/* solution 1 */
.admin-interface .module.filtered #changelist-filter {
    position: fixed;
    z-index: 50;
    box-shadow: 0px 4px 16px rgba(0,0,0,0.2);
    bottom: 40px;
    right: 40px;
    top: auto;
    max-width: 240px;
    margin: 0;
    padding: 0;
    max-height: calc(100% - 115px);
}

.admin-interface .module.filtered #changelist-filter > h2 {
    position: sticky;
    top: 0;
    z-index: 10;
    border: 1px solid rgba(255,255,255,0.3);
    border-bottom: none;
    cursor: pointer;
}

/* collapsed */
.admin-interface .module.filtered #changelist-filter {
    height: 35px;
    overflow: hidden;
}

/* solution 2 */
.admin-interface .module.filtered #changelist-filter {
    margin-left: -240px;
    height: 34px;
    overflow: hidden;
    cursor: pointer;
    margin-top: 5px;
    box-shadow: 4px 4px 16px rgba(0,0,0,0.6);
}
EricPobot commented 6 days ago

@fabiocaccamo Thanks for your suggestions.

I've used them in the following override of the change_list.html template :

{% extends "admin/change_list.html" %}

{% block extrastyle %}
    {{ block.super }}

    <style>
        #changelist-filter {
            margin-top: 5px;
            box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.6);

            h2 {
                cursor: pointer;
            }
        }

        #changelist-filter.collapsed {
            height: 34px !important;
            overflow-y: hidden !important;
            margin-left: -240px;
        }
    </style>
{% endblock %}

{% block footer %}
    {{ block.super }}

    <script>
        const changelistFilterElt = document.getElementById("changelist-filter");

        changelistFilterElt.querySelector("h2").addEventListener("click", () => {
            changelistFilterElt.classList.toggle("collapsed");
        });
    </script>
{% endblock %}

The toggling script needs to be put in the footer block to ensure it is included at the very end of the HTML code, so that the filter container element is defined when the initialization JS code is executed.

It seems to work fine in Django 5.x, even with django-admin-interface addon.