Dashboard Grid
CSS Grid layout with draggable and resizable dashboard panels.
Preview
Revenue
$12,345
Users
1,234
Arguments
dashboard_grid(panels=[{'id': 'p1', 'title': 'Revenue', 'col': 1, 'row': 1, 'width': 2, 'height': 1, 'content': '<p>$12,345</p>'}, {'id': 'p2', 'title': 'Users', 'col': 3, 'row': 1, 'width': 2, 'height': 1, 'content': '<p>1,234</p>'}])Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import DashboardGrid
from django.utils.safestring import mark_safe
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = DashboardGrid(panels=[{'id': 'p1', 'title': 'Revenue', 'col': 1, 'row': 1, 'width': 2, 'height': 1, 'content': mark_safe('<p>$12,345</p>')}, {'id': 'p2', 'title': 'Users', 'col': 3, 'row': 1, 'width': 2, 'height': 1, 'content': mark_safe('<p>1,234</p>')}])
@event_handler()
def dashboard_move(self, value=None, **kwargs):
... # write to self.component; the re-render carries it
@event_handler()
def dashboard_resize(self, value=None, **kwargs):
... # write to self.component; the re-render carries itmy_template.html
django
{{ component }}Events this component sends to the view: dashboard_move, dashboard_resize.
Needs a client hook djust does not ship: dj-hook="DashboardGrid". The markup renders, but the interaction described above is yours to add — register window.djust.hooks.DashboardGrid = { mounted() { … } } before client.js loads (see the hooks guide).
Parameters
| Name | Type | Default |
|---|---|---|
| panels | list | None | None |
| columns | int | 4 |
| row_height | str | '200px' |
| gap | str | '1rem' |
| move_event | str — renames the event; identity is `name` | 'dashboard_move' |
| resize_event | str — renames the event; identity is `name` | 'dashboard_resize' |
| 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.dashboard_grid | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 7 of this component's classes at line 2004, 2006, 2007, 2008, 2009, 2010, 2426. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |