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': '$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 moves
my_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

NameTypeDefaultDescription
panelslist | NoneNonelist 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.
columnsint4number of grid columns (default 4)
row_heightstr'200px'CSS row height (default "200px")
gapstr'1rem'CSS gap (default "1rem")
move_eventstr — renames the event; identity is `name`'dashboard_move'djust event on panel drag
resize_eventstr — renames the event; identity is `name`'dashboard_resize'djust event on panel resize
custom_classstr''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
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 2054, 2056, 2057, 2058, 2059, 2060, 2066. Override those rules, or the custom properties they read, in a stylesheet loaded after it.