-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
- Overview
-
Action Sheet
-
Button
- Floating Action Button
- Drop Down Button
-
Context Menu
-
List
-
Lookup
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
React Pivot Grid - State Persistence
The PivotGrid can persist its state. If a user sorts and filters data, modifies summary display modes, expands headers, or makes other changes, the component saves these modifications and restores them when a user reloads the page. Refer to the stateStoring article for a full list of modifications that can be saved.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
import React from 'react';
import PivotGrid, {
FieldChooser,
FieldPanel,
StateStoring,
} from 'devextreme-react/pivot-grid';
import Button from 'devextreme-react/button';
import PivotGridDataSource from 'devextreme/ui/pivot_grid/data_source';
import sales from './data.ts';
const onRefreshClick = () => {
window.location.reload();
};
const onResetClick = () => {
dataSource.state({});
};
const onContextMenuPreparing = (e) => {
const sourceField = e.field;
if (sourceField) {
if (!sourceField.groupName || sourceField.groupIndex === 0) {
e.items.push({
text: 'Hide field',
onItemClick() {
let fieldIndex: number;
if (sourceField.groupName) {
const areaField: any = dataSource.getAreaFields(sourceField.area, true)[sourceField.areaIndex];
fieldIndex = areaField.index;
} else {
fieldIndex = sourceField.index;
}
dataSource.field(fieldIndex, {
area: null,
});
dataSource.load();
},
});
}
if (sourceField.dataType === 'number') {
const menuItems = [];
e.items.push({ text: 'Summary Type', items: menuItems });
['Sum', 'Avg', 'Min', 'Max'].forEach((summaryType) => {
const summaryTypeValue = summaryType.toLowerCase();
menuItems.push({
text: summaryType,
value: summaryType.toLowerCase(),
onItemClick(args) {
setSummaryType(args, sourceField);
},
selected: e.field.summaryType === summaryTypeValue,
});
});
}
}
};
const dataSource = new PivotGridDataSource({
fields: [{
caption: 'Region',
width: 120,
dataField: 'region',
area: 'row',
sortBySummaryField: 'sales',
}, {
caption: 'City',
dataField: 'city',
width: 150,
area: 'row',
}, {
dataField: 'date',
dataType: 'date',
area: 'column',
}, {
groupName: 'date',
groupInterval: 'year',
}, {
groupName: 'date',
groupInterval: 'quarter',
}, {
dataField: 'sales',
dataType: 'number',
summaryType: 'sum',
format: 'currency',
area: 'data',
}],
store: sales,
});
const setSummaryType = (args, sourceField) => {
dataSource.field(sourceField.index, {
summaryType: args.itemData.value,
});
dataSource.load();
};
const App = () => (
<React.Fragment>
<div id="pivotgrid-demo">
<div className="desc-container">Expand, filter, sort and perform other operations
on the PivotGrid’s columns and
rows. <a onClick={onRefreshClick}>Refresh</a> the web page and note that
the PivotGrid’s state is automatically persisted.
</div>
<Button
text={"Reset the PivotGrid's State"}
onClick={onResetClick}
/>
<PivotGrid
id="sales"
dataSource={dataSource}
allowSortingBySummary={true}
allowSorting={true}
allowFiltering={true}
allowExpandAll={true}
showBorders={true}
height={570}
onContextMenuPreparing={onContextMenuPreparing}
>
<StateStoring
enabled={true}
type="localStorage"
storageKey="dx-widget-gallery-pivotgrid-storing"
/>
<FieldPanel
visible={true}
/>
<FieldChooser enabled={true} />
</PivotGrid>
</div>
</React.Fragment>
);
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
To enable state persistence, set stateStoring.enabled to true and specify the storageKey and type properties. Depending on the type, the state can be saved to a localStorage or sessionStorage. With localStorage, the state persists across browser sessions; with sessionStorage, it is reset after the current session. This demo uses localStorage.
Alternatively, you can implement the customSave and customLoad functions to save and load the state according to custom logic. In this case, set the type property to "custom".