Skip to main content

Pivoting

Pivoting breaks down data in an additional dimension — it transforms distinct values from one column into separate result columns, each showing an aggregate for that value.

Enabling Pivoting

To make a column available for pivoting, set the enablePivot parameter to true on ColDef, otherwise a pivoting attempt on this column will result in a runtime exception.

ColDef priceColumn = ColDef.builder()
.field("price")
.enablePivot(true)
.build();
  • Source code for this grid available here
  • Backend source code available here
Loading grid...

Best Practices - Limiting Column Generation

When pivoting, changes in data, aggregation or pivot columns can cause the number of generated columns to scale exponentially. To prevent this from happening, you can set the pivotMaxGeneratedColumns option on QueryBuilder. Server will count number of columns to be generated in advance.

When the grid generates a number of pivot columns exceeding this value, it halts column generation and throws the OnPivotMaxColumnsExceededException.

this.queryBuilder = QueryBuilder.builder(Entity.class, entityManager)
.colDefs(
// colDefs
)
.pivotMaxGeneratedColumns(1000)
.build();

Example - Limiting Column Generation

  • Column generation is checked on server (limit 10 columns)
  • Adding Bid Type pivoting will result in error on server
  • Source code for this grid available here
  • Backend source code available here
Loading grid...