-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b000b90
commit e5e911b
Showing
8 changed files
with
229 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
docs/data/data-grid/pivoting/GridPivotingMultipleValues.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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 initialColumns = [ | ||
{ field: 'product' }, | ||
{ field: 'type' }, | ||
{ field: 'price' }, | ||
{ field: 'quantity' }, | ||
]; | ||
|
||
export default function GridPivotingMultipleValues() { | ||
const apiRef = useGridApiRef(); | ||
|
||
const { isPivot, setIsPivot, props } = unstable_useGridPivoting({ | ||
rows: initialRows, | ||
columns: initialColumns, | ||
pivotModel: { | ||
rows: ['type'], | ||
columns: ['product'], | ||
values: [ | ||
{ field: 'price', aggFunc: 'sum' }, | ||
{ field: 'quantity', aggFunc: 'avg' }, | ||
], | ||
}, | ||
}); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<input | ||
id="pivot" | ||
type="checkbox" | ||
checked={isPivot} | ||
onChange={(e) => setIsPivot(e.target.checked)} | ||
/> | ||
<label htmlFor="pivot">Pivot</label> | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
key={isPivot.toString()} | ||
{...props} | ||
apiRef={apiRef} | ||
experimentalFeatures={{ columnGrouping: true }} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/data/data-grid/pivoting/GridPivotingMultipleValues.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<input | ||
id="pivot" | ||
type="checkbox" | ||
checked={isPivot} | ||
onChange={(e) => setIsPivot(e.target.checked)} | ||
/> | ||
<label htmlFor="pivot">Pivot</label> | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
key={isPivot.toString()} | ||
{...props} | ||
apiRef={apiRef} | ||
experimentalFeatures={{ columnGrouping: true }} | ||
/> | ||
</div> |
62 changes: 62 additions & 0 deletions
62
docs/data/data-grid/pivoting/GridPivotingMultipleValues.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from 'react'; | ||
import { | ||
DataGridPremium, | ||
useGridApiRef, | ||
GridColDef, | ||
GridRowModel, | ||
unstable_useGridPivoting, | ||
} from '@mui/x-data-grid-premium'; | ||
import { unstable_useId as useId } from '@mui/utils'; | ||
|
||
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 initialColumns: GridColDef[] = [ | ||
{ field: 'product' }, | ||
{ field: 'type' }, | ||
{ field: 'price' }, | ||
{ field: 'quantity' }, | ||
]; | ||
|
||
export default function GridPivotingMultipleValues() { | ||
const apiRef = useGridApiRef(); | ||
|
||
const { isPivot, setIsPivot, props } = unstable_useGridPivoting({ | ||
rows: initialRows, | ||
columns: initialColumns, | ||
pivotModel: { | ||
rows: ['type'], | ||
columns: ['product'], | ||
values: [ | ||
{ field: 'price', aggFunc: 'sum' }, | ||
{ field: 'quantity', aggFunc: 'avg' }, | ||
], | ||
}, | ||
}); | ||
|
||
const inputId = useId(); | ||
|
||
return ( | ||
<div style={{ width: '100%' }}> | ||
<input | ||
id={inputId} | ||
type="checkbox" | ||
checked={isPivot} | ||
onChange={(e) => setIsPivot(e.target.checked)} | ||
/> | ||
<label htmlFor={inputId}>Pivot</label> | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
key={isPivot.toString()} | ||
{...props} | ||
apiRef={apiRef} | ||
experimentalFeatures={{ columnGrouping: true }} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
15 changes: 15 additions & 0 deletions
15
docs/data/data-grid/pivoting/GridPivotingMultipleValues.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<input | ||
id="pivot" | ||
type="checkbox" | ||
checked={isPivot} | ||
onChange={(e) => setIsPivot(e.target.checked)} | ||
/> | ||
<label htmlFor="pivot">Pivot</label> | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPremium | ||
key={isPivot.toString()} | ||
{...props} | ||
apiRef={apiRef} | ||
experimentalFeatures={{ columnGrouping: true }} | ||
/> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters