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': '$12,345'}, {'id': 'p2', 'title': 'Users', 'col': 3, 'row': 1, 'width': 2, 'height': 1, 'content': '1,234'}])Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import DashboardGrid
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': '$12,345'}, {'id': 'p2', 'title': 'Users', 'col': 3, 'row': 1, 'width': 2, 'height': 1, 'content': '1,234'}])
@event_handler()
def dashboard_move(self, value=None, **kwargs):
pass # your app acts on 'dashboard_move'; no component state moves
@event_handler()
def dashboard_resize(self, value=None, **kwargs):
pass # your app acts on 'dashboard_resize'; no component state movesmy_template.html
django
{{ component }}Events this component sends to the view: dashboard_move, dashboard_resize.
Needs its script on the page: <script src="{% static 'djust_components/dashboard-grid.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| panels | list | None | None | list of panel dicts with id, title, col, row, width, height, content. ``content`` is text and is escaped. Markup the app built itself can be passed as ``mark_safe(...)`` to the class or the Django tag; the Rust template engine receives list arguments as data and escapes ``content`` either way. |
| columns | int | 4 | number of grid columns (default 4) |
| row_height | str | '200px' | CSS row height (default "200px") |
| gap | str | '1rem' | CSS gap (default "1rem") |
| move_event | str — renames the event; identity is `name` | 'dashboard_move' | djust event on panel drag |
| resize_event | str — renames the event; identity is `name` | 'dashboard_resize' | djust event on panel resize |
| custom_class | str | '' | additional CSS classes |
| **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 2054, 2056, 2057, 2058, 2059, 2060, 2066. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |