Pivot Table
Configurable pivot table that aggregates data by row/column dimensions.
Preview
| region | Q1 | Q2 | Total |
|---|---|---|---|
| North | 120 | 150 | 270 |
| South | 90 | 0 | 90 |
| Total | 210 | 150 | 360 |
Arguments
pivot_table(rows='region', cols='quarter', values='revenue', data=[{'region': 'North', 'quarter': 'Q1', 'revenue': 120}, {'region': 'North', 'quarter': 'Q2', 'revenue': 150}, {'region': 'South', 'quarter': 'Q1', 'revenue': 90}])Usage
views.py
python
from djust import LiveView
from djust.components import PivotTable
class MyView(LiveView):
template_name = "my_template.html"
def mount(self, request, **kwargs):
self.component = PivotTable(rows='region', cols='quarter', values='revenue', data=[{'region': 'North', 'quarter': 'Q1', 'revenue': 120}, {'region': 'North', 'quarter': 'Q2', 'revenue': 150}, {'region': 'South', 'quarter': 'Q1', 'revenue': 90}])my_template.html
django
{{ component }}Parameters
| Name | Type | Default |
|---|---|---|
| data | list | None | None |
| rows | str | '' |
| cols | str | '' |
| values | str | '' |
| agg | str | 'sum' |
| title | str | None | None |
| show_totals | bool | True |
| 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.pivot_table | Subclass it, or pass custom_class, to change how it renders. |
| css | djust_components/components.css | Defines 10 of this component's classes at line 2185, 2186, 2188, 2189, 2190, 2191, 2192, 2446. Override those rules, or the custom properties they read, in a stylesheet loaded after it. |