Pivot Table Controller

Pivot Table Controller is a Stimulus controller for creating a pivot table from an HTML table.

This is still in the experimental phase of development.

Attributes

HTML Attributes

These are standard HTML attributes (with no prefix) used by Table Filter.

Attribute Element(s) Default Value(s) Description
aria-busy (root element)
false true
false
The controller will set this to true any time it is modifying the DOM of the root element or its children.
You can use the value in your CSS to indicate that work is in progress.
aria-sort th ascending This attribute is added to the column header of the created table that is currently sorted.
ascending Indicates that the column is sorted in ascending order.
descending Indicates that the column is sorted in descending order.

data- Attributes

All of these attributes are prefixed with "data-" in the attribute name.

Attribute Element(s) Default Value(s) Description
controller (any)
pivottable This attribute provides the Pivot Table functionality.
value td This attribute is added to each cell in the created table that holds the pivoted or aggregated data.
It holds the unformatted value of the cell.

data-pivottable- Attributes

Attribute Element(s) Default Value(s) Description
source (root)
The id of the table to use as the source for the pivot table.
Note: This attribute is required for the controller to work properly.
col th
td
This is added by the controller to each column header and cell in the table it creates.
The controller does not use this attribute itself, instead it is available for use by external code.
For example, you could use this attribute for styling the column header.
aggregate This is added to columns that hold aggregated data.
group This is added to columns that hold group data.
value This is added to each column holding pivoted data.
group (root)
Comma separated list of columns to group by.
Example: "column1,column2,column3"
Note: This attribute is required for the controller to work properly.
sort (root)
The column to sort the pivot table by.
Note: This attribute is required for the controller to work properly.
field (root)
The column holding the data to be aggregated.
Note: This attribute is required for the controller to work properly.
operation (root)
sum sum
count
average
The operation to perform on the data.
pivot (root)
The column to pivot the data on.
Note: This attribute is required for the controller to work properly.

Events

pivottable: Events

These are custom events that the controller will fire when it takes certain actions.

All of these events are prefixed by "pivottable:".

Event Parameters Description
initialized Called any time that the controller is initialized.
connected Called any time that the controller is connected.
disconnected Called any time that the controller is disconnected.
building Called as the controller is starting to build the pivot table.
built Called any time that the controller has finished building the pivot table.

Methods

While it is recommended to use the controller via the attributes listed above, the following methods can be called directly if needed.

Method Returns Arguments Event(s) Description
buildPivotTable (rename) Called to build the pivot table.
Note: This method is called automatically when the controller is initialized.
You can call this method to rebuild the pivot table if needed.
Though it is generally not needed to call this method directly as the controller will listen for changes to source table.