Skip to content

Instantly share code, notes, and snippets.

@jjdelc
Created May 22, 2011 08:56
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jjdelc/985283 to your computer and use it in GitHub Desktop.
Save jjdelc/985283 to your computer and use it in GitHub Desktop.
Collapse list_filter in Django admin
;(function($){
ListFilterCollapsePrototype = {
bindToggle: function(){
var that = this;
this.$filterEl.click(function(){
that.$filterList.slideToggle();
});
},
init: function(filterEl) {
this.$filterEl = $(filterEl).css('cursor', 'pointer');
this.$filterList = this.$filterEl.next('ul').hide();
this.bindToggle();
}
}
function ListFilterCollapse(filterEl) {
this.init(filterEl);
}
ListFilterCollapse.prototype = ListFilterCollapsePrototype;
$(document).ready(function(){
$('#changelist-filter').children('h3').each(function(){
var collapser = new ListFilterCollapse(this);
});
});
})(django.jQuery);
@lindyang
Copy link

lindyang commented Oct 5, 2013

hello,I've use the js,and it works well.But if I want this kind of effect:when I refresh my django admin site,the list_filter can collapse while not wide.In which place of the js code should be change.

@peppelinux
Copy link

I wrote a snippets for menu collapse and single element menu collapse.

It's a fork from abyx code, I've just extended it.

If a filter was previously activated the element menu related to this will start as opened.

The filter menu starts closed as default.

https://github.com/peppelinux/Django-snippets/tree/master/django-admin.js-snippets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment