Data Grid

Editable spreadsheet-like data grid with cell editing, column resize,

python 14 params

Preview

NameOwnerStatus
AlphaAdaActive
BetaGracePaused
Arguments
data_grid(columns=[{'key': 'name', 'label': 'Name'}, {'key': 'owner', 'label': 'Owner'}, {'key': 'status', 'label': 'Status'}], rows=[{'name': 'Alpha', 'owner': 'Ada', 'status': 'Active'}, {'name': 'Beta', 'owner': 'Grace', 'status': 'Paused'}])

Usage

views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import DataGrid


class MyView(LiveView):
    template_name = "my_template.html"

    def mount(self, request, **kwargs):
        self.component = DataGrid(columns=[{'key': 'name', 'label': 'Name'}, {'key': 'owner', 'label': 'Owner'}, {'key': 'status', 'label': 'Status'}], rows=[{'name': 'Alpha', 'owner': 'Ada', 'status': 'Active'}, {'name': 'Beta', 'owner': 'Grace', 'status': 'Paused'}])

    @event_handler()
    def grid_cell_edit(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: grid_cell_edit.

Needs its script on the page: <script src="{% static 'djust_components/data-grid.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.

Parameters

NameTypeDefault
columnslist | NoneNone
rowslist | NoneNone
row_keystr'id'
edit_eventstr — renames the event; identity is `name`'grid_cell_edit'
resizableboolTrue
frozen_leftint0
frozen_rightint0
stripedboolFalse
compactboolFalse
keyboard_navboolTrue
new_row_eventstr — renames the event; identity is `name`''
delete_row_eventstr — renames the event; identity is `name`''
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.data_gridSubclass it, or pass custom_class, to change how it renders.
cssdjust_components/components.cssDefines 6 of this component's classes at line 1181, 1182, 1183, 1184, 1185, 1191. Override those rules, or the custom properties they read, in a stylesheet loaded after it.