Data Table
Data table component for tabular data display.
Preview
| Name | Status | Updated |
|---|---|---|
| Alpha | Active | 2m ago |
| Beta | Paused | 1h ago |
| Gamma | Active | yesterday |
Arguments
data_table(columns=[{'key': 'name', 'label': 'Name'}, {'key': 'status', 'label': 'Status'}, {'key': 'updated', 'label': 'Updated'}], rows=[{'name': 'Alpha', 'status': 'Active', 'updated': '2m ago'}, {'name': 'Beta', 'status': 'Paused', 'updated': '1h ago'}, {'name': 'Gamma', 'status': 'Active', 'updated': 'yesterday'}])Usage
views.py
python
from djust import LiveView
from djust.decorators import event_handler
from djust.components import DataTable
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = DataTable(columns=[{'key': 'name', 'label': 'Name'}, {'key': 'status', 'label': 'Status'}, {'key': 'updated', 'label': 'Updated'}], rows=[{'name': 'Alpha', 'status': 'Active', 'updated': '2m ago'}, {'name': 'Beta', 'status': 'Paused', 'updated': '1h ago'}, {'name': 'Gamma', 'status': 'Active', 'updated': 'yesterday'}])
@event_handler()
def on_table_sort(self, value, **kwargs):
self.component.sort_by = valuemy_template.html
django
{{ component }}Events this component sends to the view: on_table_sort.
Needs its script on the page: <script src="{% static 'djust_components/data-table.js' %}"></script>. djust ships it; without it the markup renders but does not update in the browser.
Parameters
| Name | Type | Default |
|---|---|---|
| columns | list | None | None |
| rows | list | None | None |
| sort_by | str | '' |
| sort_desc | bool | False |
| sort_event | str — renames the event; identity is `name` | 'on_table_sort' |
| striped | bool | False |
| compact | bool | False |
| 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.data_table | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 5 of this component's classes at line 2463, 2464, 2465, 2466, 2467. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |