Skip to content

Commit

Permalink
Merge pull request #557 from normanjaeckel/ExpandTreeByDefault
Browse files Browse the repository at this point in the history
Added option to DraggableMPTTAdmin to expand the tree on first page visit
  • Loading branch information
matthiask committed Apr 7, 2017
2 parents 86b5e14 + c4da901 commit 308040b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/admin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ see below.)
``list_per_page`` is set to 2000 by default (which effectively disables
pagination for most trees).

You may set the attribute ``expand_tree_by_default = True`` in your
DraggableMPTTAdmin to expand the tree on first page visit (default is
False). After this the state of every node (expanded or collapsed) is saved
to the browser storage.


Replacing ``indented_title``
----------------------------
Expand Down
2 changes: 2 additions & 0 deletions mptt/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ class DraggableMPTTAdmin(MPTTModelAdmin):
list_display = ('tree_actions', 'indented_title') # Sane defaults.
list_display_links = ('indented_title',) # Sane defaults.
mptt_level_indent = 20
expand_tree_by_default = False

def tree_actions(self, item):
try:
Expand Down Expand Up @@ -256,6 +257,7 @@ def _tree_context(self, request):
'collapseTree': _('Collapse tree'),
'expandTree': _('Expand tree'),
},
'expandTreeByDefault': self.expand_tree_by_default,
}

def _build_tree_structure(self, queryset):
Expand Down
4 changes: 3 additions & 1 deletion mptt/static/mptt/draggable-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ django.jQuery(function($){
expandOrCollapseNode(treeNode(storedNodes[i]));
}
} else {
collapseTree();
if (!DraggableMPTTAdmin.expandTreeByDefault) {
collapseTree();
}
}
}

Expand Down

0 comments on commit 308040b

Please sign in to comment.