Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGridPremium] Pivoting PoC #9877

Draft
wants to merge 214 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
214 commits
Select commit Hold shift + click to select a range
4c8a656
add basic demo
cherniavskii Jul 24, 2023
4a03bd1
Merge branch 'master' into pivoting
cherniavskii Aug 1, 2023
7584aed
move hook to the package
cherniavskii Aug 1, 2023
b000b90
docs:api
cherniavskii Aug 1, 2023
123eea7
support multiple values
cherniavskii Aug 1, 2023
ba605bb
avoid duplicating columns
cherniavskii Aug 2, 2023
bdcf7af
Merge branch 'master' into pivoting
cherniavskii Aug 3, 2023
1e1f764
fix column name
cherniavskii Aug 3, 2023
e59850c
support pivoting without pivot columns
cherniavskii Aug 3, 2023
0c17229
add pivot model editor
cherniavskii Aug 3, 2023
08e89b1
fix ts error
cherniavskii Aug 3, 2023
3844829
Merge branch 'master' into pivoting
cherniavskii Aug 3, 2023
b5b08fb
move GridPivotModelEditor to the package
cherniavskii Aug 3, 2023
19f0c48
Merge branch 'master' into pivoting
cherniavskii Aug 4, 2023
049fc4e
Merge branch 'master' into pivoting
cherniavskii Aug 19, 2023
eaea9b1
support two pivoting columns
cherniavskii Aug 21, 2023
d001ac9
add second column pivot
cherniavskii Aug 21, 2023
eaae5df
fix some of generated pivot columns missing
cherniavskii Aug 22, 2023
3c6ecc4
sort pivot columns
cherniavskii Aug 22, 2023
8fd2fdb
Merge branch 'master' into pivoting
cherniavskii Aug 22, 2023
0204aba
add third pivot column to the movies demo
cherniavskii Aug 23, 2023
af58582
fix some column groups not being sorted
cherniavskii Aug 23, 2023
38dfd5e
add rating colDef
cherniavskii Aug 23, 2023
1d343f7
only consider filtered rows for pivoting
cherniavskii Aug 23, 2023
aa7a881
update pivot model
cherniavskii Aug 23, 2023
0f25eb0
support different sort orders for pivot columns
cherniavskii Aug 23, 2023
25a80ab
Merge branch 'master' into pivoting
cherniavskii Aug 28, 2023
a0c527e
allow to change the aggregation functions for values
cherniavskii Aug 28, 2023
0fff6c8
do not allow to expand leaf rows in pivot mode
cherniavskii Aug 28, 2023
2c88d8c
fix proptype warning
cherniavskii Aug 28, 2023
a65ab5a
restore the grid state after disabling pivoting
cherniavskii Aug 29, 2023
323ebf0
Merge branch 'master' into pivoting
cherniavskii Aug 29, 2023
fcf3904
Merge branch 'master' into pivoting
cherniavskii Aug 31, 2023
5da92c2
allow to change pivot columns sorting order
cherniavskii Aug 31, 2023
fe0c896
Merge branch 'master' into pivoting
cherniavskii Sep 4, 2023
d52f126
enable pivot by default
cherniavskii Sep 5, 2023
1f0ab47
update editor layout
cherniavskii Sep 4, 2023
09a2160
move movies demo to the top
cherniavskii Sep 5, 2023
a96d09a
update pivot model editor layout
cherniavskii Sep 4, 2023
43341af
Merge branch 'master' into pivoting
cherniavskii Sep 6, 2023
587b58f
Merge branch 'master' into pivoting
cherniavskii Sep 6, 2023
888c852
Merge branch 'master' into pivoting
cherniavskii Sep 8, 2023
7642843
do not show zero values in pivot mode
cherniavskii Sep 8, 2023
fe85445
fix ts error
cherniavskii Sep 8, 2023
3ed20a3
fix state persistence not working
cherniavskii Sep 8, 2023
eea700c
show aggregation footer
cherniavskii Sep 8, 2023
10abd2e
update docs
cherniavskii Sep 8, 2023
7fa194c
fix state export being called while in pivot mode
cherniavskii Sep 8, 2023
c596efe
Merge branch 'master' into pivoting
cherniavskii Sep 15, 2023
9c6425a
Merge branch 'next' into pivoting
cherniavskii Jan 26, 2024
e4ced3a
update demos
cherniavskii Jan 26, 2024
9d9f7ea
add missing type import
cherniavskii Jan 26, 2024
ac1b796
render empty value for avg aggregation if sum === 0
cherniavskii Jan 26, 2024
7ad1da3
docs:api
cherniavskii Jan 26, 2024
b29e594
fix pivoting skipping some values when calculating aggregation
cherniavskii Jan 29, 2024
ac3981d
Merge branch 'next' into pivoting
cherniavskii Jan 29, 2024
d6fc77a
use value formatter from the original column in pivot mode
cherniavskii Jan 29, 2024
b78ab0e
Merge branch 'next' into pivoting
cherniavskii Feb 12, 2024
34d1be4
fix merge issues
cherniavskii Feb 12, 2024
4b58289
copy valueGetter and valueFormatter from original columns
cherniavskii Feb 13, 2024
2d15aeb
add side panel for pivoting
cherniavskii Feb 13, 2024
11f87e9
add drag and drop
cherniavskii Feb 13, 2024
235df33
Merge branch 'next' into pivoting
cherniavskii Feb 29, 2024
8bf31ea
Merge branch 'next' into pivoting
cherniavskii Mar 4, 2024
92fb138
add drag handles
cherniavskii Mar 4, 2024
f921d52
add dropover effect
cherniavskii Mar 4, 2024
bacd632
use theme colors
cherniavskii Mar 4, 2024
b8ef780
use headerName if available
cherniavskii Mar 4, 2024
b091c89
style section headers
cherniavskii Mar 4, 2024
fa8de33
use auto-animate
cherniavskii Mar 4, 2024
7d9b61b
Merge branch 'next' into pivoting
cherniavskii Mar 5, 2024
232023f
update yarn.lock
cherniavskii Mar 5, 2024
1f1ff0e
support fields reorder
cherniavskii Mar 5, 2024
ba64958
improve spacing styles
cherniavskii Mar 5, 2024
192d0fa
Merge branch 'next' into pivoting
cherniavskii Mar 14, 2024
73a7117
Merge branch 'master' into pivoting
cherniavskii Mar 21, 2024
8f981a6
Merge branch 'master' into pivoting
cherniavskii Apr 1, 2024
0ae98cc
move useResize hook to a separate file
cherniavskii Apr 1, 2024
d3cac44
use pointer events for pivot panel resizing
cherniavskii Apr 1, 2024
e7de4da
use setPointerCapture instead of attaching events to document
cherniavskii Apr 1, 2024
4cd221d
Merge branch 'master' into pivoting
cherniavskii Apr 6, 2024
91aa1fb
fix import
cherniavskii Apr 6, 2024
acf1bf6
add delete button
cherniavskii Apr 6, 2024
8068759
fix markdown page build
cherniavskii Apr 8, 2024
158d151
Merge branch 'master' into pivoting
cherniavskii Apr 15, 2024
17ae173
do not sort column groups if sort is undefined
cherniavskii Apr 15, 2024
de1cbc9
allow changing sorting direction for column fields
cherniavskii Apr 15, 2024
6a98e58
add select for aggregation function
cherniavskii Apr 15, 2024
96bbd9d
Merge branch 'master' into pivoting
cherniavskii Apr 24, 2024
98d96d4
update pnpm-lock
cherniavskii Apr 24, 2024
446d9b5
Merge branch 'master' into pivoting
cherniavskii Apr 27, 2024
65c9b36
do not reset the key on the data grid
cherniavskii Apr 29, 2024
d1dc4f5
Merge branch 'master' into pivoting
cherniavskii Apr 29, 2024
b0dd454
fix state restoration when pivot goes off
cherniavskii Apr 29, 2024
a5827be
useEnhancedEffect
cherniavskii Apr 29, 2024
ad08a73
Merge branch 'master' into pivoting
cherniavskii May 20, 2024
d147b5c
update pnpm lock
cherniavskii May 20, 2024
8be6fb2
remove workaround
cherniavskii May 20, 2024
f735e52
Merge branch 'master' into pivoting
cherniavskii Jun 7, 2024
ab301ce
update pnpm lock
cherniavskii Jun 7, 2024
b70b71c
get rows and columns data from the grid state and properly restore it
cherniavskii Jun 10, 2024
5ff16d7
Merge branch 'master' into pivoting
cherniavskii Jun 13, 2024
e430f3f
update pnpm lock
cherniavskii Jun 13, 2024
9012d05
add commodities demo
cherniavskii Jun 13, 2024
16e376e
tweak pivot panel styles
cherniavskii Jun 13, 2024
f5778d6
remove experiments page
cherniavskii Jun 14, 2024
3c6697d
sticky column groups
cherniavskii Jun 14, 2024
b8fcee0
only make column groups sticky
cherniavskii Jun 14, 2024
2d8b99a
update demo
cherniavskii Jun 14, 2024
7b01346
pass pivotParams prop
cherniavskii Jun 14, 2024
12c2a23
fix ts issues
cherniavskii Jun 14, 2024
45ea253
remove old editor
cherniavskii Jun 14, 2024
6d65e8d
docs:api
cherniavskii Jun 14, 2024
ed6b57d
proptypes
cherniavskii Jun 14, 2024
2850d37
lint
cherniavskii Jun 14, 2024
134fb7f
Merge branch 'master' into pivoting
cherniavskii Jun 19, 2024
d7886ed
Merge branch 'master' into pivoting
cherniavskii Jun 20, 2024
67a5551
Merge branch 'master' into pivoting
cherniavskii Jul 1, 2024
9fa2113
improve panel spacing
KenanYusuf Jul 10, 2024
acb85c9
update pivot panel ui
KenanYusuf Aug 2, 2024
d63f0a1
Add some sidebar primitives and style drag elements
KenanYusuf Aug 2, 2024
9ef1960
move pivot sections into their own container
KenanYusuf Aug 2, 2024
d2c39ed
improve component structure and update panel design
KenanYusuf Aug 14, 2024
1ac1eed
fix item animation
KenanYusuf Aug 14, 2024
42ae07e
add pivot menu
KenanYusuf Aug 15, 2024
64097df
Merge branch 'master' into pivoting
KenanYusuf Aug 15, 2024
956ba69
update pnpm-lock.yaml
KenanYusuf Aug 15, 2024
8281739
simplify field moving handlers
KenanYusuf Aug 16, 2024
b6313b6
Merge remote-tracking branch 'mui/master' into pivoting
cherniavskii Sep 2, 2024
a9cd235
update pnpm lock
cherniavskii Sep 2, 2024
45a4482
Merge branch 'master' into pivoting
KenanYusuf Sep 4, 2024
954a2e7
aggregation select styles
KenanYusuf Sep 4, 2024
512cc7f
change sort select to sort icon to match column headers
KenanYusuf Sep 5, 2024
6021f52
persist sort and aggFunc state across reorders
KenanYusuf Sep 5, 2024
61d77ef
open columns in sidebar
KenanYusuf Sep 12, 2024
48684ef
Merge branch 'master' into pivoting
cherniavskii Oct 3, 2024
42d02d6
Merge branch 'master' into pivoting
cherniavskii Oct 27, 2024
932b078
remove dead code
cherniavskii Oct 28, 2024
c60e5f3
use original columns for filtering in the pivot mode
cherniavskii Oct 28, 2024
e51e407
Merge branch 'master' into pivoting
cherniavskii Oct 28, 2024
e625753
Merge branch 'master' into pivoting
cherniavskii Dec 5, 2024
7df1d3f
update lockfile
cherniavskii Dec 5, 2024
bb29cb5
perf: use map instead of object lookup + find
cherniavskii Dec 5, 2024
a61ce96
perf: reduce memory allocations
cherniavskii Dec 5, 2024
e95acb5
perf: avoid double loop
cherniavskii Dec 5, 2024
f2852f8
use map for lookup
cherniavskii Dec 5, 2024
d64f66e
Merge branch 'master' into pivoting
cherniavskii Dec 16, 2024
55c0a94
update lockfile
cherniavskii Dec 16, 2024
1f8a842
Merge branch 'master' into pivoting
cherniavskii Dec 18, 2024
82f380a
update lockfile
cherniavskii Dec 18, 2024
338a2dc
useState => useMemo
cherniavskii Dec 18, 2024
5771929
fix: show row expansion icon in grouping row cell
cherniavskii Dec 19, 2024
18d91ec
fix: do not hide grouping column
cherniavskii Dec 19, 2024
9bfd130
do not include grouping columns as fields available in pivot panel
cherniavskii Dec 19, 2024
3162b44
fix runtime error
cherniavskii Dec 19, 2024
fa7137a
Merge branch 'master' into pivoting
cherniavskii Dec 19, 2024
b8ebf2c
Merge branch 'master' into pivoting
cherniavskii Dec 19, 2024
150fee2
fix emotion warning
cherniavskii Dec 19, 2024
c21ff33
perf: optimize aggregation lookup creation
cherniavskii Dec 20, 2024
4c4fda1
perf: optimize group aggregation when using a lot of aggregation fields
cherniavskii Dec 20, 2024
e2735d4
Merge branch 'master' into pivoting
cherniavskii Dec 20, 2024
abcebe5
Merge branch 'master' into pivoting
cherniavskii Dec 23, 2024
e732110
proptypes
cherniavskii Dec 23, 2024
2b18359
types + lint
cherniavskii Dec 23, 2024
d34e2fb
Merge branch 'master' into pivoting
cherniavskii Dec 23, 2024
65b0954
fix pivot panel not opening
cherniavskii Dec 23, 2024
fb81d41
fix types
cherniavskii Dec 23, 2024
e44060e
docs:api
cherniavskii Dec 23, 2024
5a6f2b9
Merge branch 'master' into pivoting
cherniavskii Dec 26, 2024
3d808b6
fix pivoting not working with empty pivot columns
cherniavskii Dec 26, 2024
72c92cb
add unit test
cherniavskii Dec 26, 2024
28db11c
add unit test
cherniavskii Dec 26, 2024
8587ce7
add financial demo
cherniavskii Dec 26, 2024
329d35a
fixed pivot by derived values
cherniavskii Dec 26, 2024
e38b3f7
fix: add missing test helper
cherniavskii Dec 26, 2024
21047f2
add unit test
cherniavskii Dec 27, 2024
d0ca55b
update financial demo
cherniavskii Dec 27, 2024
8ea01dd
Merge branch 'master' into pivoting
cherniavskii Dec 30, 2024
7b534c8
Merge branch 'master' into pivoting
cherniavskii Dec 30, 2024
17aac94
move useMounted hook to x-internals package
cherniavskii Dec 30, 2024
62156c2
support initial pivot mode for sync data
cherniavskii Dec 30, 2024
8aae785
support initial pivot mode for async data
cherniavskii Dec 30, 2024
aad64e1
fix regression tests error
cherniavskii Dec 31, 2024
5d75da1
Merge remote-tracking branch 'mui/master' into pivoting
cherniavskii Dec 31, 2024
8631835
Merge branch 'master' into pivoting
cherniavskii Jan 2, 2025
edcd4af
Merge branch 'master' into pivoting
cherniavskii Jan 7, 2025
fc11d9d
Merge branch 'master' into pivoting
cherniavskii Jan 8, 2025
588fa9b
fix ts error
cherniavskii Jan 8, 2025
90ec99d
fix ts error
cherniavskii Jan 8, 2025
ff1ed84
Merge branch 'master' into pivoting
cherniavskii Jan 9, 2025
0c5d10b
set column group header size
KenanYusuf Jan 21, 2025
58558d5
Merge branch 'master' into pivoting
cherniavskii Jan 30, 2025
3cafb80
docs:api
cherniavskii Jan 30, 2025
53b3f14
ui updates
KenanYusuf Jan 31, 2025
4697253
fixes
KenanYusuf Jan 31, 2025
30d620e
fix
KenanYusuf Jan 31, 2025
d110cff
scroll shadows
KenanYusuf Jan 31, 2025
4d5c84c
field search
KenanYusuf Jan 31, 2025
db08a52
improve typography
KenanYusuf Jan 31, 2025
52150c4
Merge branch 'master' into pivoting
KenanYusuf Feb 3, 2025
e247da8
minor fixes
KenanYusuf Feb 3, 2025
b749276
field visibility
KenanYusuf Feb 5, 2025
298b62f
Merge branch 'master' into pivoting
cherniavskii Feb 7, 2025
b5a728a
fix missing columns on pivot model change
cherniavskii Feb 7, 2025
c44e0cf
fix failing tests
cherniavskii Feb 7, 2025
7b698b0
autogenerate year and quarter columns for dates
cherniavskii Feb 7, 2025
faed8ff
fix ts error
cherniavskii Feb 10, 2025
d546817
Merge branch 'master' into pivoting
cherniavskii Feb 10, 2025
032f3b6
column management
KenanYusuf Feb 10, 2025
2b1f97d
make fields always available
KenanYusuf Feb 10, 2025
3efbc9a
minor changes
KenanYusuf Feb 10, 2025
91417a2
Merge branch 'master' into pivoting
KenanYusuf Feb 12, 2025
07f97a0
fix checkbox styles
KenanYusuf Feb 12, 2025
52a8ff6
Merge branch 'master' into pivoting
KenanYusuf Feb 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data/data-grid/aggregation/aggregation.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The following snippets build on the demo above to show various use cases for the
// Aggregate the root group in the top-level footer
// and the other groups in their grouping row
// (default behavior)
getAggregationPosition=(groupNode) => (groupNode == null ? 'footer' : 'inline'),
getAggregationPosition={(groupNode) => (groupNode.depth === -1 ? 'footer' : 'inline')}

// Aggregate all the groups in their grouping row;
// the root will not be aggregated
Expand Down
67 changes: 67 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingBasic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
unstable_useGridPivoting,
} from '@mui/x-data-grid-premium';

const initialRows = [
{ id: 1, product: 'Product 1', type: 'Type A', price: 10, quantity: 2 },
{ id: 2, product: 'Product 2', type: 'Type A', price: 12, quantity: 3 },
{ id: 3, product: 'Product 3', type: 'Type B', price: 8, quantity: 1 },
{ id: 4, product: 'Product 4', type: 'Type C', price: 20, quantity: 8 },
];

const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});

const initialColumns = [
{ field: 'product' },
{ field: 'type' },
{
field: 'price',
valueFormatter: (value) => {
if (!value) {
return '';
}
return currencyFormatter.format(value);
},
},
{ field: 'quantity' },
];

export default function GridPivotingBasic() {
const apiRef = useGridApiRef();

const [pivotModel, setPivotModel] = React.useState({
rows: [{ field: 'type' }],
columns: [],
values: [{ field: 'price', aggFunc: 'sum' }],
});

const [isPivotMode, setIsPivotMode] = React.useState(false);

const pivotParams = unstable_useGridPivoting({
apiRef,
pivotModel,
onPivotModelChange: setPivotModel,
pivotMode: isPivotMode,
onPivotModeChange: setIsPivotMode,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPremium
rows={initialRows}
columns={initialColumns}
pivotParams={pivotParams}
apiRef={apiRef}
columnGroupHeaderHeight={36}
/>
</div>
);
}
70 changes: 70 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingBasic.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
GridColDef,
GridRowModel,
unstable_useGridPivoting,
Unstable_GridPivotModel as PivotModel,
} from '@mui/x-data-grid-premium';

const initialRows: GridRowModel[] = [
{ id: 1, product: 'Product 1', type: 'Type A', price: 10, quantity: 2 },
{ id: 2, product: 'Product 2', type: 'Type A', price: 12, quantity: 3 },
{ id: 3, product: 'Product 3', type: 'Type B', price: 8, quantity: 1 },
{ id: 4, product: 'Product 4', type: 'Type C', price: 20, quantity: 8 },
];

const currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 0,
maximumFractionDigits: 0,
});

const initialColumns: GridColDef[] = [
{ field: 'product' },
{ field: 'type' },
{
field: 'price',
valueFormatter: (value) => {
if (!value) {
return '';
}
return currencyFormatter.format(value);
},
},
{ field: 'quantity' },
];

export default function GridPivotingBasic() {
const apiRef = useGridApiRef();

const [pivotModel, setPivotModel] = React.useState<PivotModel>({
rows: [{ field: 'type' }],
columns: [],
values: [{ field: 'price', aggFunc: 'sum' }],
});

const [isPivotMode, setIsPivotMode] = React.useState(false);

const pivotParams = unstable_useGridPivoting({
apiRef,
pivotModel,
onPivotModelChange: setPivotModel,
pivotMode: isPivotMode,
onPivotModeChange: setIsPivotMode,
});

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPremium
rows={initialRows}
columns={initialColumns}
pivotParams={pivotParams}
apiRef={apiRef}
columnGroupHeaderHeight={36}
/>
</div>
);
}
7 changes: 7 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingBasic.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<DataGridPremium
rows={initialRows}
columns={initialColumns}
pivotParams={pivotParams}
apiRef={apiRef}
columnGroupHeaderHeight={36}
/>
50 changes: 50 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingCommodities.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
unstable_useGridPivoting,
GridToolbar,
} from '@mui/x-data-grid-premium';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function GridPivotingCommodities() {
const apiRef = useGridApiRef();

const { data, loading } = useDemoData({
dataSet: 'Commodity',
rowLength: 1_000,
editable: true,
});

const [pivotModel, setPivotModel] = React.useState({
rows: [{ field: 'brokerName' }],
columns: [{ field: 'commodity', sort: 'asc' }],
values: [{ field: 'quantity', aggFunc: 'sum' }],
});

const [isPivotMode, setIsPivotMode] = React.useState(false);

const pivotParams = unstable_useGridPivoting({
apiRef,
pivotModel,
onPivotModelChange: setPivotModel,
pivotMode: isPivotMode,
onPivotModeChange: setIsPivotMode,
});

return (
<div style={{ width: '100%' }}>
<div style={{ height: 600, width: '100%' }}>
<DataGridPremium
rows={data.rows}
columns={data.columns}
apiRef={apiRef}
slots={{ toolbar: GridToolbar }}
pivotParams={pivotParams}
loading={loading}
columnGroupHeaderHeight={36}
/>
</div>
</div>
);
}
51 changes: 51 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingCommodities.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as React from 'react';
import {
DataGridPremium,
useGridApiRef,
unstable_useGridPivoting,
Unstable_GridPivotModel as PivotModel,
GridToolbar,
} from '@mui/x-data-grid-premium';
import { useDemoData } from '@mui/x-data-grid-generator';

export default function GridPivotingCommodities() {
const apiRef = useGridApiRef();

const { data, loading } = useDemoData({
dataSet: 'Commodity',
rowLength: 1_000,
editable: true,
});

const [pivotModel, setPivotModel] = React.useState<PivotModel>({
rows: [{ field: 'brokerName' }],
columns: [{ field: 'commodity', sort: 'asc' }],
values: [{ field: 'quantity', aggFunc: 'sum' }],
});

const [isPivotMode, setIsPivotMode] = React.useState(false);

const pivotParams = unstable_useGridPivoting({
apiRef,
pivotModel,
onPivotModelChange: setPivotModel,
pivotMode: isPivotMode,
onPivotModeChange: setIsPivotMode,
});

return (
<div style={{ width: '100%' }}>
<div style={{ height: 600, width: '100%' }}>
<DataGridPremium
rows={data.rows}
columns={data.columns}
apiRef={apiRef}
slots={{ toolbar: GridToolbar }}
pivotParams={pivotParams}
loading={loading}
columnGroupHeaderHeight={36}
/>
</div>
</div>
);
}
11 changes: 11 additions & 0 deletions docs/data/data-grid/pivoting/GridPivotingCommodities.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div style={{ height: 600, width: '100%' }}>
<DataGridPremium
rows={data.rows}
columns={data.columns}
apiRef={apiRef}
slots={{ toolbar: GridToolbar }}
pivotParams={pivotParams}
loading={loading}
columnGroupHeaderHeight={36}
/>
</div>
Loading