Description This example demonstrates how to change the alignment of the values displayed in grid cells of the Angular pivot component. The default behavior is to align the values to the right side of the grid cells. To change the default cells alignment, use the formatSettings align property during the definition of the value fields of the Angular pivot grid. In addition to cells content alignment, the formatSettings object allows you to specify how to format the numbers displayed in the pivot grid cells. For example, you may change the number of digits after the decimal point, the thousands separator, whether negative numbers will be displayed in brackets or with a minus sign, as well as custom prefix and sufix text.
A live Angular example of jqxPivotGrid, the jQWidgets PivotGrid component, with its complete source code below. It is one of 12 jqxPivotGrid demos for Angular.
source property – Gets or sets pivot source adapter used to supply data to the pivot grid.multipleSelectionEnabled property – Gets or sets whether the multiple selection in the pivot grid is enabled or disabled.treeStyleRows property – Gets or sets the rows of the pivot grid are displayed as a tree structure or using classic OLAP style.autoResize property – Gets or sets if the size of pivot grid adjusts automatically to display the entire content.To run it in your own app, install the package with npm install jqwidgets-ng, add these files to a standalone Angular CLI app, and add jqx.base.css and a theme to the styles in angular.json. Getting started with jqxPivotGrid shows the setup step by step.
import { Component } from '@angular/core';
import { jqxPivotGridComponent } from 'jqwidgets-ng/jqxpivotgrid';
import { CommonModule } from '@angular/common';
import { jqxPivotGridModule } from 'jqwidgets-ng/jqxpivotgrid';
@Component({
imports: [CommonModule, jqxPivotGridModule],
selector: 'app-root',
templateUrl: './app.html',
styleUrl: './app.css'
})
export class App {
constructor() {
this.pivotDataSource = this.createPivotDataSource();
}
pivotDataSource: null;
getWidth() : any {
if (document.body.offsetWidth < 850) {
return '90%';
}
return 850;
}
createPivotDataSource(): any {
// prepare sample data
let data = new Array();
let countries =
[
"Germany", "France", "United States", "Italy", "Spain", "Finland", "Canada", "Japan", "Brazil", "United Kingdom", "China", "India", "South Korea", "Romania", "Greece"
];
let dataPoints =
[
"2.25", "1.5", "3.0", "3.3", "4.5", "3.6", "3.8", "2.5", "5.0", "1.75", "3.25", "4.0"
];
for (let i = 0; i < countries.length * 2; i++) {
let row: any = {};
let value = parseFloat(dataPoints[Math.round((Math.random() * 100)) % dataPoints.length]);
row["country"] = countries[i % countries.length];
row["value"] = value;
data[i] = row;
}
// create a data source and data adapter
let source =
{
localdata: data,
datatype: "array",
datafields:
[
{ name: 'country', type: 'string' },
{ name: 'value', type: 'number' }
]
};
let dataAdapter = new jqx.dataAdapter(source);
dataAdapter.dataBind();
// create a pivot data source from the dataAdapter
let pivotDataSource = new jqx.pivot(
dataAdapter,
{
pivotValuesOnRows: false,
rows: [{ dataField: 'country', width: 190 }],
columns: [],
values: [
{ dataField: 'value', width: 200, 'function': 'min', text: 'cells left alignment', formatSettings: { align: 'left', prefix: '', decimalPlaces: 2 } },
{ dataField: 'value', width: 200, 'function': 'max', text: 'cells center alignment', formatSettings: { align: 'center', prefix: '', decimalPlaces: 2 } },
{ dataField: 'value', width: 200, 'function': 'average', text: 'cells right alignment', formatSettings: { align: 'right', prefix: '', decimalPlaces: 2 } }
]
}
);
return pivotDataSource;
}
}
<jqxPivotGrid
[width]="getWidth()"
[height]="400"
[source]="pivotDataSource"
[treeStyleRows] = "true"
[autoResize] = "false"
[multipleSelectionEnabled] = "true"
>
</jqxPivotGrid>