Smart PivotGrid State Management β Implement seamless reset functionality while preserving user preferences with Syncfusion EssentialJS2 PivotGrid persistence in ASP.NET MVC applications.
This sample application demonstrates a production-ready solution for resetting PivotGrid controls to their initial state without disabling the EnablePersistence feature. Users can customize their PivotGrid configurationsβfield arrangements, sorting, filtering, and layoutβwith persistent storage across sessions, while retaining the ability to reset all changes back to default values instantly.
- β Smart Reset Functionality β Clear all customizations while maintaining EnablePersistence
- β Local Storage State Management β JavaScript-based persistence using browser localStorage
- β EssentialJS2 MVC Components β Enterprise-grade Syncfusion PivotGrid integration
- β Initial State Capture β Automatic initial configuration snapshot on first load
- β User-Friendly Controls β Simple UI button for one-click state restoration
- β ASP.NET MVC Best Practices β Follows MVC patterns with clean architecture
- β Session Persistence β Retains user preferences across application sessions
- Framework: ASP.NET MVC 5.2.3+
- Language: C# 4.5+
- IDE: Visual Studio 2022 or Visual Studio Code
- UI Components: Syncfusion EJ2 MVC 16.3.0+
- Frontend: jQuery 3.5.0, Bootstrap 5.3.3
- Database: Entity Framework 6.1.3
- .NET Framework: 4.7.2 or higher
- Visual Studio: 2022 Community Edition or Professional
- Memory: 2GB minimum
- Storage: 500MB for dependencies
- Browser: Modern browsers supporting ES6 and localStorage
git clone https://github.com/SyncfusionExamples/mvc-reset-PivotGrid-to-initial-state-while-enabling-EnablePersistence
cd Reset-PivotGrid-to-initial-state-while-enabling-EnablePersistence- Launch Visual Studio 2022
- Click File β Open β Project/Solution
- Navigate to
EssentialJS2MvcApplication2.sln - Click Open
# Right-click Solution β Restore NuGet Packages
# Or use Package Manager Console:
Update-Package -Reinstall# Press Ctrl+Shift+B or
Build β Build Solution- Press F5 to start debugging
- Or click the Run button in the toolbar
- Application launches at
http://localhost:XXXX
- Build & Run β Press F5 to launch the application
- Navigate to PivotGrid β Go to the PivotGrid Features page
- Customize the Grid β Drag fields, apply filters, change sorting
- Verify Persistence β Refresh the page; changes persist
- Click Reset Button β Return to initial state instantly
- Confirm Active Persistence β Make new changes; they persist again
When the PivotGrid loads for the first time, the application captures and stores the initial configuration:
function load() {
if (window.localStorage.getItem('initialState') === null &&
window.localStorage.getItem('pivotviewpivot1')) {
// Store initial state settings in local storage
window.localStorage.setItem('initialState',
window.localStorage.getItem('pivotviewpivotgrid'));
}
}When the "Go To Initial State" button is clicked, the stored initial configuration is restored:
document.getElementById("state").addEventListener('click', function () {
var model = JSON.parse(window.localStorage.getItem('initialState'));
// Reset initial state to grid through setProperties
document.getElementById('pivotgrid').ej2_instances[0].setProperties(model);
});Reset-PivotGrid-to-initial-state-while-enabling-EnablePersistence/
βββ Controllers/
β βββ PivotGridController.cs # PivotGrid data and logic
β βββ HomeController.cs # Application entry point
βββ Views/
β βββ PivotGrid/
β β βββ PivotGridFeatures.cshtml # Main PivotGrid UI
β βββ Shared/
β βββ _Layout.cshtml # Master layout
βββ Models/ # Data models and view models
βββ Scripts/ # JavaScript libraries and utilities
βββ Content/ # CSS stylesheets and themes
βββ App_Start/ # Configuration files
βββ App_Data/ # Local database files
βββ EssentialJS2MvcApplication2.sln # Visual Studio solution
Modify pivot configuration in PivotGridFeatures.cshtml:
@Html.EJS().PivotView("pivotgrid")
.Width("800")
.Height("300")
.EnablePersistence(true) // Enable state persistence
.ShowFieldList(true) // Show field list panel
.ShowGroupingBar(true) // Show grouping bar
.DataSource(dataSource => dataSource
.Data((IEnumerable<object>)ViewBag.Data)
.Rows(rows => { rows.Name("Country").Add(); })
.Columns(columns => { columns.Name("Year").Add(); })
.Values(values => { values.Name("Amount").Add(); }))
.Render()The application supports multiple themes. Modify the theme reference in _Layout.cshtml:
- Fabric theme (default)
- Bootstrap theme
- Material theme
- High Contrast theme
Q: PivotGrid not persisting changes
- Ensure
EnablePersistence(true)is set - Check browser localStorage is enabled
- Verify no browser privacy settings block localStorage
Q: Reset button not working
- Confirm initial state was captured on first load
- Check browser console for JavaScript errors
- Verify localStorage contains 'initialState' key
Q: Application won't start
- Ensure .NET Framework 4.7.2+ is installed
- Check all NuGet packages restored successfully
- Verify Visual Studio 2022 installation is complete
Q: PivotGrid not displaying data
- Check PivotGridController for data source configuration
- Verify ViewBag.Data contains valid data
- Review browser Network tab for API errors
Contributions are welcome! To contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit changes with clear messages
- Push to the branch and open a Pull Request
This project is licensed under the Syncfusion Community License. See Syncfusion License for details.
For issues, questions, or suggestions:
- Open a GitHub issue with detailed reproduction steps
- Review this README's troubleshooting section
- Check Syncfusion's official documentation
- Submit feature requests via GitHub Discussions