A pivot grid for the browser
React pivot grid component for large data sets.
Manage measures (aggregated figures) by dimensions (axises) in rows or columns directly on the grid.
Install zebulon-grid
using npm.
npm install zebulon-grid --save
And in your code:
import ZebulonGrid from 'zebulon-grid'
import React, { Component } from "react";
import ReactDOM from "react-dom";
import ZebulonGrid from "zebulon-grid";
const buildData = (n0, n1, n2) => {
let data = [];
for (let i0 = 0; i0 < n0; i0++) {
for (let i1 = 0; i1 < n1; i1++) {
for (let i2 = 0; i2 < n2; i2++) {
data.push({
totoId: i0,
totoLabel: `toto${i0}`,
titi: i1,
tutu: `tutu${i2}`,
qty: Math.round(50 * Math.random()) + 1,
amt: Math.round(150 * Math.random()) + 3
});
}
}
}
return data;
};
const buildConfiguration = () => ({
measureHeaders: "columns",
width: 1000,
height: 800,
cellHeight: 30,
cellWidth: 100,
dimensions: [
{
id: "toto",
caption: "Toto",
keyAccessor: "totoId",
labelAccessor: "totoLabel",
sort: {
keyAccessor: "totoLabel"
}
},
{
id: "titi",
caption: "Titi",
keyAccessor: "titi"
},
{
id: "tutu",
caption: "Tutu",
keyAccessor: "tutu"
}
],
measures: [
{
valueAccessor: "qty",
id: "qty",
caption: "Quantity",
aggregation: "sum"
},
{
valueAccessor: "amt",
id: "amt",
caption: "Amount",
aggregation: "sum"
}
],
axis:{
columns: ["tutu"],
rows: ["toto", "titi"],
measures: ["qty", "amt"],
measureHeaders: "columns"
}
});
class MyPivotGrid extends Component {
constructor(props) {
super(props);
this.state = {};
}
data = buildData(20, 12, 7);
configuration = buildConfiguration();
render() {
return (
<ZebulonGrid
data={this.data}
configuration={this.configuration}
sizes={{
height: 600,
width: 1000,
cellWidth: 80,
cellHeight: 28,
zoom: 0.9
}}
></ZebulonGrid>
);
}
}
ReactDOM.render(<MyPivotGrid ></MyPivotGrid>, document.getElementById("root"));
Property | Type | Description |
---|---|---|
configuration | PropTypes.object |
Meta description of the multidimensional matrix linked to the data set |
menuFunctions | PropTypes.object |
Custom functions callable from the data cell area contextual menu. |
configurationFunctions | PropTypes.object |
Named custom formats, accessors, sorts and aggregations. |
data | PropTypes.arrayOf(PropTypes.object) |
Data set as an array of objects or a promise. |
pushedData] | PropTypes.arrayOf(PropTypes.object) |
Data set as an array of objects. |
sizes | PropTypes.object) |
sizes of the grid (height, width), zoom, default cell sizes |
The data set (data property) can be either an array of similar objects or a promise that will be resolved as an array of objects.
[
{
totoId: 25,
totoLabel: "toto25",
titi: 3,
tutu: "tutuA",
qty: 100,
amt: 12456
},
{
totoId: 154,
totoLabel: "toto154",
titi: 12,
tutu: "tutuS",
qty: 22,
amt: 2539
},
...
]
Rows can be added dynamically to the data set using the pushedData property.
Changed data cells will be highlighted using the corresponding CSS.
The configuration property is an object describing the pivot grid objects as measure or dimensions and their links with the data set properties.
Accessors are used to get the appropriate values from the data set.
They can be :
dimensions: [
{
id: "toto",
caption: "Toto",
keyAccessor: "totoId",
labelAccessor: "totoLabel",
sort: {
keyAccessor: "totoId"
},
format:x=>x.toUpperCase()
},
{
id: "titi",
caption: "Titi",
keyAccessor: "titi",
},
...]
measures: [
{
valueAccessor: "qty",
id: "qty",
caption: "Quantity",
format: value =>(
<div style={{ color: "blue", textAlign: "right" }}>
{Number(value).toFixed(0)}
</div>
),
aggregation: "sum"
},
{
valueAccessor: "amt",
id: "amt",
caption: "Amount",
aggregation: "sum",
format: "amount"
},...]
{
axis:{
columns: ["titi"],
rows: ["toto"],
measures: ["qty", "amt"],
measureHeaders: "columns"}
}
features = {
dimensions: "enabled",
measures: "enabled",
resize: "enabled",
expandCollapse: "enabled",
totals: "enabled",
filters: "enabled",
sorting: "enabled",
configuration: "enabled"
}
{
formats: {amount:...},
accessors: {...},
sorts: {...},
aggregations: {...}
}
{
dataCellFunctions: {
drilldown: cell => {...},
otherDrilldown: cell => {...}
},
rangeFunctions: { range: range => {...} },
gridFunctions: {...}
}