Tree View
Expandable tree view component.
Preview
Arguments
tree_view(nodes=[{'id': 'src', 'label': 'src', 'expanded': True, 'children': [{'id': 'src/app', 'label': 'app.py'}, {'id': 'src/util', 'label': 'util.py'}]}, {'id': 'tests', 'label': 'tests', 'children': []}])Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import TreeView
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = TreeView(nodes=[{'id': 'src', 'label': 'src', 'expanded': True, 'children': [{'id': 'src/app', 'label': 'app.py'}, {'id': 'src/util', 'label': 'util.py'}]}, {'id': 'tests', 'label': 'tests', 'children': []}])
@event_handler()
def tree_expand(self, **kwargs):
self.component.nodes = ... # `toggle_node` — see this component's docs
@event_handler()
def tree_select(self, value, **kwargs):
self.component.selected = valuemy_template.html
django
{{ component }}Events this component sends to the view: tree_expand, tree_select.
Parameters
| Name | Type | Default |
|---|---|---|
| nodes | list | None | None |
| expand_event | str — renames the event; identity is `name` | 'tree_expand' |
| select_event | str — renames the event; identity is `name` | 'tree_select' |
| selected | str | '' |
| custom_class | str | '' |
| **kwargs | — passed to `Component.__init__`: `name=` identifies the instance in the events it sends, `id=` sets `component.id`, and any other keyword is kept as state | — |
Source & styles
| File | Path | Notes |
|---|---|---|
| module | djust.components.components.tree_view | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 8 of this component's classes at line 827, 828, 829, 831, 833, 834, 837, 838. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |