new PivotTableModel()
A PivotTableModel is used to build a model of a HTML table based on a DataSet and the header, rows, and slice settings.
A PivotTableModel requires the DataSet to be passed in on the Constructor, and then can be built using the build() method.
The PivotTable layout can be controlled using the TableGroup, every time a change is made to the heading, rows, or slice, using the TableGroup API, the PivotTableModel will automatically rebuild its model
Parameters:
Type | Description |
---|---|
data.DataSet |
Example
var pv = new PivotTable(dataset); pv.build(); var tHead = this.pvModel.getTHead(); var tBody = this.pvModel.getTBody(); //Render Rows and Cells for thead for(var i=0; i < tHead.length; i++) { var tr = tHead[i]; var cells = tr.getTableCells(); for(var j=0; i < cells.length; j++) { var th = cells[j]; } } //Render Rows and Cells for tbody
Methods
-
build( [header] [, rows] [, slice])
-
The build method builds the pivot table from the DataSet that was passed in on the constructor.
All the arguments are optional, but if supplied will be used to define which Dimensions are in the Header, Rows, and which have fixed values in the pivot table.
The arguments will be used to create a TableGroup however, if no arguments are provided, a default TableGroup will be built.
Parameters:
Name Type Argument Description header
string <optional>
array of dimension ids in the order for the table header
rows
string <optional>
array of dimension ids in order for the table rows
slice
string <optional>
array of objects { "DimId" : "DimValue" } to define the slices
Examples
Defining the layout
var header = ["FREQ", "TIME_PERIOD"] var rows = ["REF_AREA"] var slice = [{"SEX", "M"}, {"SERIES", "EMP"}] pivotTable.build(header, rows, slice);
Use automatic layout
pivotTable.build(); var layout = pivotTable.getTableGroup();
-
getDataSet()
-
Returns the DataSet which this PivotTableModel was built from
Returns:
- Type
- data.DataSet
-
getTableGroup()
-
Returns the TableGroup object which is used to control which Dimensions are in the Pivot Rows, Columns, and Slice
Returns:
- Type
- data.vis.TableGroup
-
getTBody()
-
Returns the TableRows that make up the tbody
Returns:
- Type
- Array.<data.vis.TableRow>
-
getTHead()
-
Returns the TableRows that make up the thead
Returns:
- Type
- Array.<data.vis.TableRow>
-
update()
-
Updates the PivotTableModel with a new DataSet - this will rebuild the TableRows and TableCells