React UI Components Documentation
The React PivotGrid displays summarized data in a multi-dimensional, cross-tabulated view. This guide adds the React PivotGrid (jqxPivotGrid) to an app, then shows how to set its options, handle its events and call its methods.
jqwidgets-scriptsjqwidgets-scripts/jqwidgets-react-tsx/jqxpivotgrid 
In a React project (to start one, see Getting started with React), add the package:
npm install jqwidgets-scripts
import JqxPivotGrid, { jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxpivotgrid';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.base.css';
import 'jqwidgets-scripts/jqwidgets/styles/jqx.tailwind-blue-dark.css';
jqx.base.css is required. The second file is a theme; pick one of the jqx.*.css files (material, fluent, light, dark and more) and pass its name to the theme prop.
The source of the live Pivot Grid Cell Values Alignment demo:
import type { JSX } from 'react';
import { useState } from 'react';
import JqxPivotGrid, { jqx } from 'jqwidgets-scripts/jqwidgets-react-tsx/jqxpivotgrid';
interface DataRow {
country: string;
value: number;
}
function createPivotDataSource(): unknown {
const data: DataRow[] = [];
const countries = [
'Germany',
'France',
'United States',
'Italy',
'Spain',
'Finland',
'Canada',
'Japan',
'Brazil',
'United Kingdom',
'China',
'India',
'South Korea',
'Romania',
'Greece'
];
const 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++) {
const value = parseFloat(dataPoints[Math.round(Math.random() * 100) % dataPoints.length]);
data[i] = { country: countries[i % countries.length], value };
}
const source = {
datafields: [
{ name: 'country', type: 'string' },
{ name: 'value', type: 'number' }
],
datatype: 'array',
localdata: data
};
const dataAdapter = new jqx.dataAdapter(source);
dataAdapter.dataBind();
return new jqx.pivot(dataAdapter, {
columns: [],
pivotValuesOnRows: false,
rows: [{ dataField: 'country', width: 190 }],
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 }
}
]
});
}
function App(): JSX.Element {
const [source] = useState(() => createPivotDataSource());
return (
<JqxPivotGrid
theme="tailwind-blue-dark"
style={{ width: 800, height: 400 }}
source={source}
treeStyleRows
autoResize={false}
multipleSelectionEnabled
/>
);
}
export default App;Options are props. Keep objects such as the data adapter and the columns stable across renders with useMemo, so the component does not reload them.
Each event is a prop named on plus the event name with a capital first letter. For example, pivotitemexpanding: This event is triggered when a pivot item is expanding.
const handlePivotitemexpanding = (event: any): void => {
console.log(event.args);
};
return <JqxPivotGrid onPivotitemexpanding={handlePivotitemexpanding} />;
Call methods through a ref. For example, refresh: Refreshes the content of the pivot grid component
import { useRef } from 'react';
const myPivotGrid = useRef<JqxPivotGrid>(null);
const onClick = () => {
myPivotGrid.current!.refresh();
};
return <JqxPivotGrid ref={myPivotGrid} />;
Every component also has setOptions({ … }) and getOptions('name'), to change or read options after the first render.