Dashboard Grid

CSS Grid layout with draggable and resizable dashboard panels.

python 8 params

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 it
my_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

NameTypeDefault
panelslist | NoneNone
columnsint4
row_heightstr'200px'
gapstr'1rem'
move_eventstr — renames the event; identity is `name`'dashboard_move'
resize_eventstr — renames the event; identity is `name`'dashboard_resize'
custom_classstr''
**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
FilePathNotes
moduledjust.components.components.dashboard_gridSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 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.