Skip to main content
Version: Next (5.0)

Pivot Table

The pivot table is an analytic component. It loads the rows of a query and lets the user build a report from them: the user drags the fields to the rows and to the columns, picks an aggregation (count, sum, average...) and a renderer (table, heat map...), and the table is calculated in the browser.

PivotTable

When to use it​

Use a pivot table when the user must explore a set of data (group it, total it, cross it) and you do not know in advance which groups they will need. If the report is fixed, a grid with the right query is simpler and supports paging, editing and selection.

The pivot table works on all the rows that the query returns: the grouping and the totals are calculated by the client, not by the server. Because of that:

  • Set max="0" to load every row. When max is not set, the initial load asks the server for a page of rows, like a grid does (30 rows by default, see awe.application.component.grid-rows-per-page in properties), and the pivot would only use those rows.
  • Keep the query to the fields the user needs. Every field of the query becomes a field of the pivot table.

XML skeleton​

<pivot-table id="[pivot-id]" initial-load="query" target-action="[query-id]" max="0"
rows="[fields]" cols="[fields]" aggregator="[aggregator]" aggregation-field="[field]"
style="expand"/>

A pivot table can contain these child elements: context-button, context-separator (see context menu) and dependency (see dependencies).

Attributes​

The attributes are the ones of the screen.xsd schema (see XSD tooling).

Identification and data loading​

AttributeUseTypeDescriptionValues / default
idRequiredStringIdentifier of the pivot table. It must be unique in the screen
styleOptionalStringCSS classes of the pivot tableUse expand to fill the available space (see layout)
initial-loadOptionalStringWhere the data comes from on the initial loadquery (the usual one), enum, value
server-actionOptionalStringServer action that reloads the dataSee the server action list
target-actionOptionalStringQuery that returns the dataQuery identifier
maxOptionalIntegerMaximum number of rows to load0 loads every row. Default: the grid page size (30)
autoloadOptionalBooleanLaunches the target-action when the screen is initializedAngularJS engine only
autorefreshOptionalIntegerLaunches the target-action every X secondsAngularJS engine only

Initial layout of the table​

The user can change all of these in the browser. The attributes only set what the user sees when the table is first drawn.

AttributeUseTypeDescriptionValues / default
rowsOptionalStringFields that start in the rowsField names separated by commas
colsOptionalStringFields that start in the columnsField names separated by commas
rendererOptionalStringRenderer selected at the startTable (default), Table Barchart, Heatmap, Row Heatmap, Col Heatmap
aggregatorOptionalStringAggregator selected at the startSee aggregators. Default: Count
aggregation-fieldOptionalStringField that the aggregator works onA field of the query. Not needed for Count
sort-methodOptionalStringHow the values of a field are sortednatural (default), absolute (by absolute numeric value)
total-row-placementOptionalStringWhere the row with the totals is drawntop, bottom (default)
total-column-placementOptionalStringWhere the column with the totals is drawnleft, right (default)

Number format​

AttributeUseTypeDescriptionValues / default
decimal-numbersOptionalIntegerNumber of decimals of the resultsDefault: the decimals of the numeric options of the application, or 0
thousand-separatorOptionalStringThousands separatorDefault: the one of the numeric options of the application
decimal-separatorOptionalStringDecimal separatorDefault: the one of the numeric options of the application

The three attributes are only applied by the custom aggregators (Custom Sum, Custom Average...) of the AngularJS engine. The standard aggregators format the numbers with the default format of the library, and the custom aggregators exist only when the aggregator attribute is set.

Aggregators​

The aggregator attribute accepts these values:

GroupValues
CountCount, Count Unique Values, List Unique Values
Sum and statisticsSum, Integer Sum, Average, Minimum, Maximum, Sum over Sum, 80% Upper Bound, 80% Lower Bound
FractionsSum as Fraction of Total, Sum as Fraction of Rows, Sum as Fraction of Columns, Count as Fraction of Total, Count as Fraction of Rows, Count as Fraction of Columns
Custom (number format)Custom Sum, Custom Average, Custom Minimum, Custom Maximum, Custom Sum over Sum, Custom 80% Upper Bound, Custom 80% Lower Bound

The custom aggregators are the same as the standard ones but they use the format defined by decimal-numbers, thousand-separator and decimal-separator.

Note: Custom 80% Upper Bound and Custom 80% Lower Bound do not apply the custom number format, and both calculate the upper bound. Use 80% Upper Bound and 80% Lower Bound instead.

Example​

The pivot table of the test screen pivot-test groups the rows of a query by the Als field and sums the Prg1 field. The user can change the groups, the aggregator and the renderer on the screen:

<window label="SCREEN_TEXT_DATA" style="expand" expandible="vertical">
<tag type="div" style="panel-body expand scrollable-both" expandible="vertical">
<pivot-table id="listaDatos" initial-load="query" target-action="QryUniTstId" max="0"
cols="Als" aggregation-field="Prg1" style="expand"/>
</tag>
</window>

To reload the data (for example from a search button, as the test screen does) use the filter action on the pivot table:

<button button-type="submit" label="BUTTON_SEARCH" icon="search" id="ButSch">
<button-action type="filter" target="listaDatos"/>
</button>

This example is the pivot table of the test screen pivot-test (awe-tests/awe-boot and awe-tests/awe-boot-react), with max="0" added.

Changing the groups from the server​

Three client actions change the table from a service or a dependency:

ActionParameterDescription
set-pivot-group-rowsrowsSets the fields of the rows, as a comma-separated list
set-pivot-group-colscolsSets the fields of the columns, as a comma-separated list
set-pivot-sorterssortersSets the order of the values of each field

AngularJS and React engines​

The pivot table is drawn with a different library in each engine, and the XML attributes are not equivalent:

FeatureAngularJS engineReact engine
LibraryPivotTable.js (jQuery), included in AWEreact-pivottable 0.11
rows, colsAppliedApplied
renderer, aggregator, aggregation-fieldAppliedApplied as initial values (Table Barchart included)
sort-methodAppliedApplied
total-row-placement, total-column-placementAppliedNot applied: the totals are always on the right and at the bottom
decimal-numbers, thousand-separator, decimal-separator, custom aggregatorsAppliedApplied: the Custom ... aggregators exist
Actions set-pivot-group-rows, set-pivot-group-cols, set-pivot-sortersAppliedApplied
Context menu (context-button)AvailableAvailable (right click on the pivot table)
autoload, autorefreshAppliedIgnored
Texts of the tableTranslated (English, Spanish, Basque, French)Always in English
Maximum number of values listed in the filter of a fieldawe.application.component.pivot-num-group (5000)pivotOptions.numGroup setting (5000)

In the React engine the XML attributes are initial values: the user can still change the renderer and the aggregator in the table, and those choices are kept while the screen is open. The Table Barchart renderer works in both engines, with the bars of each row (and of the totals row) scaled on their own; negative values, and rows without a positive maximum, draw no bar. The only difference left is the total placement (total-row-placement, total-column-placement): react-pivottable always draws the totals on the right and at the bottom, which is the AngularJS default. The attributes do not break the screen.

Reviewed for AWE 5.